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 Paul Duran <pa...@gmail.com> on 2005/05/02 15:19:52 UTC

correct method to get attachments from a soap response?

Hi all,

I'm writing a java application that calls a .NET web service. I have
generated the java-side code using the wsdl2java ant task.

The .NET web service generates a pdf document and sends it back to the
client as a SOAP attachment.

I am wondering what the 'correct' way of obtaining soap attachments
from a call to a web service is. The code I currently have (that
works) involves casting the 'soap' object to a 'soap stub' object.. as
the soap stub has methods to get the attachments.

see the code below for what i mean.

-----
ReportGeneratorLocator rgl = new ReportGeneratorLocator();

ReportGeneratorSoapStub reportGeneratorSoap =
(ReportGeneratorSoapStub) rgl.getReportGeneratorSoap();

reportGeneratorSoap.doReport(new DoReportDataSet(result.get_any()), "pdf");

Object[] attachments = reportGeneratorSoap.getAttachments();
-----

As I said, this code actually works but I'm concerned that i'm having
to cast to the stub object to get the attachments.

The documentation i've found so far mentions the MessageContext
class.. but when i call MessageContext.getCurrentContext(), i receive
a null value.

Can anybody clue me in as to whether i'm doing the right thing? Or if
not, what the 'right thing' actually is?

thanks,
Paul.

Re: correct method to get attachments from a soap response?

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

I've asked a similar question some time ago, but didn't get an answer. 
The code I eventually came up with looks like this:

XlsExport xlsExport = null;
try
{
	xlsExport = locator.getXlsExport();
         String msg = xlsExport.exportExperiment(id, zipped);
         MessageContext mx = locator.getCall().getMessageContext();
	Message m = mx.getCurrentMessage();
	logger.info("[client]: Found attachments: "+m.countAttachments());
	....
}
...
This way I can access the attachments without having to cast. I don't 
know if this is better than your approach or even it's okay to do it 
like that - but as in your case - it works.

Hope it helps.

Regards,
Tom

Paul Duran wrote:
> Hi all,
> 
> I'm writing a java application that calls a .NET web service. I have
> generated the java-side code using the wsdl2java ant task.
> 
> The .NET web service generates a pdf document and sends it back to the
> client as a SOAP attachment.
> 
> I am wondering what the 'correct' way of obtaining soap attachments
> from a call to a web service is. The code I currently have (that
> works) involves casting the 'soap' object to a 'soap stub' object.. as
> the soap stub has methods to get the attachments.
> 
> see the code below for what i mean.
> 
> -----
> ReportGeneratorLocator rgl = new ReportGeneratorLocator();
> 
> ReportGeneratorSoapStub reportGeneratorSoap =
> (ReportGeneratorSoapStub) rgl.getReportGeneratorSoap();
> 
> reportGeneratorSoap.doReport(new DoReportDataSet(result.get_any()), "pdf");
> 
> Object[] attachments = reportGeneratorSoap.getAttachments();
> -----
> 
> As I said, this code actually works but I'm concerned that i'm having
> to cast to the stub object to get the attachments.
> 
> The documentation i've found so far mentions the MessageContext
> class.. but when i call MessageContext.getCurrentContext(), i receive
> a null value.
> 
> Can anybody clue me in as to whether i'm doing the right thing? Or if
> not, what the 'right thing' actually is?
> 
> thanks,
> Paul.