File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes need to add namespace ns2: in the all webservices response tags. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "need to add namespace ns2: in the all webservices response tags. " Watch "need to add namespace ns2: in the all webservices response tags. " New topic
Author

need to add namespace ns2: in the all webservices response tags.

Mukesh Puri
Greenhorn

Joined: Sep 01, 2009
Posts: 9
Hello,

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

Example

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Reponse xmlns="http://persistent.reponsetypeoffrepush.clientplus.steria.com">
<Idsession>11025</Idsession>
<Offres>
<Offre>
<Code_Offre>AAINV</Code_Offre>
</Offre>
<Offres>
<Spots>
<Spot>
<Type_Spot>SC</Type_Spot>
</Spot>
</Spots>
<Idoffre/>
</Reponse>
</soapenv:Body>
</soapenv:Envelope>.




But i required

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:Reponse xmlns="http://persistent.push.clientplus.steria.com" xmlns:ns2="http://persistent.reponsetypeoffrepush.clientplus.steria.com">
<ns2:Idsession>##idsession##</ns2:Idsession>
<ns2:Offres>
<ns2:Offre>
<ns2:Code_Offre>AAINV</ns2:Code_Offre>
</ns2:Offre>
</ns2:Offres>
<ns2:Spots>
<ns2:Spot>
<ns2:Type_Spot>SC</ns2:Type_Spot>
</ns2:Spot>
</ns2:Spots>
<ns2:Idoffre/>
</ns2:Reponse>
</soap:Body>
</soap:Envelope>


Please help me, I need it to add and complete it urgently....
Any more detail required contact me at mukesh.vpuri@gmail.com

Thank in advance for the help

Regards
Mukesh Puri
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
To me, it looks like the two SOAP messages are functionally identical. So, curious as I am, I have to ask: Why do you need the second format?
In the second SOAP message, the namespace http://persistent.push.clientplus.steria.com is not used anywhere. If you remove it and the namespaceprefix from the namespace http://persistent.reponsetypeoffrepush.clientplus.steria.com, then you have the first SOAP message.
Best wishes!
Mukesh Puri
Greenhorn

Joined: Sep 01, 2009
Posts: 9
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.

Thanks
Mukesh Puri
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
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.

Best wishes!
Mukesh Puri
Greenhorn

Joined: Sep 01, 2009
Posts: 9
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) .


Best Regards
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
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! :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to add namespace ns2: in the all webservices response tags.
 
Similar Threads
Talk to sharepoint through its web services
namespace issue for doc/lit wrapped
error while connecting to webservices
unable to connect to .Net web service using axis with java
Response <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>