Kafkaesque
Kafkaesque

Reputation: 1283

HttpClient 4 redirect handling different inside Tomcat

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?

Upvotes: 0

Views: 230

Answers (2)

Kafkaesque
Kafkaesque

Reputation: 1283

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.

Upvotes: 0

ok2c
ok2c

Reputation: 27538

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

Upvotes: 1

Related Questions