ocean O
asked on
how to change the namespace in soap response
HI, I am writing a soap web service.
The response that I got is starting with : <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">,
but it require to be : <env:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">.
I tried to add below line code in package-info.java, to replace the soap prefix with env, but it didn't work.
xmlns = {
@javax.xml.bind.annotation .XmlNs(pre fix="env", namespaceURI="http://schemas.xmlsoap.org/soap/envelope/")
}
any inputs is welcome.
Thanks
The response that I got is starting with : <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">,
but it require to be : <env:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">.
I tried to add below line code in package-info.java, to replace the soap prefix with env, but it didn't work.
xmlns = {
@javax.xml.bind.annotation
}
any inputs is welcome.
Thanks
sorry I thought you were generating the string manually.
The server who sends you this
needs to change their XML and define a namespace "env".
<env:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
needs to change their XML and define a namespace "env".
ASKER
I can't change the server . I am thinking to write a soap handler to change the namespace of response from <soap> to <env>. Something like below, but I don'y know where to call this method:
public boolean handleMessage(SOAPMessageC ontext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MES SAGE_OUTBO UND_PROPER TY);
if (outboundProperty.booleanV alue()) {
try {
SOAPMessage msg = smc.getMessage();
SOAPPart sp = msg.getSOAPPart();
sp.getEnvelope().removeNam espaceDecl aration("s oap");
sp.getEnvelope().setPrefix ("ENV");
sp.getEnvelope().getBody() .setPrefix ("ENV");
sp.getEnvelope().getHeader ().setPref ix("ENV");
smc.setMessage(msg);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public boolean handleMessage(SOAPMessageC
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MES
if (outboundProperty.booleanV
try {
SOAPMessage msg = smc.getMessage();
SOAPPart sp = msg.getSOAPPart();
sp.getEnvelope().removeNam
sp.getEnvelope().setPrefix
sp.getEnvelope().getBody()
sp.getEnvelope().getHeader
smc.setMessage(msg);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
If the "env" namespace is not defined then it is invalid XML, you have to fix the server. Can you post the SOAP response you get?
but it require to be
The example that you show is not modifying the namespace but the namespace alias. The namespace in that example is identical in both. While I can't say for sure from only seeing one line, but that second example would not be what you want as you have defined the "soap" alias to point to a namespace, but you are using the "env" alias which probably points to nothing at all.
So I ask.. what is the bigger picture here? Why do you think that you need to modify this alias? If all parts of both the server and client are implemented correctly, the actual value of the alias shouldn't be of concern, just that they refer to a namespace, and THAT namespace has the correct value.
ASKER
I am migrating web services from weblogic to tomcat. I am using apache cxf for the implementation.
The response that I got is like this:
The original example response is like this:
So I have to change all the "soap" namespace into "env" , like from "<soap:Envelope" to "<env:Envelope".
Thanks
The response that I got is like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:getWorkAreasResponse xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://netg.z.com/WS/AService/" xmlns:ns3="http://netg.z.com/WS/Common/">
<m:net_areas>
<m:net_Area>
<m:net_area>west</m:net_area>
</m:net_Area>
<m:net_Area>
<m:net_area>east</m:net_area>
</m:net_Area>
</m:net_areas>
</m:getWorkAreasResponse>
</soap:Body>
</soap:Envelope>
The original example response is like this:
<env:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<m:getWorkAreasResponse xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://netg.z.com/WS/AService/" xmlns:ns3="http://netgeo.vzw.com/WS/Common/">
<m:net_areas>
<m:net_Area>
<m:net_area>west</m:net_area>
</m:net_Area>
<m:net_Area>
<m:net_area>east</m:net_area>
</m:net_Area>
</m:net_areas>
</m:getWorkAreasResponse>
</env:Body>
</env:Envelope>
So I have to change all the "soap" namespace into "env" , like from "<soap:Envelope" to "<env:Envelope".
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mccarl:
Thanks for the info. I resolved the issue by adding :
<jaxws:properties>
<entry key="soap.env.ns.map">
<map>
<entry key="env" value="http://schemas.xmlsoap.org/soap/envelope/"/>
</map>
</entry>
</jaxws:properties>
Thanks for the info. I resolved the issue by adding :
<jaxws:properties>
<entry key="soap.env.ns.map">
<map>
<entry key="env" value="http://schemas.xmlsoap.org/soap/envelope/"/>
</map>
</entry>
</jaxws:properties>
Open in new window