I updated HttpClient 3.0 to 4.1 and I have a problem with https connections
that take 5 seconds between synchronize and handshake message.
This delay does not occur with old version.
I'm using preemptive authentication and accepting all certificates.

Anybody can help me?

My code:

public static void main(String[] args) throws Exception {
    
        TrustStrategy trustStrategy = new TrustSelfSignedStrategy();
        X509HostnameVerifier hostnameVerifier = new
AllowAllHostnameVerifier();
        SchemeSocketFactory ssf = PlainSocketFactory.getSocketFactory();
        SSLSocketFactory sslSf = new SSLSocketFactory(trustStrategy,
hostnameVerifier);
        Scheme http = new Scheme(NmsProtocols.HTTP.getProtocolString(),
NmsProtocols.HTTP.getDefaultPort(), ssf);
        Scheme https = new Scheme(NmsProtocols.HTTPS.getProtocolString(),
NmsProtocols.HTTPS.getDefaultPort(), sslSf);
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(http);
        schemeRegistry.register(https);
        
        ClientConnectionManager connection = new
ThreadSafeClientConnManager(schemeRegistry);

        HttpParams httpParams = new BasicHttpParams();
        httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
60000);
        httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
        httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);
        
        CredentialsProvider credentialsProv = new
BasicCredentialsProvider();
        Credentials cred = new UsernamePasswordCredentials("admin",
"admin");
        credentialsProv.setCredentials(new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT, AuthScope.ANY_REALM), cred);
        
        HttpRequestRetryHandler retryHandler = new
DefaultHttpRequestRetryHandler(2, false);
        AbstractHttpClient httpClient = new DefaultHttpClient(connection);
        httpClient.setCredentialsProvider(credentialsProv);
        httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
        httpClient.setHttpRequestRetryHandler(retryHandler);
        httpClient.setParams(httpParams);
        
        HttpGet httpGet = new HttpGet("/teste.xml");
        HttpHost httpHost = new HttpHost("10.3.102.4", 443, "https");
        
        BasicScheme basicAuth = new BasicScheme();
        BasicHttpContext authContext = new BasicHttpContext();
        authContext.setAttribute("preemptive-auth", basicAuth);
        HttpResponse response = httpClient.execute(httpHost, httpGet,
authContext);
        System.out.println(response.getStatusLine());
        
    }

private static class PreemptiveAuth implements HttpRequestInterceptor {

    @Override
    public void process(final HttpRequest request, final HttpContext
context) throws HttpException {
        AuthState authState = (AuthState)
context.getAttribute(ClientContext.TARGET_AUTH_STATE);

        if (authState.getAuthScheme() == null) {
            AuthScheme authScheme = (AuthScheme)
context.getAttribute("preemptive-auth");
            CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(ClientContext.CREDS_PROVIDER);
            HttpHost targetHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (authScheme != null) {
                AuthScope authScope = new
AuthScope(targetHost.getHostName(), targetHost.getPort());
                Credentials creds = credsProvider.getCredentials(authScope);
                if (creds == null) {
                    throw new HttpException("No credentials for preemptive
authentication"); //$NON-NLS-1$
                }
                authState.setAuthScheme(authScheme);
                authState.setCredentials(creds);
            }
        }
    }
}
http://old.nabble.com/file/p29555624/EtherealPkts2.png 
-- 
View this message in context: 
http://old.nabble.com/5-seconds-to-handshake-with-https-connection-tp29555624p29555624.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to