jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1754681 - in /jmeter/trunk: src/core/org/apache/jmeter/util/HostNameSetter.java src/core/org/apache/jmeter/util/SlowSSLSocket.java src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java xdocs/changes.xml
Date Sun, 14 Aug 2016 10:41:14 GMT
On 31 July 2016 at 21:07,  <pmouawad@apache.org> wrote:
> Author: pmouawad
> Date: Sun Jul 31 20:07:10 2016
> New Revision: 1754681
>
> URL: http://svn.apache.org/viewvc?rev=1754681&view=rev
> Log:
> Bug 59902 - Https handshake failure when setting httpclient.socket.https.cps property
> Bugzilla Id: 59902
>
> Added:
>     jmeter/trunk/src/core/org/apache/jmeter/util/HostNameSetter.java   (with props)
> Modified:
>     jmeter/trunk/src/core/org/apache/jmeter/util/SlowSSLSocket.java
>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
>     jmeter/trunk/xdocs/changes.xml
>
> Added: jmeter/trunk/src/core/org/apache/jmeter/util/HostNameSetter.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/HostNameSetter.java?rev=1754681&view=auto
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/util/HostNameSetter.java (added)
> +++ jmeter/trunk/src/core/org/apache/jmeter/util/HostNameSetter.java Sun Jul 31 20:07:10
2016
> @@ -0,0 +1,84 @@
> +package org.apache.jmeter.util;
> +
> +import java.lang.ref.WeakReference;
> +import java.lang.reflect.InvocationTargetException;
> +import java.lang.reflect.Method;
> +import java.util.concurrent.atomic.AtomicReference;
> +
> +import javax.net.ssl.SSLSocket;
> +
> +/**
> + * Uses the underlying implementation to support Server Name Indication (SNI).
> + * @author Michael Locher <cmbntr@gmail.com>

@author tags in code are deprecated by the ASF; they are only accurate
at initial commit, and the ASF is about community code development.

Authors can be credited elsewhere, e.g. in changes.xml, but strictly
speaking the author should be asked to agree to this change, as it
affects their original contribution.

We should not commit new code with @author entries.

Nor should code be committed without the AL header.

In this case it's not clear where the code originated, as it does not
appear to be attached to the Bugzilla.

> + * @see <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1119">HTTPCLIENT-1119</a>
> + */
> +public class HostNameSetter {
> +
> +    private static final AtomicReference<HostNameSetter> CURRENT = new AtomicReference<>();
> +
> +    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<>(setter);
> +    }
> +
> +    private static Method init(Class<?> cls) {
> +        Method s = null;
> +        try {
> +            s = cls.getMethod("setHost", String.class);
> +        } catch (Exception 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
> +                    | IllegalAccessException
> +                    | InvocationTargetException e) {
> +                setServerNameIndicationFail(e);
> +            }
> +        }
> +    }
> +
> +    private static void setServerNameIndicationFail(Exception e) {
> +        // ignore
> +    }
> +}
> \ No newline at end of file
>
> Propchange: jmeter/trunk/src/core/org/apache/jmeter/util/HostNameSetter.java
> ------------------------------------------------------------------------------
>     svn:mime-type = text/plain
>
> Modified: jmeter/trunk/src/core/org/apache/jmeter/util/SlowSSLSocket.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/SlowSSLSocket.java?rev=1754681&r1=1754680&r2=1754681&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/util/SlowSSLSocket.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/util/SlowSSLSocket.java Sun Jul 31 20:07:10
2016
> @@ -22,6 +22,7 @@ import java.io.IOException;
>  import java.io.InputStream;
>  import java.io.OutputStream;
>  import java.net.InetAddress;
> +import java.net.InetSocketAddress;
>  import java.net.SocketAddress;
>  import java.net.SocketException;
>  import java.nio.channels.SocketChannel;
> @@ -174,6 +175,12 @@ public class SlowSSLSocket extends SSLSo
>
>      @Override
>      public void connect(SocketAddress endpoint, int timeout) throws IOException {
> +        // see Bug 59902
> +        if(endpoint instanceof InetSocketAddress) {
> +            InetSocketAddress address =
> +                    (InetSocketAddress) endpoint;
> +            HostNameSetter.setServerNameIndication(address.getHostString(), sslSock);
> +        }
>          sslSock.connect(endpoint, timeout);
>      }
>
>
> Modified: 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=1754681&r1=1754680&r2=1754681&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
(original)
> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/JMeterClientConnectionOperator.java
Sun Jul 31 20:07:10 2016
> @@ -25,11 +25,7 @@
>  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;
>
> @@ -39,6 +35,7 @@ import org.apache.http.conn.OperatedClie
>  import org.apache.http.conn.scheme.SchemeRegistry;
>  import org.apache.http.impl.conn.DefaultClientConnection;
>  import org.apache.http.impl.conn.DefaultClientConnectionOperator;
> +import org.apache.jmeter.util.HostNameSetter;
>
>  /**
>   * Custom implementation of {@link DefaultClientConnectionOperator} to fix SNI Issue
> @@ -90,78 +87,4 @@ public class JMeterClientConnectionOpera
>              }
>          }
>      }
> -
> -    /**
> -     * Uses the underlying implementation to support Server Name Indication (SNI).
> -     * @author Michael Locher <cmbntr@gmail.com>
> -     * @see <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1119">HTTPCLIENT-1119</a>
> -     */
> -    private static class HostNameSetter {
> -
> -        private static final AtomicReference<HostNameSetter> CURRENT = new AtomicReference<>();
> -
> -        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<>(setter);
> -        }
> -
> -        private static Method init(Class<?> cls) {
> -            Method s = null;
> -            try {
> -                s = cls.getMethod("setHost", String.class);
> -            } catch (SecurityException | 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
> -                        | IllegalAccessException
> -                        | InvocationTargetException e) {
> -                    setServerNameIndicationFail(e);
> -                }
> -            }
> -        }
> -
> -        private static void setServerNameIndicationFail(Exception e) {
> -            // ignore
> -        }
> -    }
>  }
>
> Modified: jmeter/trunk/xdocs/changes.xml
> URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1754681&r1=1754680&r2=1754681&view=diff
> ==============================================================================
> --- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
> +++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Jul 31 20:07:10 2016
> @@ -138,6 +138,7 @@ Summary
>  <h3>HTTP Samplers and Test Script Recorder</h3>
>  <ul>
>      <li><bug>58888</bug>HTTP(S) Test Script Recorder (ProxyControl)
does not add TestElement's returned by SamplerCreator createChildren ()</li>
> +    <li><bug>59902</bug>Https handshake failure when setting <code>httpclient.socket.https.cps</code>
property</li>
>   </ul>
>
>  <h3>Other Samplers</h3>
>
>

Mime
View raw message