Cannot change soap URI in envelope using java SoapMessage

前端 未结 1 359
情歌与酒
情歌与酒 2020-12-30 15:11

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

相关标签:
1条回答
  • 2020-12-30 15:17

    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");
    
    0 讨论(0)
提交回复
热议问题