Author: pmouawad
Date: Wed Feb 17 10:47:40 2016
New Revision: 1730810
URL: http://svn.apache.org/viewvc?rev=1730810&view=rev
Log:
Bug 57935 - SSL SNI extension not supported by HttpClient 4.2.6
Bugzilla Id: 57935
Added:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
(with props)
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
jmeter/trunk/xdocs/changes.xml
Added:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java?rev=1730810&view=auto
==============================================================================
---
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
(added)
+++
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
Wed Feb 17 10:47:40 2016
@@ -0,0 +1,171 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.Socket;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.net.ssl.SSLSocket;
+
+import org.apache.http.HttpHost;
+import org.apache.http.conn.DnsResolver;
+import org.apache.http.conn.OperatedClientConnection;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.impl.conn.DefaultClientConnection;
+import org.apache.http.impl.conn.DefaultClientConnectionOperator;
+
+/**
+ * Custom implementation of {@link DefaultClientConnectionOperator} to fix SNI
Issue
+ * @see https://bz.apache.org/bugzilla/show_bug.cgi?id=57935
+ * @since 3.0
+ * TODO Remove it when full upgrade to 4.5.X is done and cleanup is made in
the Socket Factory of JMeter that handles client certificates and Slow socket
+ */
+public class JMeterClientConnectionOperator extends
+ DefaultClientConnectionOperator {
+
+ /**
+ * @param schemes
+ * the scheme registry
+ */
+ public JMeterClientConnectionOperator(final SchemeRegistry schemes) {
+ super(schemes);
+ }
+
+ /**
+ * @param schemes
+ * the scheme registry
+ * @param dnsResolver
+ * the custom DNS lookup mechanism
+ */
+ public JMeterClientConnectionOperator(final SchemeRegistry schemes,
+ final DnsResolver dnsResolver) {
+ super(schemes, dnsResolver);
+ }
+
+ @Override
+ public OperatedClientConnection createConnection() {
+ return new JMeterDefaultClientConnection();
+ }
+
+
+ private static class JMeterDefaultClientConnection extends
DefaultClientConnection {
+ public JMeterDefaultClientConnection() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.http.impl.conn.DefaultClientConnection#opening(java.net.Socket,
org.apache.http.HttpHost)
+ */
+ @Override
+ public void opening(Socket sock, HttpHost target) throws IOException {
+ super.opening(sock, target);
+ if(sock instanceof SSLSocket) {
+ HostNameSetter.setServerNameIndication(target.getHostName(),
(SSLSocket) sock);
+ }
+ }
+ }
+
+ /**
+ * Uses the underlying implementation to support Server Name Indication
(SNI).
+ * @author Michael Locher <[email protected]>
+ * @see https://issues.apache.org/jira/browse/HTTPCLIENT-1119
+ */
+ private static class HostNameSetter {
+
+ private static final AtomicReference<HostNameSetter> CURRENT = new
AtomicReference<HostNameSetter>();
+
+ private final WeakReference<Class<?>> cls;
+ private final WeakReference<Method> setter;
+
+ private HostNameSetter(Class<?> clazz, Method setter) {
+ this.cls = new WeakReference<Class<?>>(clazz);
+ this.setter = setter == null ? null : new
WeakReference<Method>(setter);
+ }
+
+ private static Method init(Class<?> cls) {
+ Method s = null;
+ try {
+ s = cls.getMethod("setHost", String.class);
+ } catch (SecurityException e) {
+ initFail(e);
+ } catch (NoSuchMethodException e) {
+ initFail(e);
+ }
+ CURRENT.set(new HostNameSetter(cls, s));
+ return s;
+ }
+
+ private static void initFail(Exception e) {
+ // ignore
+ }
+
+ private Method reuse(Class<?> cls) {
+ final boolean wrongClass = this.cls.get() != cls;
+ if (wrongClass) {
+ return init(cls);
+ }
+
+ final boolean setterNotSupported = this.setter == null;
+ if (setterNotSupported) {
+ return null;
+ }
+
+ final Method s = setter.get();
+ final boolean setterLost = s == null;
+ return setterLost ? init(cls) : s;
+ }
+
+ /**
+ * Invokes the {@code #setName(String)} method if one is present.
+ *
+ * @param hostname the name to set
+ * @param sslsock the socket
+ */
+ public static void setServerNameIndication(String hostname, SSLSocket
sslsock) {
+ final Class<?> cls = sslsock.getClass();
+ final HostNameSetter current = CURRENT.get();
+ final Method setter = (current == null) ? init(cls) :
current.reuse(cls);
+ if (setter != null) {
+ try {
+ setter.invoke(sslsock, hostname);
+ } catch (IllegalArgumentException e) {
+ setServerNameIndicationFail(e);
+ } catch (IllegalAccessException e) {
+ setServerNameIndicationFail(e);
+ } catch (InvocationTargetException e) {
+ setServerNameIndicationFail(e);
+ }
+ }
+ }
+
+ private static void setServerNameIndicationFail(Exception e) {
+ // ignore
+ }
+ }
+}
Propchange:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java?rev=1730810&r1=1730809&r2=1730810&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
(original)
+++
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/MeasuringConnectionManager.java
Wed Feb 17 10:47:40 2016
@@ -31,6 +31,7 @@ import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
+import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.DnsResolver;
@@ -62,6 +63,17 @@ public class MeasuringConnectionManager
this.measuredConnection = new MeasuringConnectionRequest(res,
this.sample);
return this.measuredConnection;
}
+
+ /**
+ * Overriden to use {@link JMeterClientConnectionOperator} and fix SNI
issue
+ * @see https://bz.apache.org/bugzilla/show_bug.cgi?id=57935
+ * @see
org.apache.http.impl.conn.PoolingClientConnectionManager#createConnectionOperator(org.apache.http.conn.scheme.SchemeRegistry)
+ */
+ @Override
+ protected ClientConnectionOperator createConnectionOperator(
+ SchemeRegistry schreg) {
+ return new JMeterClientConnectionOperator(schreg);
+ }
public void setSample(SampleResult sample) {
this.sample = sample;
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1730810&r1=1730809&r2=1730810&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Wed Feb 17 10:47:40 2016
@@ -249,6 +249,7 @@ Summary
<li><bug>58800</bug>proxy.pause default value , fix documentation</li>
<li><bug>58844</bug>Buttons enable / disable is broken in the arguments
panel. Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
<li><bug>58861</bug>When clicking on up, down or detail while in a cell of
the argument panel, newly added content is lost. Contributed by Benoit Wiart
(benoit dot wiart at gmail.com)</li>
+ <li><bug>57935</bug>SSL SNI extension not supported by HttpClient
4.2.6</li>
</ul>
<h3>Other Samplers</h3>