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/26 12:33:11 UTC

Attachments [again]

Sorry to bother you again with the same question, but I am really stuck 
here.

I need to send a binary file from the server to a client, yet I am not 
sure where/when to actually add the attachment (on the server) and how 
to get access to the attachment on the client side.

So far I'm trying this:
DataHandler dh = new DataHandler(new FileDataSource("/tmp/ws_expor.xls"));
         SOAPMessageContext smc = (SOAPMessageContext) 
MessageContext.getCurrentContext();
         boolean isNull = smc==null;
         logger.info("is smc == null?"+isNull);
         AttachmentPart ap = smc.getMessage().createAttachmentPart();
         ap.setDataHandler(dh);
         smc.getMessage().addAttachmentPart(ap);

Any answers or pointers to samples/documentation would be extremely helpful.

Thank you,

Tom

Re: Attachment Blues [RESOLVED]

Posted by Tom Ziemer <t....@dkfz-heidelberg.de>.
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

Attachment Blues

Posted by Tom Ziemer <t....@dkfz-heidelberg.de>.
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

Re: Attachments [again]

Posted by Tom Ziemer <t....@dkfz-heidelberg.de>.
Hi,

I looked at it but the important question (sending binary data from the 
server to the client) for me wasn't answered:
http://www.mail-archive.com/axis-user@xml.apache.org/msg09828.html

Right now I am using a datahandler to achieve this - but the dh is not 
in the attachment but directly returned by my service. Of course I am 
happy, that it works, but I am not sure why. How is the binary data 
transfered? Any thoughts?

Thanks,
Tom


Anne Thomas Manes wrote:
> Did you check the attachments section in the Wiki?
> http://wiki.apache.org/ws/FrontPage/Axis 
> 
> On 4/26/05, Tom Ziemer <t....@dkfz-heidelberg.de> wrote:
> 
>>Sorry to bother you again with the same question, but I am really stuck
>>here.
>>
>>I need to send a binary file from the server to a client, yet I am not
>>sure where/when to actually add the attachment (on the server) and how
>>to get access to the attachment on the client side.
>>
>>So far I'm trying this:
>>DataHandler dh = new DataHandler(new FileDataSource("/tmp/ws_expor.xls"));
>>         SOAPMessageContext smc = (SOAPMessageContext)
>>MessageContext.getCurrentContext();
>>         boolean isNull = smc==null;
>>         logger.info("is smc == null?"+isNull);
>>         AttachmentPart ap = smc.getMessage().createAttachmentPart();
>>         ap.setDataHandler(dh);
>>         smc.getMessage().addAttachmentPart(ap);
>>
>>Any answers or pointers to samples/documentation would be extremely helpful.
>>
>>Thank you,
>>
>>Tom
>>

Re: Attachments [again]

Posted by Anne Thomas Manes <at...@gmail.com>.
Did you check the attachments section in the Wiki?
http://wiki.apache.org/ws/FrontPage/Axis 

On 4/26/05, Tom Ziemer <t....@dkfz-heidelberg.de> wrote:
> Sorry to bother you again with the same question, but I am really stuck
> here.
> 
> I need to send a binary file from the server to a client, yet I am not
> sure where/when to actually add the attachment (on the server) and how
> to get access to the attachment on the client side.
> 
> So far I'm trying this:
> DataHandler dh = new DataHandler(new FileDataSource("/tmp/ws_expor.xls"));
>          SOAPMessageContext smc = (SOAPMessageContext)
> MessageContext.getCurrentContext();
>          boolean isNull = smc==null;
>          logger.info("is smc == null?"+isNull);
>          AttachmentPart ap = smc.getMessage().createAttachmentPart();
>          ap.setDataHandler(dh);
>          smc.getMessage().addAttachmentPart(ap);
> 
> Any answers or pointers to samples/documentation would be extremely helpful.
> 
> Thank you,
> 
> Tom
>