0

I have SOAP response of something like this

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
    xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
    <soapenv:Body>
        <calculate_response>
            <tid>33433</tid>
            <status>0</status>
            <reason>0</reason>
        </calculate_response>
    </soapenv:Body>
</soapenv:Envelope>

I need to add namespace to it and it should look something like this

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    xmlns:def="http://com.sample.xyz/Messages">
    <soapenv:Body>
        <def:calculate_response>
            <tid>33433</tid>
            <status>0</status>
            <reason>0</reason>
        </def:calculate_response>
    </soapenv:Body>
</soapenv:Envelope>

I have created stub using wsimport, and I need this response to be modified before processing it further.

Actually it's a two step process as I understood , first step is to add namespace to soap envelop then add prefix to it. Regarding prefix part I found this . I'm not clear about how to do first step.

Note: I need to modify response at client side and I cannot change SOAP at server side.

Community
  • 1
  • 1
Sajjad
  • 853
  • 2
  • 15
  • 32
  • Why do you need to change the response at client side? What are you trying to achieve by adding that namespace? – Alin Pandichi Dec 30 '15 at 12:01
  • Actually soap client is expecting a response to be of type `{http://com.sample.xyz/Messages}calculate_response`, where as it is not returned by the server, It happens to be missing namespace. – Sajjad Dec 30 '15 at 12:09
  • Why don't you regenerate the Soap client classes so that they match the response sent by the server? – Alin Pandichi Dec 30 '15 at 12:13
  • I did, I used wsdl, xsd from server to generate client classes but it is expecting a response to be like that where as server is not returning it. – Sajjad Dec 30 '15 at 12:14

1 Answers1

0

I have achieved this with the help of SOAP Message Handlers

I've written handler which implements SOAPHandler<SOAPMessageContext> and overridden its handleMessage(SOAPMessageContext context){} with following implementation.

//Get soapElement from your soap request.
if (soapElement.getTagName().equalsIgnoreCase("calculate_response")) {
       soapElement.setElementQName(
         new QName("http://com.sample.xyz/Messages",
                  "calculate_response",
                  "def"));
Sajjad
  • 853
  • 2
  • 15
  • 32