Setting a custom HTTP header dynamically with Spring-WS client

后端 未结 7 575
我在风中等你
我在风中等你 2020-12-24 05:53

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

7条回答
  •  北海茫月
    2020-12-24 06:42

    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();
         HttpComponentsConnection connection =(HttpComponentsConnection) context.getConnection();
         connection.addRequestHeader("name", "suman");
    
        return true;
    }
    
    public boolean handleResponse(MessageContext messageContext)
            throws WebServiceClientException {
        return true;
    }
    
    }
    

    config:

        
        ...
        
            
                
            
        
    
    

提交回复
热议问题