How to change “SOAP-ENV” default prefix of Spring-WS

后端 未结 3 2161
清歌不尽
清歌不尽 2021-02-13 15:29

I\'ve created a web service using Spring-WS. To maintain compatibility with the old system, I need to change namespace prefix from SOAP-ENV to soap.

相关标签:
3条回答
  • 2021-02-13 15:37

    I use SAAJ. Try this.

    1. soapEnvelope.removeNamespaceDeclaration("SOAP-ENV");
    2. soapEnvelope.addNamespaceDeclaration("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    3. soapEnvelope.setPrefix("soapenv");
    4. soapHeader.setPrefix("soapenv");
    5. soapBody.setPrefix("soapenv");

    Don't forget: soapMessage.saveChanges();

    Reference:Changing the default XML namespace prefix generated with JAXWS

    0 讨论(0)
  • 2021-02-13 15:40

    A better solution

    Use SOAPMessage API instead of DOM.

      private void alterSoapEnvelope(SaajSoapMessage soapResponse) {
        try {
          SOAPMessage soapMessage = soapResponse.getSaajMessage();
          SOAPPart soapPart = soapMessage.getSOAPPart();
          SOAPEnvelope envelope = soapPart.getEnvelope();
          SOAPHeader header = soapMessage.getSOAPHeader();
          SOAPBody body = soapMessage.getSOAPBody();
          SOAPFault fault = body.getFault();
          envelope.removeNamespaceDeclaration(envelope.getPrefix());
          envelope.addNamespaceDeclaration(PREFERRED_PREFIX, SOAP_ENV_NAMESPACE);
          envelope.setPrefix(PREFERRED_PREFIX);
          header.setPrefix(PREFERRED_PREFIX);
          body.setPrefix(PREFERRED_PREFIX);
          if (fault != null) {
            fault.setPrefix(PREFERRED_PREFIX);
          }
        } catch (SOAPException e) {
          e.printStackTrace();
        }
      }
    

    It's much faster now.

    0 讨论(0)
  • 2021-02-13 15:40

    Additional Point :

    you have to extend your Webservice config class with WsConfigurationAdapter and add your CustomEndpointInterceptor in the webservice config class as stated below.

    Then only the interceptor works.

    Refer below link for more details

    https://memorynotfound.com/spring-ws-intercept-request-response-soap-messages/

    0 讨论(0)
提交回复
热议问题