This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Can anyone help me, in adding the namespace(ns2) in my response tag of webservices?
I am using two xsd, one for each request and response. I am getting the output correct with all the tag, but with missing name spaces (ns2).
yes, i know, both the soap messages are functionally identical.
But my client don't understand that, He want the response as the second one with namespace(ns2) before each tag.
So can you please help me out and let me know the step/solution to get the second soap message.
Joined: Oct 04, 2006
I completely understand your situation, so here we go, even though this method will add overhead to your web service:
- Create a handler class that implements SOAPHandler<SOAPMessageContext>.
- Implement the method handleMessage to process messages that are going out from the web service.
To determine if a message is outbound, use the following code snippet (assuming you have access to the SOAPMessageContext):
- Retrieve and process the SOAP message along the following lines:
At this stage you have two choices, as far as I know:
1. Apply a transformation to the payload.
Since I am not good at transformations, I cannot elaborate.
2. Iterate over the elements in the DOM document obtained, creating a new XML fragment in which the namespace in question has the required prefix.
Since I am lazy, I will not elaborate. :-)
- Finally, insert the new XML fragment into the SOAP body.
You may want to add some check for the namespace in question before you start processing the XML fragment. This way you can hopefully avoid some unnecessary processing if the namespace in question is not present in the response message.
Joined: Sep 01, 2009
Thanks Ivan Krizsan, for you help and solution.
I also get another solution, In SoapBindingSkeleton class, there is static method in which,
_oper = new org.apache.axis.description.OperationDesc (), is present,
In which its third parameter contain an new object (javax.xml.namespace.QName). And its QName parameter we write ns2:, before the second parameter, thats response tag name like (ns2:response) .
Joined: Oct 04, 2006
Ah, ok - sorry, I am not that familiar with Axis, so I did not know about that solution.
Anyway, good to hear that you found a way to solve things! :-)