• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to recognize redirects?

 
Marwan Oweis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I have a servlet (call it Servlet A) that once called opens an Http Connection on another server with another servlet (call it Servlet B). This is done using java.net.HttpURLConnection.

The URL for Servlet B actually points to a load balancer, so my request gets redirected to the appropriate host.

My question is as follows: is there a way for Servlet A to get the host or ip to which it gets redirected?

Let me give an example:
1) Servlet A opens a connection to http://www.example.com/checkExample
2) www.example.com is the host name of load balancer. It redirects the request to http://www.redirectexample.com/checkExample

Is there a way for Servlet A to recognize/figure out the redirect URL: www.redirectexample.com?



Thanks,
Marwan
SCJP5, SCWCD5
[ June 09, 2008: Message edited by: Marwan Oweis ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not that I can see.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at the JavaDocs it appears that setFollowRedirects is true by default. Perhaps you could set that to false and handle the new address in your code.

Bill
 
Marwan Oweis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
Looking at the JavaDocs it appears that setFollowRedirects is true by default. Perhaps you could set that to false and handle the new address in your code.

Bill


Thanks! I saw that but it never registered.

I found a code sample in the apache commons project:


[ June 10, 2008: Message edited by: Marwan Oweis ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic