You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/02/04 09:26:54 UTC

svn commit: r1728421 - /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java

Author: pmouawad
Date: Thu Feb  4 08:26:54 2016
New Revision: 1728421

URL: http://svn.apache.org/viewvc?rev=1728421&view=rev
Log:
un-duplicate the proxy handling
clarify/simplify code
fix typo in comment
Patch by B. Wiart
#resolve #106

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1728421&r1=1728420&r2=1728421&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java Thu Feb  4 08:26:54 2016
@@ -684,18 +684,27 @@ public class HTTPHC4Impl extends HTTPHCA
         Map<HttpClientKey, HttpClient> mapHttpClientPerHttpClientKey = HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY.get();
         
         final String host = url.getHost();
-        final String proxyHost = getProxyHost();
-        final int proxyPort = getProxyPortInt();
+        String proxyHost = getProxyHost();
+        int proxyPort = getProxyPortInt();
+        String proxyPass = getProxyPass();
+        String proxyUser = getProxyUser();
 
+        // static proxy is the globally define proxy eg command line or properties
         boolean useStaticProxy = isStaticProxy(host);
+        // dynamic proxy is the proxy defined for this sampler
         boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);
+        boolean useProxy = useStaticProxy || useDynamicProxy;
+        
+        // if both dynamic and static are used, the dynamic proxy has priority over static
+        if(!useDynamicProxy) {
+            proxyHost = PROXY_HOST;
+            proxyPort = PROXY_PORT;
+            proxyUser = PROXY_USER;
+            proxyPass = PROXY_PASS;
+        }
 
         // Lookup key - must agree with all the values used to create the HttpClient.
-        HttpClientKey key = new HttpClientKey(url, (useStaticProxy || useDynamicProxy), 
-                useDynamicProxy ? proxyHost : PROXY_HOST,
-                useDynamicProxy ? proxyPort : PROXY_PORT,
-                useDynamicProxy ? getProxyUser() : PROXY_USER,
-                useDynamicProxy ? getProxyPass() : PROXY_PASS);
+        HttpClientKey key = new HttpClientKey(url, useProxy, proxyHost, proxyPort, proxyUser, proxyPass);
         
         HttpClient httpClient = mapHttpClientPerHttpClientKey.get(key);
 
@@ -709,7 +718,7 @@ public class HTTPHC4Impl extends HTTPHCA
             resetSSLContext = false;
         }
 
-        if (httpClient == null){ // One-time init for this client
+        if (httpClient == null) { // One-time init for this client
 
             HttpParams clientParams = new DefaultedHttpParams(new BasicHttpParams(), DEFAULT_HTTP_PARAMS);
 
@@ -735,7 +744,7 @@ public class HTTPHC4Impl extends HTTPHCA
             ((AbstractHttpClient) httpClient).addResponseInterceptor(METRICS_SAVER); // HACK
             ((AbstractHttpClient) httpClient).addRequestInterceptor(METRICS_RESETTER); 
             
-            // Override the defualt schemes as necessary
+            // Override the default schemes as necessary
             SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry();
 
             if (SLOW_HTTP != null){
@@ -747,23 +756,15 @@ public class HTTPHC4Impl extends HTTPHCA
             }
 
             // Set up proxy details
-            if (useDynamicProxy){
+            if(useProxy) {
+
                 HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                 clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
-                String proxyUser = getProxyUser();
                 
                 if (proxyUser.length() > 0) {                   
                     ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(
                             new AuthScope(proxyHost, proxyPort),
-                            new NTCredentials(proxyUser, getProxyPass(), localHost, PROXY_DOMAIN));
-                }
-            } else if (useStaticProxy) {
-                HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT);
-                clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
-                if (PROXY_USER.length() > 0) {
-                    ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(
-                            new AuthScope(PROXY_HOST, PROXY_PORT),
-                            new NTCredentials(PROXY_USER, PROXY_PASS, localHost, PROXY_DOMAIN));
+                            new NTCredentials(proxyUser, proxyPass, localHost, PROXY_DOMAIN));
                 }
             }
 
@@ -1066,7 +1067,7 @@ public class HTTPHC4Impl extends HTTPHCA
     protected String sendPostData(HttpPost post)  throws IOException {
         // Buffer to hold the post body, except file content
         StringBuilder postedBody = new StringBuilder(1000);
-        HTTPFileArg files[] = getHTTPFiles();
+        HTTPFileArg[] files = getHTTPFiles();
 
         final String contentEncoding = getContentEncodingOrNull();
         final boolean haveContentEncoding = contentEncoding != null;