Spring Web服务模板将MustUnderstand设置为none或false

时间:2016-08-09 03:28:18

标签: java soap spring-boot soap-client spring-ws

如何将MustUnderstand设置为none或false。我正在使用spring boot和web服务模板来创建客户端。

的pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-ws</artifactId>
</dependency>

配置

@Configuration
public class BrokerConnectionServiceConfiguration {

    @Autowired
    private LuiUrlBuilder luiUrlBuilder;    

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setPackagesToScan("com.example");
        return marshaller;
    }    

    @Bean
    public BrokerConnectionServiceClient brokerConnectionServiceClient(Jaxb2Marshaller marshaller) {
        BrokerConnectionServiceClient client = new BrokerConnectionServiceClient();
        client.setDefaultUri(luiUrlBuilder.getConnectionServiceUri());
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);

        return client;
    }

BrokerConnectionServiceClient.java

public class BrokerConnectionServiceClient extends WebServiceGatewaySupport {

    private static final Logger log = LoggerFactory.getLogger(BrokerConnectionServiceClient.class);

    @Autowired
    private LuiUrlBuilder luiUrlBuilder;    

    public void getBrokerConnectionServiceData(ConnectionRequestType connectionRequestType) {

        log.debug("inside getBrokerConnectionServiceData");

        try {
            getWebServiceTemplate()
                    .marshalSendAndReceive(
                            new JAXBElement<>(new QName(Constants.BROKER_CONNECTION_SERVICE_NAMESPACE_URI, Constants.BROKER_CONNECTION_SERVICE_LOCAL_PART), ConnectionRequestType.class, connectionRequestType),
                            new ActionCallback(new URI(luiUrlBuilder.getConnectionServiceCallBackLocation()), new Addressing200408()));
        } catch (URISyntaxException e) {
            log.trace("URISyntaxException occurred", e);
        }
    }
}

enter image description here

有些正文可以让我知道如何将“Must understand”设置为无或错误,将 WS-A版设置为“ 200508 ”而不是“的 200408

提前致谢

1 个答案:

答案 0 :(得分:1)

使用WebServiceMessageCallback我们可以实现。 ActionCallback实习生实现了WebServiceMessageCallback。

<强> BrokerConnectionServiceClient.java

getWebServiceTemplate()
.marshalSendAndReceive(
      new JAXBElement<>(new QName(Constants.BROKER_CONNECTION_SERVICE_NAMESPACE_URI, Constants.BROKER_CONNECTION_SERVICE_LOCAL_PART), ConnectionRequestType.class, connectionRequestType),
      new WebServiceMessageCallback() {
      @Override
      public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
      SOAPMessage soapMessage = ((SaajSoapMessage) message).getSaajMessage();
      SOAPHeader soapHeader = soapMessage.getSOAPHeader();

      SOAPHeaderElement actionElement = soapHeader.addHeaderElement(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing", "Action", "wsa"));
      actionElement.setMustUnderstand(false);
      actionElement.setTextContent("ConnectionService");
    }
});

<强>输出

<wsa:Action soapenv:mustUnderstand="0">ConnectionService</wsa:Action>

对于剩余的字段也一样。