View | Details | Raw Unified | Return to bug 58099
Collapse All | Expand All

(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-30 / +14 lines)
Lines 28-34 Link Here
28
import java.net.URL;
28
import java.net.URL;
29
import java.net.URLDecoder;
29
import java.net.URLDecoder;
30
import java.nio.charset.Charset;
30
import java.nio.charset.Charset;
31
import java.security.GeneralSecurityException;
32
import java.security.PrivilegedActionException;
31
import java.security.PrivilegedActionException;
33
import java.security.PrivilegedExceptionAction;
32
import java.security.PrivilegedExceptionAction;
34
import java.util.ArrayList;
33
import java.util.ArrayList;
Lines 78-83 Link Here
78
import org.apache.http.conn.ConnectionKeepAliveStrategy;
77
import org.apache.http.conn.ConnectionKeepAliveStrategy;
79
import org.apache.http.conn.DnsResolver;
78
import org.apache.http.conn.DnsResolver;
80
import org.apache.http.conn.params.ConnRoutePNames;
79
import org.apache.http.conn.params.ConnRoutePNames;
80
import org.apache.http.conn.scheme.PlainSocketFactory;
81
import org.apache.http.conn.scheme.Scheme;
81
import org.apache.http.conn.scheme.Scheme;
82
import org.apache.http.conn.scheme.SchemeRegistry;
82
import org.apache.http.conn.scheme.SchemeRegistry;
83
import org.apache.http.entity.ContentType;
83
import org.apache.http.entity.ContentType;
Lines 92-98 Link Here
92
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
92
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
93
import org.apache.http.impl.client.DefaultHttpClient;
93
import org.apache.http.impl.client.DefaultHttpClient;
94
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
94
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
95
import org.apache.http.impl.conn.SchemeRegistryFactory;
96
import org.apache.http.impl.conn.SystemDefaultDnsResolver;
95
import org.apache.http.impl.conn.SystemDefaultDnsResolver;
97
import org.apache.http.message.BasicNameValuePair;
96
import org.apache.http.message.BasicNameValuePair;
98
import org.apache.http.params.BasicHttpParams;
97
import org.apache.http.params.BasicHttpParams;
Lines 110-120 Link Here
110
import org.apache.jmeter.protocol.http.control.CookieManager;
109
import org.apache.jmeter.protocol.http.control.CookieManager;
111
import org.apache.jmeter.protocol.http.control.HeaderManager;
110
import org.apache.jmeter.protocol.http.control.HeaderManager;
112
import org.apache.jmeter.protocol.http.util.EncoderCache;
111
import org.apache.jmeter.protocol.http.util.EncoderCache;
113
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
114
import org.apache.jmeter.protocol.http.util.HTTPArgument;
112
import org.apache.jmeter.protocol.http.util.HTTPArgument;
115
import org.apache.jmeter.protocol.http.util.HTTPConstants;
113
import org.apache.jmeter.protocol.http.util.HTTPConstants;
116
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
114
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
117
import org.apache.jmeter.protocol.http.util.SlowHC4SSLSocketFactory;
118
import org.apache.jmeter.protocol.http.util.SlowHC4SocketFactory;
115
import org.apache.jmeter.protocol.http.util.SlowHC4SocketFactory;
119
import org.apache.jmeter.samplers.SampleResult;
116
import org.apache.jmeter.samplers.SampleResult;
120
import org.apache.jmeter.services.FileServer;
117
import org.apache.jmeter.services.FileServer;
Lines 197-205 Link Here
197
    // Scheme used for slow HTTP sockets. Cannot be set as a default, because must be set on an HttpClient instance.
194
    // Scheme used for slow HTTP sockets. Cannot be set as a default, because must be set on an HttpClient instance.
198
    private static final Scheme SLOW_HTTP;
195
    private static final Scheme SLOW_HTTP;
199
    
196
    
200
    // We always want to override the HTTPS scheme, because we want to trust all certificates and hosts
201
    private static final Scheme HTTPS_SCHEME;
