0

I've got an HttpClient instance that fetches a remote resource. I configure it to handle redirects.

        HttpParams params = new BasicHttpParams();
        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
            SOCKET_TIMEOUT);
        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                CONNECTION_TIMEOUT);
        params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT,
                CONN_MANAGER_TIMEOUT_VALUE);
        params.setParameter(ClientPNames.COOKIE_POLICY,
                CookiePolicy.BROWSER_COMPATIBILITY);

        params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
        params.setBooleanParameter(ClientPNames.REJECT_RELATIVE_REDIRECT,
                false);
        params.setIntParameter(ClientPNames.MAX_REDIRECTS, 4);
        httpclient = new DefaultHttpClient(cm, params);

When I'm calling it from inside a webapp (Tomcat6) I get the 301 response. When I call it from JSE environment I get the 200 final response (redirects get handled). My first suspect was classloading issues, but printing out the source of HttpClient class shows that both times it's loaded from httpclient-4.2.5.jar

Any ideas how else I can debug this?

ok2c
  • 26,450
  • 5
  • 63
  • 71
Kafkaesque
  • 1,233
  • 9
  • 13

2 Answers2

1

Run HttpClient with the context / wire logging turned on as described here and compare HTTP message exchanged in both environments.

ok2c
  • 26,450
  • 5
  • 63
  • 71
  • Thanks for the suggestion. The log lines show that it is most likely the same version of the code (goign by source code line numbers), but the only difference is that it does NOT handle redirects. Every log line before the redirect handling in the DefaultRequestDirector is identical. I can't see how the settings are any different. – Kafkaesque Dec 11 '13 at 09:03
  • @Kafkaesque User-Agent header generated by HttpClient should contain the release version. Please add both session logs to the original question or post them to the HttpClient user list. Discounting the possibility of green men from Mars hiding in the server room, HttpClient in default configuration should always automatically follow valid redirect locations. – ok2c Dec 11 '13 at 10:00
  • I was about to post the logs, but then tried upgrading to version 4.2.6 of httpclient and it appears to fix the problem. Thanks for the help – Kafkaesque Dec 11 '13 at 11:31
  • @Kafkaesque There has been no changes in 4.2.6 even vaguely related to redirect handling. You might want to check your server room. – ok2c Dec 11 '13 at 13:04
  • It's not solved... the problem is back. I don't believe I was high at the time... I really did see a 200 OK. – Kafkaesque Dec 11 '13 at 14:04
0

The HttpClient instance was shared throughout the webapp, including SolrJ (Solr client), which set the "follow redirect" param to false. I figured this out by creating a copy of the RequestDirector with extra logging lines. I could have simply looked for all calls of HttpClient.getParams(). The more you know.

Kafkaesque
  • 1,233
  • 9
  • 13