hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd W Lainhart <lainh...@us.ibm.com>
Subject Re: HttpClient with CircularRedirectException
Date Tue, 14 Oct 2014 14:14:25 GMT
You can turn off circular redirect checking.  You haven't said what 
version of the library you're using.  Assuming the latest, take a look at 
RequestConfig.Builder.  There are other options/mechanisms for raising the 
limits, or taking part in the analysis process.





Todd Lainhart
Rational software
IBM Corporation
550 King Street, Littleton, MA 01460-1250
1-978-899-4705
2-276-4705 (T/L)
lainhart@us.ibm.com




From:   srihari na <namasrihari@gmail.com>
To:     HttpClient User Discussion <httpclient-users@hc.apache.org>
Date:   10/14/2014 10:04 AM
Subject:        HttpClient with CircularRedirectException



Hello,

We are trying a simple Get request to a server which is seems to be in
circular redirection and end up in CircularRedirectException, based on 
some
internet search hits there is a mechanism to disable the
circuralRedirectionException, however we hit maximum redirection hits(100)
occurred. We were able to hit the same server with a simple standalone 
java
program, Mozilla and Chrome ReST client which is working fine where as the
Apache client libraries is throwing the above mentioned exception. I have
pasted the code snippet below and java program, please help me overcome
this situation. The Authorization header is intentionally garbled for
security reasons however with the code error is reproduced and with proper
header also we see the problem.

DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            KeyStore trustStore  =
KeyStore.getInstance(KeyStore.getDefaultType());
            FileInputStream instream = new FileInputStream(new
File("C:\\IBMJDK7\\jre\\lib\\security\\cacerts"));
            try {
                trustStore.load(instream, "changeit".toCharArray());
            } finally {
                try { instream.close(); } catch (Exception ignore) {}
            }

            SSLSocketFactory socketFactory = new
SSLSocketFactory(trustStore);
            Scheme sch = new Scheme("https", 443, socketFactory);

httpclient.getConnectionManager().getSchemeRegistry().register(sch);

            HttpGet httpget = new HttpGet("
https://login.eloqua.com:443/id/
");
            httpget.addHeader("Authorization", "Basic
VGVjaG5vbG9neVBhcnRuZXJQZXJzaX");
            httpget.addHeader("Accept","application/json");
            System.out.println("executing request" +
httpget.getRequestLine());

            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " +
entity.getContentLength());
            }
            EntityUtils.consume(entity);

        } finally {
            httpclient.getConnectionManager().shutdown();
        }

Sample Java Code

public class TestEloquaJavaHttpUrl {

    public static void main(String [] args) throws Exception {
        // configure the SSLContext with a TrustManager
        SSLContext ctx = SSLContext.getInstance("SSLv3");
        ctx.init(new KeyManager[0], new TrustManager[] {new
DefaultTrustManager()}, new SecureRandom());
        SSLContext.setDefault(ctx);

        URL url = new URL("https://login.eloqua.com:443/id/");
        HttpsURLConnection conn = (HttpsURLConnection) 
url.openConnection();
        conn.setRequestProperty("Authorization", "Basic
VGVjaG5vbG9neVBhcnRuZXJQZXJzaX");
        conn.setRequestProperty("Accept", "application/json");
        conn.setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        });
        System.out.println(conn.getResponseCode());
        conn.disconnect();
    }

    private static class DefaultTrustManager implements X509TrustManager {

        @Override
        public void checkClientTrusted(X509Certificate[] arg0, String 
arg1)
throws CertificateException {}

        @Override
        public void checkServerTrusted(X509Certificate[] arg0, String 
arg1)
throws CertificateException {}

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }
}

-- 
Regards,
Srihari NA


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message