File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes SOAP message with attachment server-side implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "SOAP message with attachment server-side implementation" Watch "SOAP message with attachment server-side implementation" New topic
Author

SOAP message with attachment server-side implementation

Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Hi,

I searched all over the internet and i only found clients that send SOAP messages with attachments, like this one here. Clients call a web service using something like this:

But what about the server side ? What does the server parameter looks like ? How does the server return a SOAP message with attachment ?


"Quoting yourself is stupid" - Me
Evan Caballero
Ranch Hand

Joined: Dec 10, 2009
Posts: 59
on the server side, the binary data of the attachment will be handled in a DataHandler object.
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Thanks, but i know how to read a SOAP message. I don't know what are the web service method parameters and how do i return a SOAP message back to the client.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

A tutorial of the SAAJ api is available at the Sun site. It may aid you -> http://docs.sun.com/app/docs/doc/819-3669/bnbhg?a=view


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Like i said in my first post, it's a tutorial for the client, there is nothing about the server
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you want to use SAAJ in a web service endpoint implementation class, then your web service endpoint implementation class will have to implement the Provider interface and be annotated with the @WebServiceProvider annotation.
Thus you can look for any example of implementing a web service using the Provider interface. If you do not find any, check my SCDJWS study notes at page 157. There you can find an example showing how to process and return SOAP messages using JAXB. I imagine it cannot be that difficult to modify the example to use SAAJ.
Best wishes!
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Thanks.

What about when recieving a soap message ? What's the parameter ?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
No, that is not the appropriate way to do it.
If you want to process raw SOAP messages, you should develop an endpoint implementation class that implements the Provider interface and that is annotated with @WebServiceProvider.
See the same example that I referred you to in the earlier post.
Best wishes!
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I'm still having a bit of trouble. I don't understand how do i read to the SOAPMessage. Let's say i have a class named "TestClass" that implements the Provider<SOAPMessage> interface.

1. Client calls an operation from TestClass using connection.call(message, endPoint);. What exactly is endPoint, adress to the Service ? Like http://localhost:8080/TestClass/TestClassService ?
2. TestClass calls the invoke method automaticly ?
3. I read the SOAPMessage inside the invoke method ?

Is this correct ?

Also, can i have normal web service operations in TestClass ?
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Is there any way to read a SOAPMessage with attachment without using @WebServiceProvider ? I have lots of operations in my @WebService, and if i change the annotation, it doesn't work anymore, wsdl goes crazy.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
You could try to use a handler that extracts the attachment of a SOAP message and inserts it into the message context of the request.
Alternatively, you could save the attachment to disk and insert some kind of reference to the attachment in the message context.

This way you do not have to change the implementation style of your webservice endpoint implementation class(es) and can still receive attachments with the requests to the service.
Best wishes!
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I know this must be very easy for you, but it's not for me

How do i send a SOAP message with attachment to a specific operation, the call is:
SOAPMessage result = connection.call(message,endPoint);

I don't see how can i relate the message with the operation...

I'd wish i could find an example with both client and server.

Thanks Ivan, you seems the only one that knows this stuff and is willing to help.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you are not clear about the concept of handlers, please see a fully working example (which implements logging of SOAP messages) in my SCDJWS notes:
http://faq.javaranch.com/content/Exam-Objectives-5.pdf
Take a look at section 9.5 on page 325.
Best wishes!
Thanh Luu
Greenhorn

Joined: Feb 16, 2010
Posts: 2
Hi Parvan,

I am facing the same issue with what you had. I've been trying to find what should be on the service endpoint to deal with SOAPMessage result = connection.call(message,endPoint);

Just wondering if you have the anwser for it as yet? or can you direct me to webpage which might have the solution.

Thanks.

Luut
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Sorry, but i didn't, i used base64 to send the files
Thanh Luu
Greenhorn

Joined: Feb 16, 2010
Posts: 2
Can I ask if you still use SOAPMessage result = connection.call(message,endPoint); on you ws client application or you use the generated artifacts?

Thanks,
Luut
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
No, i don't use the call.

I convert my image to bytes, then bytes to base64, and send it as a string. It's not working on the phone tho, only on the emulator.

Alex.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SOAP message with attachment server-side implementation