Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a custom HTTP header dynamically with Spring-WS client

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

like image 660
user366735 Avatar asked Jul 02 '10 21:07

user366735


1 Answers

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:

    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">     ...     <property name="interceptors">         <list>             <bean class="com.blah.AddHttpHeaderInterceptor" />         </list>     </property> </bean> 
like image 97
user366735 Avatar answered Sep 19 '22 04:09

user366735