hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
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 GMT
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);
                 }
 



Mime
View raw message