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.
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?
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.
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.