202
203
    /*
197
    /*
204
     * Create a set of default parameters from the ones initially created.
198
     * Create a set of default parameters from the ones initially created.
205
     * This allows the defaults to be overridden if necessary from the properties file.
199
     * This allows the defaults to be overridden if necessary from the properties file.
Lines 229-252 Link Here
229
            SLOW_HTTP = null;
223
            SLOW_HTTP = null;
230
        }
224
        }
231
        
225
        
232
        // We always want to override the HTTPS scheme
233
        Scheme https = null;
234
        if (CPS_HTTPS > 0) {
235
            log.info("Setting up HTTPS SlowProtocol, cps="+CPS_HTTPS);
236
            try {
237
                https = new Scheme(HTTPConstants.PROTOCOL_HTTPS, HTTPConstants.DEFAULT_HTTPS_PORT, new SlowHC4SSLSocketFactory(CPS_HTTPS));
238
            } catch (GeneralSecurityException e) {
239
                log.warn("Failed to initialise SLOW_HTTPS scheme, cps="+CPS_HTTPS, e);
240
            }
241
        } else {
242
            log.info("Setting up HTTPS TrustAll scheme");
243
            try {
244
                https = new Scheme(HTTPConstants.PROTOCOL_HTTPS, HTTPConstants.DEFAULT_HTTPS_PORT, new HC4TrustAllSSLSocketFactory());
245
            } catch (GeneralSecurityException e) {
246
                log.warn("Failed to initialise HTTPS TrustAll scheme", e);
247
            }
248
        }
249
        HTTPS_SCHEME = https;
250
        if (localAddress != null){
226
        if (localAddress != null){
251
            DEFAULT_HTTP_PARAMS.setParameter(ConnRoutePNames.LOCAL_ADDRESS, localAddress);
227
            DEFAULT_HTTP_PARAMS.setParameter(ConnRoutePNames.LOCAL_ADDRESS, localAddress);
252
        }
228
        }
Lines 726-732 Link Here
726
            if (resolver == null) {
702
            if (resolver == null) {
727
                resolver = new SystemDefaultDnsResolver();
703
                resolver = new SystemDefaultDnsResolver();
728
            }
704
            }
729
            ClientConnectionManager connManager = new MeasuringConnectionManager(SchemeRegistryFactory.createDefault(), resolver);
705
            ClientConnectionManager connManager = new MeasuringConnectionManager(createDefaultSchemeRegistry(), resolver);
730
            
706
            
731
            httpClient = new DefaultHttpClient(connManager, clientParams) {
707
            httpClient = new DefaultHttpClient(connManager, clientParams) {
732
                @Override
708
                @Override
Lines 751-760 Link Here
751
                schemeRegistry.register(SLOW_HTTP);
727
                schemeRegistry.register(SLOW_HTTP);
752
            }
728
            }
753
729
754
            if (HTTPS_SCHEME != null){
755
                schemeRegistry.register(HTTPS_SCHEME);
756
            }
757
758
            // Set up proxy details
730
            // Set up proxy details
759
            if(useProxy) {
731
            if(useProxy) {
760
732
Lines 793-798 Link Here
793
    }
765
    }
794
766
795
    /**
767
    /**
768
     * Setup LazySchemeSocketFactory
769
     */
