我想使用 Spring Integration 发送一条 SOAP 消息。我使用Java配置。 我已经尝试过下面的拦截器,但是 spring 集成将尖括号 (<>) 转换为 html 转义字符。
import org.springframework.ws.client.WebServiceClientException;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapHeaderElement;
import org.springframework.ws.soap.SoapMessage;
public class MyAuthInterceptor implements ClientInterceptor {
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
SoapMessage soapMessage = (SoapMessage) messageContext.getRequest();
SoapHeader sh = soapMessage.getSoapHeader();
QName name = new QName("http://...", "myAuth", "aut");
sh.addHeaderElement(name).setText("<username>TestUser</username>" + "<password>TestPass</password>");
return true;
}
这是生成的 SOAP 头:
<SOAP-ENV:Header>
<aut:myAuth xmlns:aut="http://.../"><username>TestUser</username><password>TestPass</password></aut:myAuth>
</SOAP-ENV:Header>
这是我的配置:
@Configuration
@EnableIntegration
public class SpringIntegrationConfiguration {
@Bean
public PublishSubscribeChannel inputChannel() {
return new PublishSubscribeChannel();
}
@Bean
public ClientInterceptor myAuthInterceptor() {
return new MyAuthInterceptor();
}
@Bean
@ServiceActivator(inputChannel = "inputChannel")
public SimpleWebServiceOutboundGateway myOutput(ClientInterceptor mekAuthInterceptor) {
SimpleWebServiceOutboundGateway simpleWebServiceOutboundGateway = new SimpleWebServiceOutboundGateway("http://...");
simpleWebServiceOutboundGateway.setInterceptors(myAuthInterceptor);
return simpleWebServiceOutboundGateway;
}
}
如何在不脱离尖括号的情况下设置 SOAP 头?
最佳答案
您必须使用 addChildElement
来构建它,而不是将其设置为文本。
关于java - 如何在Spring Integration中设置soap header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35946417/