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?