问题描述
在使用Spring-WS时,如何在客户端动态地设置一个自定义的HTTP头(而不是SOAP头)? 解析方案
在使用Spring-WS时,如何在客户端动态地设置一个自定义的HTTP头(而不是SOAP头)? 解析方案
pre> public class AddHttpHeaderInterceptor implements ClientInterceptor {
public boolean handleFault(MessageContext messageContext)
throws WebServiceClientException {
return true;
$ b $ public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
TransportContext context = TransportContextHolder.getTransportContext();
CommonsHttpConnection连接=(CommonsHttpConnection)context.getConnection();
PostMethod postMethod = connection.getPostMethod();
postMethod.addRequestHeader(fsreqid,123456);
返回true;
}
public boolean handleResponse(MessageContext messageContext)
抛出WebServiceClientException {
return true;
}
}
config:
< bean id =webServiceTemplateclass =org.springframework.ws.client.core.WebServiceTemplate>
...
< property name =interceptors>
< list>
< bean class =com.blah.AddHttpHeaderInterceptor/>
< / list>
< / property>
< / bean>
How do you set a custom HTTP header (not SOAP header) dynamically on the client side when using Spring-WS?
public class AddHttpHeaderInterceptor implements ClientInterceptor {
public boolean handleFault(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
TransportContext context = TransportContextHolder.getTransportContext();
CommonsHttpConnection connection = (CommonsHttpConnection) context.getConnection();
PostMethod postMethod = connection.getPostMethod();
postMethod.addRequestHeader( "fsreqid", "123456" );
return true;
}
public boolean handleResponse(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
}
config:
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
...
<property name="interceptors">
<list>
<bean class="com.blah.AddHttpHeaderInterceptor" />
</list>
</property>
</bean>
这篇关于使用Spring-WS客户端动态设置自定义HTTP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!