Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JAXWS client SOAP manipulation  RSS feed

 
chinmay sagade
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created stubs using a wsdl and posting a message to service.However i need to manipulate the SOAP message i am posting to this server.The problem i am facing is the client is adding default namespaces ex.ns2 in SOAP message which i don't want.
Do We have any way to do that in JAXWS?please guide.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
To make sure I understand you correctly. The following is an example of XML generated by JAXB when marshalling a Java object.


So do you, from the above XML, wish to remove the following piece?
xmlns:ns2="http://www.ivan.com/calculator"

If this is the case you can:
1) Write a handler on the client side that processes all outgoing messages removing namespace declarations.
2) Do the marshalling of the request yourself and write the output to an XMLStreamWriter.
The XML stream writer is an instance of a class you write yourself that implements the XMLStreamWriter interface and delegates to another object implementing XMLStreamWriter. In your XML stream writer class there is one method that needs special attention:

By doing this, you ensure that there will be no namespace declarations in the XML document written. If you only want to remove selected namespaces, do filtering using the arguments of the method; arg0 is the namespace prefix and arg1 is the namespace URI.
The marshalling of a request object is done like this:

The problem now is how to fit the above solution into your generated classes. I'll get back later regarding that.
Best wishes!
 
chinmay sagade
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly Ivan !!! can you please tell how to do that?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been thinking about this a little and I feel that the simplest way is to skip using the generated client artifacts and generate the request yourself, using the JAXB generated classes. Then, to filter away the unnecessary namespace declaration, use the technique I outlined in my message above.
You also have to receive the request yourself, but JAXB will help you with the unmarshalling.

Alternatively, if you do not fear the overhead a handler will introduce, that option is still available.
Best regards!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!