You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/12/09 04:06:56 UTC
svn commit: r1043826 - in
/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler:
HTTPHC3Impl.java HTTPHCAbstractImpl.java
Author: sebb
Date: Thu Dec 9 03:06:55 2010
New Revision: 1043826
URL: http://svn.apache.org/viewvc?rev=1043826&view=rev
Log:
HTTP_AUTHENTICATION_PREEMPTIVE is for Commons HttpClient only
Add HttpClientKey class for use in HttpClient ThreadLocal maps.
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=1043826&r1=1043825&r2=1043826&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 9 03:06:55 2010
@@ -36,6 +36,7 @@ import org.apache.commons.httpclient.Htt
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.ProtocolException;
@@ -57,6 +58,7 @@ import org.apache.commons.httpclient.met
import org.apache.commons.httpclient.methods.multipart.PartBase;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.params.DefaultHttpParams;
+import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.httpclient.protocol.Protocol;
@@ -87,6 +89,8 @@ public class HTTPHC3Impl extends HTTPHCA
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 ThreadLocal<Map<HostConfiguration, HttpClient>> httpClients =
@@ -613,8 +617,9 @@ public class HTTPHC3Impl extends HTTPHCA
* this <code>UrlConfig</code>
*/
private void setConnectionAuthorization(HttpClient client, URL u, AuthManager authManager) {
- HttpParams params = client.getParams();
+ HttpState state = client.getState();
if (authManager != null) {
+ HttpClientParams params = client.getParams();
Authorization auth = authManager.getAuthForURL(u);
if (auth != null) {
String username = auth.getUser();
@@ -623,7 +628,7 @@ public class HTTPHC3Impl extends HTTPHCA
if (log.isDebugEnabled()){
log.debug(username + " > D="+ username + " D="+domain+" R="+realm);
}
- client.getState().setCredentials(
+ state.setCredentials(
new AuthScope(u.getHost(),u.getPort(),
realm.length()==0 ? null : realm //"" is not the same as no realm
,AuthScope.ANY_SCHEME),
@@ -637,20 +642,16 @@ public class HTTPHC3Impl extends HTTPHCA
// We have credentials - should we set pre-emptive authentication?
if (canSetPreEmptive){
log.debug("Setting Pre-emptive authentication");
- params.setBooleanParameter(HTTP_AUTHENTICATION_PREEMPTIVE, true);
+ params.setAuthenticationPreemptive(true);
}
- }
- else
- {
- client.getState().clearCredentials();
+ } else {
+ state.clearCredentials();
if (canSetPreEmptive){
- params.setBooleanParameter(HTTP_AUTHENTICATION_PREEMPTIVE, false);
+ params.setAuthenticationPreemptive(false);
}
}
- }
- else
- {
- client.getState().clearCredentials();
+ } else {
+ state.clearCredentials();
}
}
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=1043826&r1=1043825&r2=1043826&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 Thu Dec 9 03:06:55 2010
@@ -19,6 +19,7 @@
package org.apache.jmeter.protocol.http.sampler;
import java.net.InetAddress;
+import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashSet;
@@ -41,8 +42,6 @@ public abstract class HTTPHCAbstractImpl
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","");
@@ -146,4 +145,80 @@ public abstract class HTTPHCAbstractImpl
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: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org