ASF Bugzilla – Attachment 33566 Details for
Bug 59020
Performance : Avoid useless SSL Context initialization when HTTPClient4 is used
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch fixing this issue
BUG_59020.patch (text/plain), 9.25 KB, created by
Philippe Mouawad
on 2016-02-17 18:44:51 UTC
(
hide
)
Description:
Patch fixing this issue
Filename:
MIME Type:
Creator:
Philippe Mouawad
Created:
2016-02-17 18:44:51 UTC
Size:
9.25 KB
patch
obsolete
>Index: src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java >=================================================================== >--- src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (revision 1730896) >+++ src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (working copy) >@@ -28,7 +28,6 @@ > import java.net.URL; > import java.net.URLDecoder; > import java.nio.charset.Charset; >-import java.security.GeneralSecurityException; > import java.security.PrivilegedActionException; > import java.security.PrivilegedExceptionAction; > import java.util.ArrayList; >@@ -78,6 +77,7 @@ > import org.apache.http.conn.ConnectionKeepAliveStrategy; > import org.apache.http.conn.DnsResolver; > import org.apache.http.conn.params.ConnRoutePNames; >+import org.apache.http.conn.scheme.PlainSocketFactory; > import org.apache.http.conn.scheme.Scheme; > import org.apache.http.conn.scheme.SchemeRegistry; > import org.apache.http.entity.ContentType; >@@ -92,7 +92,6 @@ > import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; > import org.apache.http.impl.client.DefaultHttpClient; > import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; >-import org.apache.http.impl.conn.SchemeRegistryFactory; > import org.apache.http.impl.conn.SystemDefaultDnsResolver; > import org.apache.http.message.BasicNameValuePair; > import org.apache.http.params.BasicHttpParams; >@@ -110,11 +109,9 @@ > import org.apache.jmeter.protocol.http.control.CookieManager; > import org.apache.jmeter.protocol.http.control.HeaderManager; > import org.apache.jmeter.protocol.http.util.EncoderCache; >-import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory; > import org.apache.jmeter.protocol.http.util.HTTPArgument; > import org.apache.jmeter.protocol.http.util.HTTPConstants; > import org.apache.jmeter.protocol.http.util.HTTPFileArg; >-import org.apache.jmeter.protocol.http.util.SlowHC4SSLSocketFactory; > import org.apache.jmeter.protocol.http.util.SlowHC4SocketFactory; > import org.apache.jmeter.samplers.SampleResult; > import org.apache.jmeter.services.FileServer; >@@ -197,9 +194,6 @@ > // Scheme used for slow HTTP sockets. Cannot be set as a default, because must be set on an HttpClient instance. > private static final Scheme SLOW_HTTP; > >- // We always want to override the HTTPS scheme, because we want to trust all certificates and hosts >- private static final Scheme HTTPS_SCHEME; >- > /* > * Create a set of default parameters from the ones initially created. > * This allows the defaults to be overridden if necessary from the properties file. >@@ -229,24 +223,6 @@ > SLOW_HTTP = null; > } > >- // We always want to override the HTTPS scheme >- Scheme https = null; >- if (CPS_HTTPS > 0) { >- log.info("Setting up HTTPS SlowProtocol, cps="+CPS_HTTPS); >- try { >- https = new Scheme(HTTPConstants.PROTOCOL_HTTPS, HTTPConstants.DEFAULT_HTTPS_PORT, new SlowHC4SSLSocketFactory(CPS_HTTPS)); >- } catch (GeneralSecurityException e) { >- log.warn("Failed to initialise SLOW_HTTPS scheme, cps="+CPS_HTTPS, e); >- } >- } else { >- log.info("Setting up HTTPS TrustAll scheme"); >- try { >- https = new Scheme(HTTPConstants.PROTOCOL_HTTPS, HTTPConstants.DEFAULT_HTTPS_PORT, new HC4TrustAllSSLSocketFactory()); >- } catch (GeneralSecurityException e) { >- log.warn("Failed to initialise HTTPS TrustAll scheme", e); >- } >- } >- HTTPS_SCHEME = https; > if (localAddress != null){ > DEFAULT_HTTP_PARAMS.setParameter(ConnRoutePNames.LOCAL_ADDRESS, localAddress); > } >@@ -726,7 +702,7 @@ > if (resolver == null) { > resolver = new SystemDefaultDnsResolver(); > } >- ClientConnectionManager connManager = new MeasuringConnectionManager(SchemeRegistryFactory.createDefault(), resolver); >+ ClientConnectionManager connManager = new MeasuringConnectionManager(createDefaultSchemeRegistry(), resolver); > > httpClient = new DefaultHttpClient(connManager, clientParams) { > @Override >@@ -751,10 +727,6 @@ > schemeRegistry.register(SLOW_HTTP); > } > >- if (HTTPS_SCHEME != null){ >- schemeRegistry.register(HTTPS_SCHEME); >- } >- > // Set up proxy details > if(useProxy) { > >@@ -793,6 +765,18 @@ > } > > /** >+ * Setup LazySchemeSocketFactory >+ */ >+ private SchemeRegistry createDefaultSchemeRegistry() { >+ final SchemeRegistry registry = new SchemeRegistry(); >+ registry.register( >+ new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); >+ registry.register( >+ new Scheme("https", 443, new LazySchemeSocketFactory())); >+ return registry; >+ } >+ >+ /** > * Setup following elements on httpRequest: > * <ul> > * <li>ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING</li> >Index: src/protocol/http/org/apache/jmeter/protocol/http/sampler/LazySchemeSocketFactory.java >=================================================================== >--- src/protocol/http/org/apache/jmeter/protocol/http/sampler/LazySchemeSocketFactory.java (revision 0) >+++ src/protocol/http/org/apache/jmeter/protocol/http/sampler/LazySchemeSocketFactory.java (revision 0) >@@ -0,0 +1,100 @@ >+package org.apache.jmeter.protocol.http.sampler; >+ >+import java.io.IOException; >+import java.net.InetSocketAddress; >+import java.net.Socket; >+import java.net.UnknownHostException; >+import java.security.GeneralSecurityException; >+ >+import org.apache.http.conn.ConnectTimeoutException; >+import org.apache.http.conn.scheme.Scheme; >+import org.apache.http.conn.scheme.SchemeSocketFactory; >+import org.apache.http.conn.ssl.SSLInitializationException; >+import org.apache.http.conn.ssl.SSLSocketFactory; >+import org.apache.http.params.HttpParams; >+import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory; >+import org.apache.jmeter.protocol.http.util.HTTPConstants; >+import org.apache.jmeter.protocol.http.util.SlowHC4SSLSocketFactory; >+import org.apache.jmeter.util.JMeterUtils; >+import org.apache.jorphan.logging.LoggingManager; >+import org.apache.log.Logger; >+ >+/** >+ * Lazy SchemeSocketFactory that lazily initializes HTTPS Socket Factory >+ * @since 3.0 >+ */ >+public class LazySchemeSocketFactory implements SchemeSocketFactory{ >+ private static final Logger LOG = LoggingManager.getLoggerForClass(); >+ >+ protected static final int CPS_HTTPS = JMeterUtils.getPropDefault("httpclient.socket.https.cps", 0); >+ private SchemeSocketFactory adaptee; >+ public LazySchemeSocketFactory() { >+ } >+ /** >+ * @param params >+ * @return >+ * @throws IOException >+ * @see org.apache.http.conn.scheme.SchemeSocketFactory#createSocket(org.apache.http.params.HttpParams) >+ */ >+ @Override >+ public Socket createSocket(HttpParams params) throws IOException { >+ checkAndInit(); >+ return adaptee.createSocket(params); >+ } >+ /** >+ * @throws SSLInitializationException >+ */ >+ private void checkAndInit() throws SSLInitializationException { >+ if(adaptee == null) { >+ synchronized (this) { >+ if(adaptee==null) { >+ if (CPS_HTTPS > 0) { >+ LOG.info("Setting up HTTPS SlowProtocol, cps="+CPS_HTTPS); >+ try { >+ adaptee = new SlowHC4SSLSocketFactory(CPS_HTTPS); >+ } catch (GeneralSecurityException e) { >+ LOG.warn("Failed to initialise SLOW_HTTPS SlowHC4SSLSocketFactory, cps="+CPS_HTTPS, e); >+ } >+ } else { >+ LOG.info("Setting up HTTPS TrustAll Socket Factory"); >+ try { >+ adaptee = new HC4TrustAllSSLSocketFactory(); >+ } catch (GeneralSecurityException e) { >+ LOG.warn("Failed to initialise HTTPS HC4TrustAllSSLSocketFactory", e); >+ } >+ } >+ } >+ } >+ } >+ } >+ /** >+ * @param sock >+ * @param remoteAddress >+ * @param localAddress >+ * @param params >+ * @return >+ * @throws IOException >+ * @throws UnknownHostException >+ * @throws ConnectTimeoutException >+ * @see org.apache.http.conn.scheme.SchemeSocketFactory#connectSocket(java.net.Socket, java.net.InetSocketAddress, java.net.InetSocketAddress, org.apache.http.params.HttpParams) >+ */ >+ @Override >+ public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, >+ InetSocketAddress localAddress, HttpParams params) >+ throws IOException, UnknownHostException, ConnectTimeoutException { >+ checkAndInit(); >+ return adaptee.connectSocket(sock, remoteAddress, localAddress, params); >+ } >+ /** >+ * @param sock >+ * @return >+ * @throws IllegalArgumentException >+ * @see org.apache.http.conn.scheme.SchemeSocketFactory#isSecure(java.net.Socket) >+ */ >+ @Override >+ public boolean isSecure(Socket sock) throws IllegalArgumentException { >+ checkAndInit(); >+ return adaptee.isSecure(sock); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 59020
: 33566