Setting a custom HTTP header dynamically with Spri

2020-02-17 08:49发布

How do you set a custom HTTP header (not SOAP header) dynamically on the client side when using Spring-WS?

7条回答
淡お忘
2楼-- · 2020-02-17 09:44

ClientInterceptor works great for static header value. But it is not possible to use it when a different value should be applied per each request. In that case WebServiceMessageCallback is helpful:

final String dynamicParameter = //...

webServiceOperations.marshalSendAndReceive(request, 
    new WebServiceMessageCallback() {
        void doWithMessage(WebServiceMessage message) {
            TransportContext context = TransportContextHolder.getTransportContext();
            CommonsHttpConnection connection = (CommonsHttpConnection) context.getConnection();
            PostMethod postMethod = connection.getPostMethod();
            postMethod.addRequestHeader( "fsreqid", dynamicParameter );
        }
}
查看更多
登录 后发表回答