【问题标题】:Spring web service template set MustUnderstand to none or falseSpring Web 服务模板将 MustUnderstand 设置为 none 或 false
【发布时间】:2016-08-09 03:28:18
【问题描述】:

如何将 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);
        }
    }
}

请告诉我如何将“Must understand”设置为 none 或 false 并将 WS-A 版本 设置为“200508”而不是“200408”?

提前致谢

【问题讨论】:

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


    【解决方案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>
    

    其余字段也一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-11
      • 2014-10-01
      • 1970-01-01
      • 2019-12-18
      • 2013-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多