I\'m trying to create a simple SOAP message to send from a client, but I am (seemingly) unable to change the URI of the \"soap\" namespace in the envelope.
This is w
In general you should not need to manually modify the SOAP namespace. What you probably want to achieve is to create a SOAP 1.2 message (which has a different namespace than SOAP 1.1). Try removing all namespace altering lines from your code and change the first line to
final SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
In case you REALLY need to specify which prefix that should be used, this code seems to work:
SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
sm.getSOAPPart().getEnvelope().setPrefix("soap");
sm.getSOAPPart().getEnvelope().removeNamespaceDeclaration("env");
sm.getSOAPHeader().setPrefix("soap");
sm.getSOAPBody().setPrefix("soap");