Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5BE8092AC for ; Tue, 31 Jan 2012 14:08:03 +0000 (UTC) Received: (qmail 10700 invoked by uid 500); 31 Jan 2012 14:08:03 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 10655 invoked by uid 500); 31 Jan 2012 14:08:03 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 10648 invoked by uid 99); 31 Jan 2012 14:08:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Jan 2012 14:08:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Jan 2012 14:08:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 03955238897D for ; Tue, 31 Jan 2012 14:07:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1238566 - /httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java Date: Tue, 31 Jan 2012 14:07:38 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120131140739.03955238897D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Tue Jan 31 14:07:38 2012 New Revision: 1238566 URL: http://svn.apache.org/viewvc?rev=1238566&view=rev Log: Fixed connection initialization and connect timeout handling in HttpCore AB Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java?rev=1238566&r1=1238565&r2=1238566&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java (original) +++ httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java Tue Jan 31 14:07:38 2012 @@ -29,11 +29,10 @@ package org.apache.http.benchmark; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.InetSocketAddress; import java.net.Socket; import java.security.KeyStore; -import javax.net.SocketFactory; -import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; @@ -53,6 +52,7 @@ import org.apache.http.entity.ContentTyp import org.apache.http.impl.DefaultConnectionReuseStrategy; import org.apache.http.impl.DefaultHttpClientConnection; import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.apache.http.params.DefaultedHttpParams; import org.apache.http.protocol.BasicHttpProcessor; @@ -158,10 +158,15 @@ public class BenchmarkWorker implements HttpResponse response = null; DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); + String scheme = targetHost.getSchemeName(); String hostname = targetHost.getHostName(); int port = targetHost.getPort(); if (port == -1) { - port = 80; + if (scheme.equalsIgnoreCase("https")) { + port = 443; + } else { + port = 80; + } } // Populate the execution context @@ -176,7 +181,8 @@ public class BenchmarkWorker implements try { resetHeader(request); if (!conn.isOpen()) { - Socket socket = null; + + Socket socket; if ("https".equals(targetHost.getSchemeName())) { if (disableSSLVerification) { SSLContext sc = SSLContext.getInstance("SSL"); @@ -195,9 +201,8 @@ public class BenchmarkWorker implements } else { sc.init(null, trustAllCerts, null); } - - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - socket = sc.getSocketFactory().createSocket(hostname, port); + socket = sc.getSocketFactory().createSocket(); + } else { if (trustStorePath != null) { System.setProperty("javax.net.ssl.trustStore", trustStorePath); @@ -205,12 +210,18 @@ public class BenchmarkWorker implements if (trustStorePassword != null) { System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); } - SocketFactory socketFactory = SSLSocketFactory.getDefault(); - socket = socketFactory.createSocket(hostname, port); + socket = SSLSocketFactory.getDefault().createSocket(); } } else { - socket = new Socket(hostname, port); + socket = new Socket(); } + + int connTimeout = HttpConnectionParams.getConnectionTimeout(params); + int soTimeout = HttpConnectionParams.getSoTimeout(params); + + socket.setSoTimeout(soTimeout); + socket.connect(new InetSocketAddress(hostname, port), connTimeout); + conn.bind(socket, params); }