0

Goal: In our Spring Application we have to call a External service which uses a Namespace "http://www.w3.org/2003/05/soap-envelope".

Issue: Currently when I'm adding the following code snippet

webServiceTemplate.marshalSendAndReceive((Object) (SubmitTransaction2) request, new WebServiceMessageCallback() {
            private static final String PREFERRED_PREFIX = "SoapTest";

            @Override
            public void doWithMessage(WebServiceMessage message) {
                try {
                    if (message instanceof SaajSoapMessage) {
                        SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
                        SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
                        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
                        SOAPHeader header = envelope.getHeader();
                        SOAPBody body = soapMessage.getSOAPBody();
                        SOAPElement soapElement = envelope.addNamespaceDeclaration(PREFERRED_PREFIX, "http://www.w3.org/2003/05/soap-envelope");
                        envelope.setPrefix(PREFERRED_PREFIX);
                        header.setPrefix(PREFERRED_PREFIX);
                        body.setPrefix(PREFERRED_PREFIX);
                        soapMessage.saveChanges();
                    }
                } catch (SOAPException soape) {
                    soape.printStackTrace();
                }
            }
        });

The SOAP Envelope I get is

<SoapTest:Envelope xmlns:SoapTest="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

But if I just change this one line

envelope.setPrefix("SOAP-ENV");

I get this response

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SoapTest="http://www.w3.org/2003/05/soap-envelope">

Can anyone suggest why is it that SoapTest namespace value gets overridden as soon as I assign it to SOAPEnvelope?

  • The namespace for [SOAP 1.1](https://www.w3.org/TR/2000/NOTE-SOAP-20000508/) is `http://schemas.xmlsoap.org/soap/envelope/`. The namespace for [SOAP 1.2](https://www.w3.org/TR/2007/REC-soap12-part0-20070427/) is `http://www.w3.org/2003/05/soap-envelope`. The External service uses SOAP 1.2, but Spring defaults to SOAP 1.1, so you need to configure Spring to use SOAP 1.2. Attempting to override the SOAP namespace is not the way. – Andreas Feb 12 '21 at 00:37
  • Thanks Andreas. You pointed me exactly what I was doing wrong. It worked. – mitul bhatnagar Feb 12 '21 at 01:46

0 Answers0