users@jersey.java.net

[Jersey] Re: Jersey-client following a Redirect response

From: Will Ferguson <WFerguson_at_northplains.com>
Date: Wed, 5 Feb 2014 09:46:31 +0000

Hi Christian,

I had to do something similar when I was receiving a redirect from one REST service to an amazon S3 URL, and needed to modify the headers on the redirect.

There may be a Jersey way, but I implemented it within HttpClient as I was using the ApacheConnector.

I extended DefaultRedirectStrategy, and override the method:

getRedirect(HttpRequest request, HttpResponse response, HttpContext context)

modify the headers when the 302 was to amazon, and then return a call to super(...).

I think this should work for you too.

To stitch into Jersey / ApacheConnector you'll want to do something like:

ApacheConnector connector = new ApacheConnector(jerseyClientConfig);
((DefaultHttpClient)connector.getHttpClient()).setRedirectStrategy(new S3RedirectStrategy());

You'll need to keep follow redirects enabled for this to work.

Hope this helps,

Will


________________________________
From: Christian Greene [christian.greene_at_oracle.com]
Sent: 04 February 2014 23:24
To: users_at_jersey.java.net
Subject: [Jersey] Jersey-client following a Redirect response

We selected Jersey-client to access REST services after having success implementing Jersey server. Upon making a request to a certain 3rd party “login” REST service, that service redirects with 302 to another “login-success” URL. The response from that URL implies it is not using the same JSESSIONID as in the cookie I sent in my original request. I could not find any client-side filter/interceptor that would allow me to set the cookie on the redirection. What am I missing? Or do I need to implement redirection myself; is there an example ClientReponseFilter that does such a thing?

[Oracle]<http://www.oracle.com/>
Christian Greene | Senior Principal Applications Developer
Phone: +1 5126715140<tel:+1%205126715140> | Fax: +1 5126715140<UrlBlockedError.aspx>
Oracle Retail R&D
9600 N Mopac Expressway | Austin, TX 78759
[Green Oracle]<http://www.oracle.com/commitment>

Oracle is committed to developing practices and products that help protect the environment







image001.gif
(image/gif attachment: image001.gif)

image002.gif
(image/gif attachment: image002.gif)