Author: sebb
Date: Thu Dec 2 16:57:37 2010
New Revision: 1041452
URL: http://svn.apache.org/viewvc?rev=1041452&view=rev
Log:
Move some common code to a super-class for the HttpClient-based samplers
Added:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
(with props)
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/HTTPHC4Impl.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=1041452&r1=1041451&r2=1041452&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
Thu Dec 2 16:57:37 2010
@@ -25,15 +25,10 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLDecoder;
-import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
import java.util.zip.GZIPInputStream;
import org.apache.commons.httpclient.Header;
@@ -66,7 +61,6 @@ import org.apache.commons.httpclient.par
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.httpclient.protocol.Protocol;
-import org.apache.jmeter.JMeter;
import org.apache.jmeter.protocol.http.control.AuthManager;
import org.apache.jmeter.protocol.http.control.Authorization;
import org.apache.jmeter.protocol.http.control.CacheManager;
@@ -86,92 +80,27 @@ import org.apache.jorphan.util.JOrphanUt
import org.apache.log.Logger;
/**
- * A sampler which understands all the parts necessary to read statistics about
- * HTTP requests, including cookies and authentication.
- *
+ * HTTP sampler using Apache (Jakarta) Commons HttpClient 3.1.
*/
-public class HTTPHC3Impl extends HTTPAbstractImpl {
+public class HTTPHC3Impl extends HTTPHCAbstractImpl {
private static final Logger log = LoggingManager.getLoggerForClass();
private static final long serialVersionUID = 240L;
- private static final String HTTP_AUTHENTICATION_PREEMPTIVE =
"http.authentication.preemptive"; // $NON-NLS-1$
-
private static final boolean canSetPreEmptive; // OK to set pre-emptive
auth?
- private static final String PROXY_HOST =
- System.getProperty("http.proxyHost",""); // $NON-NLS-1$
-
- private static final String NONPROXY_HOSTS =
- System.getProperty("http.nonProxyHosts",""); // $NON-NLS-1$
-
- private static final int PROXY_PORT =
- Integer.parseInt(System.getProperty("http.proxyPort","0")); //
$NON-NLS-1$
-
- // Have proxy details been provided?
- private static final boolean PROXY_DEFINED = PROXY_HOST.length() > 0 &&
PROXY_PORT > 0;
-
- private static final String PROXY_USER =
- JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_USER,""); // $NON-NLS-1$
-
- private static final String PROXY_PASS =
- JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_PASS,""); // $NON-NLS-1$
-
- private static final String PROXY_DOMAIN =
- JMeterUtils.getPropDefault("http.proxyDomain",""); // $NON-NLS-1$
$NON-NLS-2$
-
- public static final String IP_SOURCE = "HTTPSampler.ipSource"; //
$NON-NLS-1$ // TODO not here
-
- static final InetAddress localAddress;
-
- private static final String localHost;
-
- /*
- * Connection is re-used within the thread if possible
- */
- static final ThreadLocal<Map<HostConfiguration, HttpClient>> httpClients =
+ private static final ThreadLocal<Map<HostConfiguration, HttpClient>>
httpClients =
new ThreadLocal<Map<HostConfiguration, HttpClient>>(){
- @Override
- protected Map<HostConfiguration, HttpClient> initialValue() {
- return new HashMap<HostConfiguration, HttpClient>();
- }
- };
-
- private static final Set<String> nonProxyHostFull = new
HashSet<String>();// www.apache.org
- private static final List<String> nonProxyHostSuffix = new
ArrayList<String>();// .apache.org
-
- private static final int nonProxyHostSuffixSize;
-
- protected volatile HttpClient savedClient;
-
- private static boolean isNonProxy(String host){
- return nonProxyHostFull.contains(host) || isPartialMatch(host);
- }
-
- private static boolean isPartialMatch(String host) {
- for (int i=0;i<nonProxyHostSuffixSize;i++){
- if (host.endsWith(nonProxyHostSuffix.get(i))) {
- return true;
- }
+ @Override
+ protected Map<HostConfiguration, HttpClient> initialValue() {
+ return new HashMap<HostConfiguration, HttpClient>();
}
- return false;
- }
+ };
- static {
- if (NONPROXY_HOSTS.length() > 0){
- StringTokenizer s = new StringTokenizer(NONPROXY_HOSTS,"|");//
$NON-NLS-1$
- while (s.hasMoreTokens()){
- String t = s.nextToken();
- if (t.indexOf("*") ==0){// e.g. *.apache.org // $NON-NLS-1$
- nonProxyHostSuffix.add(t.substring(1));
- } else {
- nonProxyHostFull.add(t);// e.g. www.apache.org
- }
- }
- }
- nonProxyHostSuffixSize=nonProxyHostSuffix.size();
+ private volatile HttpClient savedClient;
+ static {
int cps =
JMeterUtils.getPropDefault("httpclient.socket.http.cps", 0); //
$NON-NLS-1$
@@ -191,31 +120,8 @@ public class HTTPHC3Impl extends HTTPAbs
// new Protocol(PROTOCOL_HTTPS,new
SlowHttpClientSocketFactory(cps),DEFAULT_HTTPS_PORT));
// }
- InetAddress inet=null;
- String localHostOrIP =
- JMeterUtils.getPropDefault("httpclient.localaddress",""); //
$NON-NLS-1$
- if (localHostOrIP.length() > 0){
- try {
- inet = InetAddress.getByName(localHostOrIP);
- log.info("Using localAddress "+inet.getHostAddress());
- } catch (UnknownHostException e) {
- log.warn(e.getLocalizedMessage());
- }
- } else {
- try {
- InetAddress addr = InetAddress.getLocalHost();
- // Get hostname
- localHostOrIP = addr.getHostName();
- } catch (UnknownHostException e) {
- log.warn("Cannot determine localhost name, and
httpclient.localaddress was not specified");
- }
- }
- localAddress = inet;
- localHost = localHostOrIP;
- log.info("Local host = "+localHost);
-
// Set default parameters as needed
- HttpParams params = DefaultHttpParams.getDefaultParams();
+ HttpParams params = DefaultHttpParams.getDefaultParams();
// Process httpclient parameters file
String file=JMeterUtils.getProperty("httpclient.parameters.file"); //
$NON-NLS-1$
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1041452&r1=1041451&r2=1041452&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Thu Dec 2 16:57:37 2010
@@ -22,7 +22,10 @@ import java.net.URL;
import org.apache.commons.lang.NotImplementedException;
-public class HTTPHC4Impl extends HTTPAbstractImpl {
+/**
+ * HTTP Sampler using Apache HttpClient 4.x.
+ */
+public class HTTPHC4Impl extends HTTPHCAbstractImpl {
protected HTTPHC4Impl(HTTPSamplerBase testElement) {
super(testElement);
Added:
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=1041452&view=auto
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
(added)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
Thu Dec 2 16:57:37 2010
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.jmeter.JMeter;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+/**
+ * Common parent class for HttpClient implementations.
+ *
+ * Includes system property settings that are handled internally by the Java
HTTP implementation,
+ * but which need to be explicitly configured in HttpClient implementations.
+ */
+public abstract class HTTPHCAbstractImpl extends HTTPAbstractImpl {
+
+ private static final Logger log = LoggingManager.getLoggerForClass();
+
+ protected static final String HTTP_AUTHENTICATION_PREEMPTIVE =
"http.authentication.preemptive"; // $NON-NLS-1$
+
+ protected static final String PROXY_HOST =
System.getProperty("http.proxyHost","");
+
+ protected static final String NONPROXY_HOSTS =
System.getProperty("http.nonProxyHosts","");
+
+ protected static final int PROXY_PORT =
Integer.parseInt(System.getProperty("http.proxyPort","0"));
+
+ protected static final boolean PROXY_DEFINED = PROXY_HOST.length() > 0 &&
PROXY_PORT > 0;
+
+ protected static final String PROXY_USER =
JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_USER,"");
+
+ protected static final String PROXY_PASS =
JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_PASS,"");
+
+ 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;
+
+ protected static final Set<String> nonProxyHostFull = new
HashSet<String>();
+
+ protected static final List<String> nonProxyHostSuffix = new
ArrayList<String>();
+
+ protected static final int nonProxyHostSuffixSize;
+
+ static {
+ if (NONPROXY_HOSTS.length() > 0){
+ StringTokenizer s = new StringTokenizer(NONPROXY_HOSTS,"|");//
$NON-NLS-1$
+ while (s.hasMoreTokens()){
+ String t = s.nextToken();
+ if (t.indexOf("*") ==0){// e.g. *.apache.org // $NON-NLS-1$
+ nonProxyHostSuffix.add(t.substring(1));
+ } else {
+ nonProxyHostFull.add(t);// e.g. www.apache.org
+ }
+ }
+ }
+ nonProxyHostSuffixSize=nonProxyHostSuffix.size();
+
+ InetAddress inet=null;
+ String localHostOrIP =
+ JMeterUtils.getPropDefault("httpclient.localaddress",""); //
$NON-NLS-1$
+ if (localHostOrIP.length() > 0){
+ try {
+ inet = InetAddress.getByName(localHostOrIP);
+ log.info("Using localAddress "+inet.getHostAddress());
+ } catch (UnknownHostException e) {
+ log.warn(e.getLocalizedMessage());
+ }
+ } else {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ // Get hostname
+ localHostOrIP = addr.getHostName();
+ } catch (UnknownHostException e) {
+ log.warn("Cannot determine localhost name, and
httpclient.localaddress was not specified");
+ }
+ }
+ localAddress = inet;
+ localHost = localHostOrIP;
+ log.info("Local host = "+localHost);
+
+ }
+
+ protected HTTPHCAbstractImpl(HTTPSamplerBase testElement) {
+ super(testElement);
+ }
+
+ protected static boolean isNonProxy(String host){
+ return nonProxyHostFull.contains(host) || isPartialMatch(host);
+ }
+
+ protected static boolean isPartialMatch(String host) {
+ for (int i=0;i<nonProxyHostSuffixSize;i++){
+ if (host.endsWith(nonProxyHostSuffix.get(i))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
Propchange:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]