770
    private SchemeRegistry createDefaultSchemeRegistry() {
771
        final SchemeRegistry registry = new SchemeRegistry();
772
        registry.register(
773
                new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
774
        registry.register(
775
                new Scheme("https", 443, new LazySchemeSocketFactory()));
776
        return registry;
777
    }
778
779
    /**
796
     * Setup following elements on httpRequest:
780
     * Setup following elements on httpRequest:
797
     * <ul>
781
     * <ul>
798
     * <li>ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING</li>
782
     * <li>ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING</li>
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/LazySchemeSocketFactory.java (+100 lines)
Line 0 Link Here
1
package org.apache.jmeter.protocol.http.sampler;
2
3
import java.io.IOException;
4
import java.net.InetSocketAddress;
5
import java.net.Socket;
6
import java.net.UnknownHostException;
7
import java.security.GeneralSecurityException;
8
9
import org.apache.http.conn.ConnectTimeoutException;
10
import org.apache.http.conn.scheme.Scheme;
11
import org.apache.http.conn.scheme.SchemeSocketFactory;
12
import org.apache.http.conn.ssl.SSLInitializationException;
13
import org.apache.http.conn.ssl.SSLSocketFactory;
14
import org.apache.http.params.HttpParams;
15
import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
16
import org.apache.jmeter.protocol.http.util.HTTPConstants;
17
import org.apache.jmeter.protocol.http.util.SlowHC4SSLSocketFactory;
18
import org.apache.jmeter.util.JMeterUtils;
19
import org.apache.jorphan.logging.LoggingManager;
20
import org.apache.log.Logger;
21
22
/**
23
 * Lazy SchemeSocketFactory that lazily initializes HTTPS Socket Factory
24
 * @since 3.0
25
 */
26
public class LazySchemeSocketFactory implements SchemeSocketFactory{
27
    private static final Logger LOG = LoggingManager.getLoggerForClass();
28
29
    protected static final int CPS_HTTPS = JMeterUtils.getPropDefault("httpclient.socket.https.cps", 0);
30
    private SchemeSocketFactory adaptee;
31
    public LazySchemeSocketFactory() {
32
    }
33
    /**
34
     * @param params
35
     * @return
36
     * @throws IOException
37
     * @see org.apache.http.conn.scheme.SchemeSocketFactory#createSocket(org.apache.http.params.HttpParams)
38
     */
39
    @Override
40
    public Socket createSocket(HttpParams params) throws IOException {
41
        checkAndInit();
42
        return adaptee.createSocket(params);
43
    }
44
    /**
45
     * @throws SSLInitializationException
46
     */
47
    private void checkAndInit() throws SSLInitializationException {
48
        if(adaptee == null) {
49
            synchronized (this) {
50
                if(adaptee==null) {
51
                    if (CPS_HTTPS > 0) {
52
                        LOG.info("Setting up HTTPS SlowProtocol, cps="+CPS_HTTPS);
53
                        try {
54
                            adaptee  = new SlowHC4SSLSocketFactory(CPS_HTTPS);
55
                        } catch (GeneralSecurityException e) {
56
                            LOG.warn("Failed to initialise SLOW_HTTPS SlowHC4SSLSocketFactory, cps="+CPS_HTTPS, e);
57
                        }
58
                    } else {
59
                        LOG.info("Setting up HTTPS TrustAll Socket Factory");
60
                        try {
61
                            adaptee = new HC4TrustAllSSLSocketFactory();
62
                        } catch (GeneralSecurityException e) {
63
                            LOG.warn("Failed to initialise HTTPS HC4TrustAllSSLSocketFactory", e);
64
                        }
65
                    }
66
                }
67
            }
68
        }
69
    }
70
    /**
71
     * @param sock
72
     * @param remoteAddress
73
     * @param localAddress
74
     * @param params
75
     * @return
76
     * @throws IOException
77
     * @throws UnknownHostException
78
     * @throws ConnectTimeoutException
79
     * @see org.apache.http.conn.scheme.SchemeSocketFactory#connectSocket(java.net.Socket, java.net.InetSocketAddress, java.net.InetSocketAddress, org.apache.http.params.HttpParams)
80
     */
81
    @Override
82
    public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress,
83
            InetSocketAddress localAddress, HttpParams params)
84
            throws IOException, UnknownHostException, ConnectTimeoutException {
85
        checkAndInit();
86
        return adaptee.connectSocket(sock, remoteAddress, localAddress, params);
87
    }
88
    /**
89
     * @param sock
90
     * @return
91
     * @throws IllegalArgumentException
92
     * @see org.apache.http.conn.scheme.SchemeSocketFactory#isSecure(java.net.Socket)
93
     */
94
    @Override
95
    public boolean isSecure(Socket sock) throws IllegalArgumentException {
96
        checkAndInit();
97
        return adaptee.isSecure(sock);
98
    }
99
100
}

Return to bug 58099