wood burning stoves 2.0*
The moose likes Web Services and the fly likes SOAP with attachments service & client example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "SOAP with attachments service & client example" Watch "SOAP with attachments service & client example" New topic
Author

SOAP with attachments service & client example

revi akula
Greenhorn

Joined: Dec 08, 2010
Posts: 4
Hi,

Can anyone provide me with a small sample of a soap service & soap client with attachments using saaj. I have been googling for over two weeks now and i couldn't find even a single example for soap service. Please help as am running out of time.


Thanks in advance !!!
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Axis2 comes with a SwA example; Metro probably does, too. The WebServicesFaq links to an article about it that has code.
revi akula
Greenhorn

Joined: Dec 08, 2010
Posts: 4
Hi Lester,
Thanks for your reply...But am new to webservice and i dont understand the concept of artifact generation....am used to eclipse IDE.

Sorry am actually confused how to write a saaj service...i understand the client concept will call the service using :

SOAPMessage smg = conn.call(msg,endpoint);

But how to write a service which accepts the SOAP Message. When i write a service like this...

public SOAPMessage respMsg(SOAP Message){
//code to extract SOAP MEssage using MessageContext
}


I get an exception during the generation of WSDL using eclipse wizard(bottom up) as below :

The service class "com.service.webservice.ServiceServlet" does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly.

My IDE is eclipse and apache tomcat is the server....

Please Help !!!
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
1) I advise to not use an IDE at first, or you'll not learn some important points about implementing WS.

2) i advise to get an existing example code running before trying to create one of your own, just so you know what's involved.

3) Be aware that JAX-RPC is a different API than SAAJ (it's also obsolete, so I advise not to spend time on it).
revi akula
Greenhorn

Joined: Dec 08, 2010
Posts: 4
Thanks lester for your timely responses and advice. Will definitely do that. But to save myself from the current urgent requirement, could you please let me know if am heading in the correct direction i.e., by writing something like this on the service side:


public SOAPMessage respAttch(SOAPMessage smgRequest){
//MessageContext
}


And how do i resolve the error i get while generating the WSDL ?

The service class "com.service.webservice.ServiceApp" does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly.

Or can you give some code snippet with method signature
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Again:
Lester Burnham wrote:2) i advise to get an existing example code running before trying to create one of your own, just so you know what's involved.

3) Be aware that JAX-RPC is a different API than SAAJ (it's also obsolete, so I advise not to spend time on it).
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I do not have a complete SAAJ example in stock, but section 5.7 in my SCDJWS 5 study notes will provide several code examples showing how to use SAAJ to create SOAP messages with and without attachments. Download the PDF document here: http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Ravi,
I agree with Lester that it's important to get to know the basics of web services and work on simple example code(SAAJ) to work on one of the complex areas of web services "SwA".

Here is a link to sample code. You need to be really patient to go through the tutorial to understand .

By the way, what is your purpose of using SAAJ? Are you in need of sending/ receiving SOAP attachments or just plain SOAP message using SAAJ?
3) Be aware that JAX-RPC is a different API than SAAJ (it's also obsolete, so I advise not to spend time on it).

Well, it's not completely true unless oracle has made usage of J2EE1.4 and prior versions absolete. There are still companies working on J2EE1.3 which still use JAX-RPC1.1.


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
revi akula
Greenhorn

Joined: Dec 08, 2010
Posts: 4
Hi Ivan & Naren,

Thanks for your reply ! But since am very new to webservices, am unable to sink any of these bigger topics.

@Ivan : I've d/w the pdf and have gone thro the section u've mentioned. Its pretty good stuff. But as i said, am new so looking out for end to end implementation of some small client & Service example with SAAJ on top of which i can build my service.

@Naren: I've gone thro' the tutorial(not completely though),but again it talks in very detailed level which i cant understand so quickly. And yes my requirement is to send docs from a SOAP client to a Web Service which would do some processing and again give back the output doc to the client.


So, please incase if you have some small client and most importantly the "web service" which would accept the attachments(as i get only client examples but not the service), i will be grateful to you people !!! Thanks in advance.
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Ravi,
please incase if you have some small client and most importantly the "web service" which would accept the attachments

"Soap with Attachments"(SwA) is one of the niche subjects within Web Services and I understand your problem that you couldn't find useful examples in your case. This is because not many people use this API. You must note that depending on the type of attachment (for mime type extensions refer here), the code changes considerably if not completely. I don't know what file extension types you are interested in. But, whatever it is SwA is normally used along with JAX-RPC or JAX-WS in the latest web services where service provider WSDL should describe attachment mime parts in the soap binding element and correspondingly service provider code should handle attachments differently based on their mime types.
For example if an attachment of pdf (I picked pdf as you mentioned "docs") is expected, then
Partial WSDL:


Web Service end point interface




Sample client (partial code)



Web Service end point implementation (partial code)


There is a topic on this at the end of RMH book. Though, it has not provided any complete example, understanding the theory would be sufficient for anyone to write their own code.
 
Consider Paul's rocket mass heater.
 
subject: SOAP with attachments service & client example
 
Similar Threads
soap with attachment question ?
Adding attachments to web service response
Sending a pdf file to client from server through web service
How to refer the current SOAP message?
Passing binary files in webservices