You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/04/14 01:04:05 UTC

svn commit: r393969 - in /jakarta/jmeter/branches/rel-2-1: bin/jmeter.properties src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java xdocs/changes.xml

Author: sebb
Date: Thu Apr 13 16:04:04 2006
New Revision: 393969

URL: http://svn.apache.org/viewcvs?rev=393969&view=rev
Log:
Bug 26136 - allow configuration of localHost for HttpClient connections

Modified:
    jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties
    jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
    jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml

Modified: jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties?rev=393969&r1=393968&r2=393969&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties (original)
+++ jakarta/jmeter/branches/rel-2-1/bin/jmeter.properties Thu Apr 13 16:04:04 2006
@@ -212,6 +212,9 @@
 #httpclient.socket.http.cps=0
 #httpclient.socket.https.cps=0
 
+# Define the local host address to be used for multi-homed hosts
+#httpclient.localaddress=1.2.3.4
+
 # Sample logging levels for HttpClient
 # Note that full category names are used, i.e. must include the org.apache.
 # Info level produces no output:

Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=393969&r1=393968&r2=393969&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java Thu Apr 13 16:04:04 2006
@@ -21,6 +21,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -85,6 +87,8 @@
     private static final String PROXY_PASS = 
         JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_PASS,""); // $NON-NLS-1$
     
+    private static InetAddress localAddress = null;
+    
     /*
      * Connection is re-used within the thread if possible
      */
@@ -141,6 +145,17 @@
             Protocol.registerProtocol(PROTOCOL_HTTPS, 
                     new Protocol(PROTOCOL_HTTPS,new SlowHttpClientSocketFactory(cps),DEFAULT_HTTPS_PORT));
         }
+
+        String localHostOrIP = 
+            JMeterUtils.getPropDefault("httpclient.localaddress",""); // $NON-NLS-1$
+        if (localHostOrIP.length() > 0){
+            try {
+                localAddress = InetAddress.getByName(localHostOrIP);
+                log.info("Using localAddress "+localAddress.getHostAddress());
+            } catch (UnknownHostException e) {
+                log.warn(e.getLocalizedMessage());
+            }
+        }
 	}
 
 	/**
@@ -237,6 +252,11 @@
 		HostConfiguration hc = new HostConfiguration();
 		hc.setHost(host, port, protocol); // All needed to ensure re-usablility
 
+        // Set up the local address if one exists
+        if (localAddress != null){
+            hc.setLocalAddress(localAddress);
+        }
+        
         Map map = (Map) httpClients.get();
 		HttpClient httpClient = (HttpClient) map.get(hc);
 		
@@ -665,7 +685,6 @@
 			for ( Iterator it = map.entrySet().iterator(); it.hasNext(); )
 			{
 				Map.Entry entry = (Map.Entry) it.next();
-				//HostConfiguration hc = (HostConfiguration) entry.getKey();
 				HttpClient cl = (HttpClient) entry.getValue();
                 cl.getHttpConnectionManager().closeIdleConnections(-1000);// Closes the connection
 			}

Modified: jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml?rev=393969&r1=393968&r2=393969&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-1/xdocs/changes.xml Thu Apr 13 16:04:04 2006
@@ -81,6 +81,7 @@
 <li>Change jmeter.bat DOS script so it works from any directory</li>
 <li>New -N option to define nonProxyHosts from command-line</li>
 <li>New -S option to define system properties from input file</li>
+<li>Bug 26136 - allow configuration of local address</li>
 </ul>
 
 <h4>Bug fixes:</h4>



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org