jim ma wrote:
The problem is that I can not simply correct that URL and
send it for the f
first  time.   The request url is generated by other  application or in some
condition sometimes provided by  user . The client side  can not  judge "
http://localhost:8080/foo";  is a request for "foo"   resource in root
context or a request url for the default page in foo context.   Server side
has that information and can judge it .  If there is a foo context , it will
reply the redirect response.
httpunit can help that.  Actually I want to know if there is second
option(configure tomcat to support that )
Tomcat behaves correctly. Your clients send incorrect URLs.

You really should not hack Tomcat to handle redirects in a different way.

Since you use HttpClient (I mean org.apache.commons.httpclient.HttpClient) you can check response status code and perform second request if status code is one of HttpStatus.SC_MOVED_TEMPORARILY or HttpStatus.SC_MOVED_PERMANENTLY. E.g.:


client.executeMethod(method);
responseCode = method.getStatusCode();
responseBody = method.getResponseBodyAsString();
if (responseCode == HttpStatus.SC_MOVED_TEMPORARILY || responseCode == HttpStatus.SC_MOVED_PERMANENTLY) {
   String redirectLocation;
   Header locationHeader = method.getResponseHeader("Location");
   if (locationHeader != null) {
       redirectLocation = locationHeader.getValue();
       method = new GetMethod(redirectLocation);
       client.executeMethod(method);
       responseCode = method.getStatusCode();
       responseBody = method.getResponseBodyAsString();
   }
}


I really do not understand your problem ;-)

If you don't have absolutely any control on URLs clients generate or http-client code your application uses you can try following: Implement simle servlet that will accept any URL as parameter. Servlet will use http-client in way described before (e.g. will handle redirects). Tell your clients to generate URLs like: http://host/your_servlet?url=url_to_fetch
In other words you should implemet proxy that will handle redirects itself.
Finally, your clients will not see any 302 redirects.

--
Mikolaj Rydzewski <[EMAIL PROTECTED]>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to