- This topic has 5 replies, 3 voices, and was last updated 16 years, 9 months ago by Riyad Kalla.
-
AuthorPosts
-
thomas.hoopMemberHow would I implement a top down soap with attachments web service? ❓
Riyad KallaMemberNot sure, but I’ll send the request to our documentation guys working on web services and see if this is a general enough thing to include.
Tom ColeParticipant@support-rkalla wrote:
Not sure, but IHey, has there been any update on this? Still not in the documentation although XFIre has had some sort of support (I believe) for attachments since 1.1. I have a rather urgent need to be able to create a web service that accepts attachments.
Riyad KallaMembertcole6, no update right now. The doc team is heavy at work on the Blue JAX-RPC and JAX-WS support docs.
In the mean time I did some searching and found this: http://xfire.codehaus.org/MTOM
Also, it seems in the XFire bundle itself, under the examples dir is the source code for that example if you need it.
Tom ColeParticipantOkay…here’s how I got it to work…
1. Sending an attachment. This was rather simple:
Define your method’s return type as Attachment, or if you return a POJO, have one of it’s attribute be an Attachment.
Create a SmpleAttachment object and return it. I did it like so though there are several ways to do it:public Attachment sendFile() {
URL url = new URL(‘http://localhost/myfile.gif”);
DataHandler handler = new DataHandler(url);
SimpleAttachment attachment = new SimpleAttachment(“12345”, handler);
return attachment;
}
You can then do things like set XOP etc on the attachment.2. Receiving an Attachment(s). This was not as easy as I expected.
Define an input parameter of type Attachment (or you can also set an attribute of one of your Object parameters as an Attachment).
The funny thing is that I couldnt’ manipulate the actual Attachment object I received. I had to use it to construct an Attachment which I could then read from:public String getFile(Attachment file) {
try {
MessageContext ctx = AbstractInvoker.getContext();
AttachmentUtil util = new AttachmentUtil();
Attachment attachment = util.getAttachment(file.getId(), ctx.getInMessage());
DataHandler handler = attachment.getDataHandler();
InputStream input = handler.getInputStream();
//read the attachment from the input…
return “Found ” + input.available() + ” bytes.”;
}
catch(Exception ex) {
return ex.getMessage();
}
}This was just some quick hacking to get something working. It let me send and receive attachments, which is better than I could do a few hours ago… The XFire documentation is SOOOOOO poor that I can’t actually believe it.
Riyad KallaMembertcole6, nice followup man. Thanks for taking the time to post it for other folks.
-
AuthorPosts