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

标签 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”设置为 none 或 false 并将 WS-A version 设置为“200508” "而不是 "200408"?

提前致谢

最佳答案

使用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>

其余字段也一样。

关于java - Spring Web 服务模板将 MustUnderstand 设置为 none 或 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38841560/

相关文章:

web-services - 如何在 ColdFusion 中进行同步 SOAP 调用

xml - 如何更改此 WSDL 中的 namespace 前缀?

spring-boot - Spring Boot 2.0.0 + OAuth2

java - 显示 JSP 内渲染的 Spring Boot buildInfo() 版本

任何对象的java toString

java - 增强现实中的模式匹配

Java 更新 1.6.0_26 导致 SOAP 异常 - NoClassDefFoundError :Could not initialize FastInfosetReflection

spring - 在运行时动态添加jar到SpringBoot

java - 如何在 Java/Scala 中正确地将字节流保存到文件中?如何修复错误保存的流?

java - 来自 application.properties 的 Spring Boot 配置