Spring integration 如何在soap请求中将会话设置为cookie
我使用ws:outbound gateway调用soap web服务,该服务期望在cookie中设置会话id 我在上述ws-gateway的请求回调中获取此会话id 我试图像下面那样丰富头部,但这是添加soap头部,而不是http头部Spring integration 如何在soap请求中将会话设置为cookie,spring-integration,Spring Integration,我使用ws:outbound gateway调用soap web服务,该服务期望在cookie中设置会话id 我在上述ws-gateway的请求回调中获取此会话id 我试图像下面那样丰富头部,但这是添加soap头部,而不是http头部 <int:chain id="login.session.extractor.chain" input-channel="login.ws.out" output-channel="login.gateway.out">
<int:chain id="login.session.extractor.chain"
input-channel="login.ws.out" output-channel="login.gateway.out">
<cic:xml-multi-node-extractor
path-selector="${login.session.path}" />
<int:header-enricher>
<int:header name="COOKIE" expression="'JSESSIONID=' + payload['${login.session.path}']" />
</int:header-enricher>
<int:transformer expression="payload['payload']" />
</int:chain>
很有可能,您只能通过自定义
的消息发送者来实现:
公共类CustomHttpComponentMessageSender扩展了HttpComponentMessageSender{
@凌驾
公共WebServiceConnectionCreateConnection(URI)引发IOException{
字符串cookie=null;
HttpComponentsConnection conn=(HttpComponentsConnection)super.createConnection(uri);
HttpPost postMethod=conn.getHttpPost();
曲奇=”;
postMethod.addHeader(“Cookie”,Cookie);
返回连接;
}
}
附加的自定义WebServiceMessageCallback
可能会将消息
发送到ThreadLocal
变量,以从CustomHttpComponentMessageSender
中处理COOKIE
头,该CustomHttpComponentMessageSender是我尝试的另一种方法,即使用拦截器ws-outbound-gateway如下所示,现在这对我来说非常有效。我只是想看看除了编写自定义代码之外,是否还有其他配置方法可以做到这一点
public class HttpHeaderInterceptor implements ClientInterceptor {
public boolean handleFault(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
TransportContext context = TransportContextHolder.getTransportContext();
HttpUrlConnection connection = (HttpUrlConnection) context
.getConnection();
connection.getConnection().addRequestProperty("COOKIE",<custom value>);
return true;
}
public boolean handleResponse(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
}
公共类HttpHeaderInterceptor实现ClientInterceptor{
公共布尔handleFault(MessageContext MessageContext)
抛出WebServiceClientException{
返回true;
}
公共布尔HandlerRequest(MessageContext MessageContext)
抛出WebServiceClientException{
TransportContext上下文=TransportContextHolder.getTransportContext();
HttpUrlConnection=(HttpUrlConnection)上下文
.getConnection();
connection.getConnection().addRequestProperty(“COOKIE”),以及;
返回true;
}
公共布尔HandlerResponse(MessageContext MessageContext)
抛出WebServiceClientException{
返回true;
}
}
感谢Artem的回复。
public class CustomHttpComponentsMessageSender extends HttpComponentsMessageSender {
@Override
public WebServiceConnection createConnection(URI uri) throws IOException {
String cookie = null;
HttpComponentsConnection conn = (HttpComponentsConnection) super.createConnection(uri);
HttpPost postMethod = conn.getHttpPost();
cookie = "<Your Custom Cookie>";
postMethod.addHeader("Cookie", cookie);
return conn;
}
}
public class HttpHeaderInterceptor implements ClientInterceptor {
public boolean handleFault(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
TransportContext context = TransportContextHolder.getTransportContext();
HttpUrlConnection connection = (HttpUrlConnection) context
.getConnection();
connection.getConnection().addRequestProperty("COOKIE",<custom value>);
return true;
}
public boolean handleResponse(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
}