Author: sebb
Date: Fri Dec 10 02:11:23 2010
New Revision: 1044196

URL: http://svn.apache.org/viewvc?rev=1044196&view=rev
Log:
Move HttpClientKey to HC4 subclass
Pull up common code from HC3 subclass

Modified:
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java?rev=1044196&r1=1044195&r2=1044196&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
 Fri Dec 10 02:11:23 2010
@@ -101,13 +101,10 @@ public class HTTPHC3Impl extends HTTPHCA
     volatile HttpClient savedClient;
 
     static {
-        int cps =
-            JMeterUtils.getPropDefault("httpclient.socket.http.cps", 0); // 
$NON-NLS-1$
-
-        if (cps > 0) {
-            log.info("Setting up HTTP SlowProtocol, cps="+cps);
+        if (CPS_HTTP > 0) {
+            log.info("Setting up HTTP SlowProtocol, cps="+CPS_HTTP);
             Protocol.registerProtocol(PROTOCOL_HTTP,
-                    new Protocol(PROTOCOL_HTTP,new 
SlowHttpClientSocketFactory(cps),DEFAULT_HTTP_PORT));
+                    new Protocol(PROTOCOL_HTTP,new 
SlowHttpClientSocketFactory(CPS_HTTP),DEFAULT_HTTP_PORT));
         }
 
         // Now done in JsseSSLManager (which needs to register the protocol)
@@ -123,10 +120,10 @@ public class HTTPHC3Impl extends HTTPHCA
         // Set default parameters as needed
         HttpClientParams params = new HttpClientParams();
 
-        // Process httpclient parameters file
+        // Process Commons HttpClient parameters file
         String file=JMeterUtils.getProperty("httpclient.parameters.file"); // 
$NON-NLS-1$
         if (file != null) {
-            HttpClientDefaultParameters.load(file,params);
+            HttpClientDefaultParameters.load(file, params);
         }
 
         // If the pre-emptive parameter is undefined, then we can set it as 
needed
@@ -134,23 +131,21 @@ public class HTTPHC3Impl extends HTTPHCA
         canSetPreEmptive =  params.isAuthenticationPreemptive();
 
         // Handle old-style JMeter properties
-        // Default to HTTP version 1.1
-        String ver=JMeterUtils.getPropDefault("httpclient.version","1.1"); // 
$NON-NLS-1$ $NON-NLS-2$
         try {
-            params.setParameter(HttpMethodParams.PROTOCOL_VERSION, 
HttpVersion.parse("HTTP/"+ver));
+            params.setParameter(HttpMethodParams.PROTOCOL_VERSION, 
HttpVersion.parse("HTTP/"+HTTP_VERSION));
         } catch (ProtocolException e) {
             log.warn("Problem setting protocol version 
"+e.getLocalizedMessage());
         }
-        String to= JMeterUtils.getProperty("httpclient.timeout"); // 
$NON-NLS-1$
-        if (to != null){
-            params.setIntParameter(HttpMethodParams.SO_TIMEOUT, 
Integer.parseInt(to));
+
+        if (SO_TIMEOUT >= 0){
+            params.setIntParameter(HttpMethodParams.SO_TIMEOUT, SO_TIMEOUT);
         }
 
         // This must be done last, as must not be overridden
         
params.setParameter(HttpMethodParams.COOKIE_POLICY,CookiePolicy.IGNORE_COOKIES);
         // We do our own cookie handling
 
-        if (JMeterUtils.getPropDefault("httpclient.loopback",false)){// 
$NON-NLS-1$
+        if (USE_LOOPBACK){
             LoopbackHttpClientSocketFactory.setup();
         }
     }

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java?rev=1044196&r1=1044195&r2=1044196&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
 Fri Dec 10 02:11:23 2010
@@ -56,8 +56,6 @@ public abstract class HTTPHCAbstractImpl
 
     protected static final String PROXY_DOMAIN = 
JMeterUtils.getPropDefault("http.proxyDomain","");
 
-    public static final String IP_SOURCE = "HTTPSampler.ipSource";
-
     protected static final InetAddress localAddress;
 
     protected static final String localHost;
@@ -68,6 +66,17 @@ public abstract class HTTPHCAbstractImpl
 
     protected static final int nonProxyHostSuffixSize;
 
+    protected static final int CPS_HTTP = 
JMeterUtils.getPropDefault("httpclient.socket.http.cps", 0);
+    
+    protected static final int CPS_HTTPS = 
JMeterUtils.getPropDefault("httpclient.socket.https.cps", 0);
+
+    protected static final boolean USE_LOOPBACK = 
JMeterUtils.getPropDefault("httpclient.loopback", false);
+    
+    protected static final String HTTP_VERSION = 
JMeterUtils.getPropDefault("httpclient.version", "1.1");
+
+    // -1 means not defined
+    protected static final int SO_TIMEOUT = 
JMeterUtils.getPropDefault("httpclient.timeout", -1);
+
     static {
         if (NONPROXY_HOSTS.length() > 0){
             StringTokenizer s = new StringTokenizer(NONPROXY_HOSTS,"|");// 
$NON-NLS-1$
@@ -144,81 +153,4 @@ public abstract class HTTPHCAbstractImpl
     protected static boolean isStaticProxy(String host){
         return PROXY_DEFINED && !isNonProxy(host);
     }
-
-    /**
-     * Holder class for all fields that define an HttpClient instance;
-     * used as the key to the ThreadLocal map of HttpClient instances.
-     */
-    protected static final class HttpClientKey {
-//        protected final String host;
-
-        private final URL url;
-        private final boolean hasProxy;
-        private final String proxyHost;
-        private final int proxyPort;
-        private final String proxyUser;
-        private final String proxyPass;
-        
-        private final int hashCode; // Always create hash because we will 
always need it
-
-        public HttpClientKey(URL url, boolean b, String proxyHost,
-                int proxyPort, String proxyUser, String proxyPass) {
-            this.url = url;
-            this.hasProxy = b;
-            this.proxyHost = proxyHost;
-            this.proxyPort = proxyPort;
-            this.proxyUser = proxyUser;
-            this.proxyPass = proxyPass;
-            this.hashCode = getHash();
-        }
-        
-        private int getHash() {
-            int hash = 17;
-            hash = hash*31 + (hasProxy ? 1 : 0);
-            if (hasProxy) {
-                hash = hash*31 + getHash(proxyHost);
-                hash = hash*31 + proxyPort;
-                hash = hash*31 + getHash(proxyUser);
-                hash = hash*31 + getHash(proxyPass);
-            }
-            hash = hash*31 + url.toString().hashCode();
-            return hash;
-        }
-
-        // Allow for null strings
-        private int getHash(String s) {
-            return s == null ? 0 : s.hashCode(); 
-        }
-        
-        @Override
-        public boolean equals (Object obj){
-            if (this == obj) {
-                return true;
-            }
-            if (obj instanceof HttpClientKey) {
-                return false;
-            }
-            HttpClientKey other = (HttpClientKey) obj;
-            if (this.hasProxy) { // otherwise proxy String fields may be null
-                return 
-                this.hasProxy == other.hasProxy &&
-                this.proxyPort == other.proxyPort &&
-                this.proxyHost.equals(other.proxyHost) &&
-                this.proxyUser.equals(other.proxyUser) &&
-                this.proxyPass.equals(other.proxyPass) &&
-                this.url.toString().equals(other.url.toString());              
  
-            }
-            // No proxy, so don't check proxy fields
-            return 
-                this.hasProxy == other.hasProxy &&
-                this.url.toString().equals(other.url.toString())
-            ;
-            
-        }
-
-        @Override
-        public int hashCode(){
-            return hashCode;
-        }
-    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to