You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Renier Rhode <re...@gmail.com> on 2008/10/02 10:30:55 UTC

Custom HTTP Headers

Hi,

I need to add custom HTTP headers to an outgoing request. The system I'm 
integrating with requires the a session identifier to be included in the 
HTTP headers on every request.

I've generated the client code using the included wsdl2java.

Any help would be appreciated.

Thanks,
Renier


Re: Custom HTTP Headers

Posted by Renier Rhode <re...@gmail.com>.
Thanks Ian, that did the trick!

Ian Roberts wrote:
> Renier Rhode wrote:
>   
>> ---- BEGIN Webservice Interaction
>> 3) Call are made to the Webservice with the JSESSIONID ( retrieved in
>> step 2 ) tacked on as an HTTP header.
>> --- END Webservice Interaction
>>     
>
> You can set a specific cookie in the client policy which will be sent
> with every request made with that proxy.  This does mean you can't use
> the same client proxy object ("myService" below) for requests with
> different session IDs at the same time, but that should be a reasonable
> tradeoff.
>
> // do the authentication and get the JSESSIONID
> JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
> factory.setServiceClass(MyService.class);
> factory.setAddress("http://....");
> // whatever else you need to set up...
>
> MyService myService = (MyService)factory.create();
>
> Client client = ClientProxy.getClient(cxfStub);
> Conduit conduit = client.getConduit();
> if(conduit instanceof HTTPConduit) {
>   HTTPClientPolicy policy = ((HTTPConduit)conduit).getClient();
>   if(policy == null) {
>     policy = new HTTPClientPolicy();
>     ((HTTPConduit)conduit).setClient(policy);
>   }
>   policy.setCookie(/*value of the Cookie: header*/);
> }
>
> // use myService here and it will pass your cookie with each request
>
> Ian
>
>   



Re: Custom HTTP Headers

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Renier Rhode wrote:
> ---- BEGIN Webservice Interaction
> 3) Call are made to the Webservice with the JSESSIONID ( retrieved in
> step 2 ) tacked on as an HTTP header.
> --- END Webservice Interaction

You can set a specific cookie in the client policy which will be sent
with every request made with that proxy.  This does mean you can't use
the same client proxy object ("myService" below) for requests with
different session IDs at the same time, but that should be a reasonable
tradeoff.

// do the authentication and get the JSESSIONID
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyService.class);
factory.setAddress("http://....");
// whatever else you need to set up...

MyService myService = (MyService)factory.create();

Client client = ClientProxy.getClient(cxfStub);
Conduit conduit = client.getConduit();
if(conduit instanceof HTTPConduit) {
  HTTPClientPolicy policy = ((HTTPConduit)conduit).getClient();
  if(policy == null) {
    policy = new HTTPClientPolicy();
    ((HTTPConduit)conduit).setClient(policy);
  }
  policy.setCookie(/*value of the Cookie: header*/);
}

// use myService here and it will pass your cookie with each request

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

Re: Custom HTTP Headers

Posted by Renier Rhode <re...@gmail.com>.
Hi Ian,

Thank you for the prompt response.

I should have clarified my problem further.

The authentication process is external to the web service.

The vendor's software flow works as follows :

1) An https request is made using Commons HTTP Client / URLConnection, 
the username and password are included as request headers.

2) The JSESSIONID  in the response is extracted

---- BEGIN Webservice Interaction
3) Call are made to the Webservice with the JSESSIONID ( retrieved in 
step 2 ) tacked on as an HTTP header.
--- END Webservice Interaction

4) Logoff url needs to be invoked using the JSESSIONID.

The way I understand it is if the authentication was part of the web 
service interaction the approach you referred me to would work, but in 
my case where the authentication is external it would not?

Thanks,
Renier

Ian Roberts wrote:
> Renier Rhode wrote:
>   
>> Hi,
>>
>> I need to add custom HTTP headers to an outgoing request. The system I'm
>> integrating with requires the a session identifier to be included in the
>> HTTP headers on every request.
>>
>> I've generated the client code using the included wsdl2java.
>>
>> Any help would be appreciated.
>>     
>
> http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html
> explains how to maintain the session in JAX-WS.  The blog is written for
> Glassfish Metro (the Sun RI) but the same approach with the
> SESSION_MAINTAIN_PROPERTY works on CXF too.
>
> Ian
>
>   



Re: Custom HTTP Headers

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Renier Rhode wrote:
> Hi,
> 
> I need to add custom HTTP headers to an outgoing request. The system I'm
> integrating with requires the a session identifier to be included in the
> HTTP headers on every request.
> 
> I've generated the client code using the included wsdl2java.
> 
> Any help would be appreciated.

http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html
explains how to maintain the session in JAX-WS.  The blog is written for
Glassfish Metro (the Sun RI) but the same approach with the
SESSION_MAINTAIN_PROPERTY works on CXF too.

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK