• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to recognize redirects?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not that I can see.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic