如何将 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 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/