Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Attachments for Webservice in Eclipse using axis 1.3 on tomcat 5.5
Attachments for Webservice in Eclipse using axis 1.3 on tomcat 5.5 [message #194128] Wed, 06 June 2007 20:03
Eclipse UserFriend
Originally posted by: Dominik.pich.info

Hi,

I am using Eclipse 3.2 with the latest Webtools to develop a webservice.
As engine to run the service I use to tomcat 5.5 with axis 1.3 (axis is
coming with eclipse!? - well I havent installed it anyway :D)

IDEA:
the service exposes two operations:
<code>
BackupResult uploadFiles(BackupFile[] files);
BackupResult downloadFiles();
//result is container for error OR files array.
</code>

SERVER:
Axis was used here to make WSDL for my Java Bean and manages the service
when published on the tomcat server.

CLIENT:
wsdl2java genereated me the necessary stubs for the needed Bean (and all
complex types)
My calls to the service are performed using axis

SO FAR SO GOOD
All's up and running... but one major drawback: every file's content is a
byte[]
This works for small files or few files but not when having to load all
data in memory just so I can then send it off.
I decided that what I wanted were attachments. And as my clients are java
and/or c# I needed a interopable solution.

AND HERE'S WHERE IT WENT WRONG
:) I realized I'd need REAL Attachments (not just some variable typed as
DataHandler) and they'd have to be in the DIME format.
I cant get ANY attachment to work though :/ (oh and I do have action and
mail.jar - no RuntimeError IIRC)

I tackled upload first. So the client has to attach data.
<code>
//remove old and make DIME
try {
((BackupServiceProxy) backupService).getStub().clearAttachments();
((BackupServiceProxy) backupService).getStub()._setProperty(
Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
} catch (Exception e) {
e.printStackTrace();
}
...
//attach File
DataSource source = new FileDataSource(new File(path));
DataHandler buildFile = new DataHandler(source);
try {
((BackupServiceProxy) backupService).getStub().addAttachment(
buildFile);

} catch (Exception e) {
e.printStackTrace();
}
</code>
I do this in a static private method after which I make the call using the
proxy object (which in turn just calls the stub):
<code>
public core.BackupResult uploadFiles(core.BackupSettings settings,
core.BackupFile[] files) throws java.rmi.RemoteException {
if (backupService == null)
_initBackupServiceProxy();
try {
int attachLength =
((BackupServiceSoapBindingStub)backupService).getAttachments ().length;
System.out.println(attachLength + " attachments");
} catch (Exception e) {
e.printStackTrace();
}
return backupService.uploadFiles(settings, files);
}
</code>
i added an output and it returns the correct amount of attachments namely
one for each file.

next step is to 'unpack' the attachments on the server and here I get 0
everytime:
<code>
public static AttachmentPart[] getMessageAttachments() throws AxisFault {
MessageContext msgContext = MessageContext.getCurrentContext();
if (null == msgContext) {
System.out.println("cant get context");
return null;
}

System.out.println("name of msg:" +
msgContext.getCurrentMessage().getSOAPPartAsString());
Iterator it = msgContext.getCurrentMessage().getAttachments();
ArrayList<AttachmentPart> attachments = new ArrayList<AttachmentPart>();
while (it.hasNext()) {
AttachmentPart part = (AttachmentPart) it.next();
attachments.add(part);
}
System.out.println(attachments.size() + " attachments");
return attachments.toArray(new AttachmentPart[0]);
}
}
</code>

QUESTION:
Simply - WHY. Im desperate and after hours of experimenting I ran out of
ideas...

Best regards,
and thanks in advance,
Dominik
Previous Topic:org.eclipse.jst.web_core.feature
Next Topic:WTP SERVER implementation
Goto Forum:
  


Current Time: Thu Mar 28 23:32:09 GMT 2024

Powered by FUDForum. Page generated in 0.07401 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top