permaculture playing cards*
The moose likes Web Services and the fly likes Adding attachments to web service response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Adding attachments to web service response" Watch "Adding attachments to web service response" New topic
Author

Adding attachments to web service response

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In the Axis framework, there is a WSDL2Java program which creates a set of Java objects for deploying a web service.

If I run WSDL2Java on a WSDL file, I will get a group of class files. Can a file attachment be added with these classes, i.e. in the {XXX}SoapBindingImpl object?

If not, is there anyway to directly add a file attachment to the outgoing SOAP repsonse?
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I am not sure if attachment can be added to generated classes. But it can be vary well added to the response. You can have a look into SOAP with Attachment (SWA) specifications or MTOM. Both of them are supported by AXIS2.


SCJP 1.5(97%) My Blog
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thanks. We were a little "stuck" on using Axis 1.4, but will be expanding a bit to include WSO2 WSAS with Axis2 in our evaluations.

shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
AXIS 1.4 support soap with attachment (SWA) though it's not support MTOM which is optimized way of sending attachment.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Sending a SOAP message with attachments to a web service and a web service that sends a SOAP repsonse with attachments are two different things.

In the first case, adding the attachement is relatively simple. In the second case, with Axis 1.4, adding the attachment to the web service SOAP response is not possible. There is no way to get to the generated SOAP message.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
As per SWA spec attachment will not be part of SOAP message. SOAP message will just have reference of attachment. SOAP message will go as root part of mime type multipart/related while attachment will go in next part. There is another way though it will increase the size of attachment by 1.3 times. Have a base64binary type of element to carry attachment. And do encoding and decoding of your attachment.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
As per SWA spec attachment will not be part of SOAP message. SOAP message will just have reference of attachment. SOAP message will go as root part of mime type multipart/related while attachment will go in next part.


Yes, this is correct. It does not have anything to do with what I just mentioned however.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
In the second case, with Axis 1.4, adding the attachment to the web service SOAP response is not possible.


I disagree with above. Do you want to say that axis 1.4 doesn't support SWA?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
As I mentioned, a client sending a SOAP message with attachments to a web service (request) and a web service which sends a SOAP message with attachments to a client (response) are different.

Firstly, do you understand this statement clearly?

Basically, we want to create a web service that sends file attachments via SOAP to the client.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Henry Pinkerton wrote:Firstly, do you understand this statement clearly?



I tried giving you some pointer to start with but that seems useless. Follow the link below which tells how to implement it in server side.

http://www.roseindia.net/webservices/web-services-development.shtml


Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thanks for you help.

However, the author in this article attempts to shows how to create a web service that can process incoming attachments from the client. As mentioned already a few times, this is not what this post is about.

The article does not demonstrate a web service sending outgoing attachments.

Processing (incoming) attachments != Sending (outgoing) attachments

Client code for sending attachments is not the same as web service code sending attachments. The attachments being sent to a web service and attachments sent to client are not the same.

PS: roseindia.net is website full of bad practices and buggy code.
Sid Misra
Greenhorn

Joined: Jun 07, 2011
Posts: 2

Hi,

I know this thread is a little old but i am in the exact same situation as Jimmy.We are stuck with Axis 1.4 and we need a web service that has an invoice number (int) in request and the spits out a response with a pdf file as an attachment.

As others i have gone over tons of examples on the web with some built in axis 2 and others which send attachments as part of the request(like a resume upload service).If some one can point me the right direction or provide some code i can run to see how sending an attachment as part of the response works it will be really helpful.Thanks

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding attachments to web service response
 
Similar Threads
Web service to pass a jar
How to invoke webservice with an attachmnet
File Attachment with WSDL2Java objects
Attachments prob using Axis
wsdl error