Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we use JAXB to marshall the whole SOAP request/response ?

 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

We know that JAX-WS runtime would handle the marshalling of entire SOAP request and response for us. But should we want to marshall the entire SOAP request including Envelope, Header and Body how do we do that. I know, we can do the unmarshalling for Body entries as we may know the xsd and we can generate the binding classes. But In order to unmarshall the entire SOAP message do we need to create binding objects for each of the schemas for the namespace http://schemas.xmlsoap.org/soap/envelope and any other schemas associated with header entries etc.

I see an example, where SOAPMessage is accessed using Provider<SOAPMessage> but this is not usin JAXB I believe. So, is there any way, JAXB can be used to access the entire SOAPMessage, instead of just the Payload. Any example would be helpful.
 
Kamal Tripathi
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use SAAJ to (un)marshall SOAP Request and response. Eventually in handlers, that's what is used. I don't think we can use JAXB to marshall/unmarshall SOAP requests and response to manipulate headers if needed and attach attachments.

In a webservice the XSD schema is not directly exposed, it is inside <wsdl:types> so even JAXB is not directly used as-is by JAX-WS.

I am a fellow aspirant for this certification so I may be wrong here. In which case veterans like Ivan can correct me here.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I absolutely agree with Kamal as SAAJ was designed to handle the entire message and produce a DOM like tree.

Regards,
Dan
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I too agree that SAAJ is meant for that low level handling of XML directly and that is what actually shown in the example which I referred for Provider<SOAPMessage>. But why not JAXB. I may not agree that xsd is not accessible, we can very well get the xsd or may be we can request it from the service providers and they should be able to provide that which we can use for generating the bindings for SOAP body entries.

But xsd for entire SOAP message is universally accessible, I do not see any problem in acquiring the XSD for SOAP envelope. But in that case, why can't we use JAXB to bind them. I have to admit that I had not tried this by myself, but just curious if anybody had done this before.

I mean, what could be a strong reason for not using JAXB to bind the entire SOAP message, if we have access to all the required xsd. Is this because, SAAJ is already available for such purposes or is there any other issues involved.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I see nothing that would stop you from using JAXB to create entire SOAP messages.
You may need to craft an XML schema describing your SOAP message and its contents, instead of being able to use the existing SOAP XML schema - I have not tried this myself.
After all, there is nothing special about a SOAP message - it is plain XML.

A reason for separating SOAP messages and its contents is that it is two different things with different functions - an envelope and a letter.
Best wishes!
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic