Okay…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.