You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Tom Ziemer <t....@dkfz-heidelberg.de> on 2005/04/27 15:42:49 UTC

Re: Attachment Blues [RESOLVED]

I fixed it. It was a stupid mistake on the client side, but I'd still 
like to know, whether I am doing it the "right way".

Thanks,

Tom

Tom Ziemer wrote:
> Hi everybody!
> 
> I've got another question about attachments:
> 
> I finally figured out how to send an attachment to my client, by
> a) looking at the archive of the list,
> b) googling and
> c) reading the axis user guide
> 
> So this is what i came up with eventually (in case somebody is having 
> the same problem):
> 
> /**
> * Webservice that exports data and sends the result
> * back to the client (as an attachment)
> */
> public String export()
> {
> // gather data
> Object[][] data = this.manager.extractData(new Integer(id));
> this.manager.convert(data, "ws_export");
> 
> // get the message context
> org.apache.axis.MessageContext msgContext = 
> org.apache.axis.MessageContext.getCurrentContext();
> 
> org.apache.axis.Message rspMsg= msgContext.getResponseMessage(); 
> rspMsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachments.SEND_TYPE_DIME); 
> 
> 
> // add the file i just generated
> java.io.File fileToAddAsAttachment = new 
> java.io.File("/tmp/ws_export.xls");
> 
> javax.activation.DataHandler dh =
> new javax.activation.DataHandler(new 
> javax.activation.FileDataSource(fileToAddAsAttachment));
> 
> org.apache.axis.attachments.AttachmentPart part =
> new org.apache.axis.attachments.AttachmentPart(dh);
> 
> rspMsg.addAttachmentPart(part);
> 
> logger.info("Attachment Size: "+rspMsg.countAttachments());
> logger.info("Sending message: "+msg);
> 
> return msg;
> }
> 
> Now, it's pretty easy to access this attachment on the client side by:
> XlsExportServiceLocator locator = new XlsExportServiceLocator();
> MessageContext mx = locator.getCall().getMessageContext();
> 
> Then I can iterate over the attachments and process them - great! The 
> only problem is: the String (msg) returned by the service is null. When 
> I remove the attachment-stuff from my service, everything is working 
> nicely, though.
> 
> So, my question is: What am I doing wrong now?
> 
> Thanks,
> 
> Tom