You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/06/28 13:00:59 UTC
svn commit: r1354913 [1/2] - in
/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src:
main/java/org/apache/http/impl/client/
main/java/org/apache/http/impl/client/exec/ test/java/org/apache/http/conn/
test/java/org/apache/http/impl/...
Author: olegk
Date: Thu Jun 28 11:00:52 2012
New Revision: 1354913
URL: http://svn.apache.org/viewvc?rev=1354913&view=rev
Log:
Replaced DefaultHttpClient with immutable HttpClient instance built with HttpClientBuilder
Added:
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java (contents, props changed)
- copied, changed from r1352833, httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/InternalHttpClient.java
Removed:
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/InternalHttpClient.java
Modified:
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestDecompressingHttpClient.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/conn/TestIdleConnectionEviction.java
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java Thu Jun 28 11:00:52 2012
@@ -173,8 +173,11 @@ import org.apache.http.protocol.Immutabl
* shut down by calling {@link ClientConnectionManager#shutdown()}!
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
*/
@ThreadSafe
+@Deprecated
public abstract class AbstractHttpClient extends AbstractBasicHttpClient {
private final Log log = LogFactory.getLog(getClass());
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ClientParamsStack.java Thu Jun 28 11:00:52 2012
@@ -29,6 +29,7 @@ package org.apache.http.impl.client;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.params.DefaultedHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.AbstractHttpParams;
@@ -64,11 +65,12 @@ import org.apache.http.params.AbstractHt
* an empty params collection, since it avoids searching the empty collection
* when looking up parameters.
*
- *
- *
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link DefaultedHttpParams}
*/
@NotThreadSafe
+@Deprecated
public class ClientParamsStack extends AbstractHttpParams {
/** The application parameter collection, or <code>null</code>. */
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java Thu Jun 28 11:00:52 2012
@@ -111,8 +111,11 @@ import org.apache.http.util.VersionInfo;
* </ul>
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpClientBuilder}.
*/
@ThreadSafe
+@Deprecated
public class DefaultHttpClient extends AbstractHttpClient {
/**
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Thu Jun 28 11:00:52 2012
@@ -40,13 +40,19 @@ import org.apache.http.HttpRequestInterc
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpVersion;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.auth.AuthSchemeFactory;
+import org.apache.http.auth.AuthSchemeRegistry;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.client.BackoffManager;
import org.apache.http.client.ConnectionBackoffStrategy;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.UserTokenHandler;
+import org.apache.http.client.params.AuthPolicy;
+import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.protocol.RequestAcceptEncoding;
import org.apache.http.client.protocol.RequestAddCookies;
import org.apache.http.client.protocol.RequestAuthCache;
@@ -57,19 +63,34 @@ import org.apache.http.client.protocol.R
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.routing.HttpRoutePlanner;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.cookie.CookieSpecFactory;
+import org.apache.http.cookie.CookieSpecRegistry;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.NoConnectionReuseStrategy;
+import org.apache.http.impl.auth.BasicSchemeFactory;
+import org.apache.http.impl.auth.DigestSchemeFactory;
+import org.apache.http.impl.auth.KerberosSchemeFactory;
+import org.apache.http.impl.auth.NTLMSchemeFactory;
+import org.apache.http.impl.auth.SPNegoSchemeFactory;
import org.apache.http.impl.client.exec.BackoffStrategyExec;
import org.apache.http.impl.client.exec.ClientExecChain;
import org.apache.http.impl.client.exec.MainClientExec;
import org.apache.http.impl.client.exec.ProtocolExec;
import org.apache.http.impl.client.exec.RedirectExec;
import org.apache.http.impl.client.exec.RetryExec;
-import org.apache.http.impl.client.exec.InternalHttpClient;
import org.apache.http.impl.conn.DefaultHttpRoutePlanner;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
import org.apache.http.impl.conn.SchemeRegistryFactory;
+import org.apache.http.impl.cookie.BestMatchSpecFactory;
+import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
+import org.apache.http.impl.cookie.IgnoreSpecFactory;
+import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
+import org.apache.http.impl.cookie.RFC2109SpecFactory;
+import org.apache.http.impl.cookie.RFC2965SpecFactory;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
@@ -161,6 +182,7 @@ import org.apache.http.util.VersionInfo;
public class HttpClientBuilder {
private HttpRequestExecutor requestExec;
+ private SchemeLayeredSocketFactory sslSocketFactory;
private ClientConnectionManager connManager;
private ConnectionReuseStrategy reuseStrategy;
private ConnectionKeepAliveStrategy keepAliveStrategy;
@@ -184,8 +206,12 @@ public class HttpClientBuilder {
private HttpParams params;
+ private Map<String, AuthSchemeFactory> authShemes;
+ private Map<String, CookieSpecFactory> cookieSpecs;
+ private CookieStore cookieStore;
+ private CredentialsProvider credentialsProvider;
+
private boolean systemProperties;
- private boolean laxRedirects;
private boolean redirectHandlingDisabled;
private boolean automaticRetriesDisabled;
private boolean contentCompressionDisabled;
@@ -205,11 +231,26 @@ public class HttpClientBuilder {
return this;
}
+ public final HttpClientBuilder setSSLSocketFactory(final SchemeLayeredSocketFactory sslSocketFactory) {
+ this.sslSocketFactory = sslSocketFactory;
+ return this;
+ }
+
public final HttpClientBuilder setConnectionManager(final ClientConnectionManager connManager) {
this.connManager = connManager;
return this;
}
+ public final HttpClientBuilder setMaxConnTotal(int maxConnTotal) {
+ this.maxConnTotal = maxConnTotal;
+ return this;
+ }
+
+ public final HttpClientBuilder setMaxConnPerRoute(int maxConnPerRoute) {
+ this.maxConnPerRoute = maxConnPerRoute;
+ return this;
+ }
+
public final HttpClientBuilder setConnectionReuseStrategy(
final ConnectionReuseStrategy reuseStrategy) {
this.reuseStrategy = reuseStrategy;
@@ -319,6 +360,35 @@ public class HttpClientBuilder {
return this;
}
+ public final HttpClientBuilder setCookieStore(final CookieStore cookieStore) {
+ this.cookieStore = cookieStore;
+ return this;
+ }
+
+ public final HttpClientBuilder setCredentialsProvider(
+ final CredentialsProvider credentialsProvider) {
+ this.credentialsProvider = credentialsProvider;
+ return this;
+ }
+
+ public final HttpClientBuilder registerAuthScheme(
+ final String name, final AuthSchemeFactory authSchemeFactory) {
+ if (this.authShemes == null) {
+ this.authShemes = new HashMap<String, AuthSchemeFactory>();
+ }
+ this.authShemes.put(name, authSchemeFactory);
+ return this;
+ }
+
+ public final HttpClientBuilder registerCookiePolicy(
+ final String name, final CookieSpecFactory cookieSpecFactory) {
+ if (this.cookieSpecs == null) {
+ this.cookieSpecs = new HashMap<String, CookieSpecFactory>();
+ }
+ this.cookieSpecs.put(name, cookieSpecFactory);
+ return this;
+ }
+
public final HttpClientBuilder disableRedirectHandling() {
redirectHandlingDisabled = true;
return this;
@@ -334,13 +404,13 @@ public class HttpClientBuilder {
return this;
}
- public final HttpClientBuilder useSystemProperties() {
- systemProperties = true;
+ public final HttpClientBuilder disableContentCompression() {
+ contentCompressionDisabled = true;
return this;
}
- public final HttpClientBuilder useLaxRedirects() {
- laxRedirects = true;
+ public final HttpClientBuilder useSystemProperties() {
+ systemProperties = true;
return this;
}
@@ -360,9 +430,14 @@ public class HttpClientBuilder {
}
ClientConnectionManager connManager = this.connManager;
if (connManager == null) {
+ SchemeRegistry schemeRegistry = systemProperties ?
+ SchemeRegistryFactory.createSystemDefault() :
+ SchemeRegistryFactory.createDefault();
+ if (sslSocketFactory != null) {
+ schemeRegistry.register(new Scheme("https", 443, sslSocketFactory));
+ }
PoolingClientConnectionManager poolingmgr = new PoolingClientConnectionManager(
- systemProperties ? SchemeRegistryFactory.createSystemDefault() :
- SchemeRegistryFactory.createDefault());
+ schemeRegistry);
if (systemProperties) {
String s = System.getProperty("http.keepAlive");
if ("true".equalsIgnoreCase(s)) {
@@ -382,7 +457,7 @@ public class HttpClientBuilder {
connManager = poolingmgr;
}
ConnectionReuseStrategy reuseStrategy = this.reuseStrategy;
- if (reuseStrategy != null) {
+ if (reuseStrategy == null) {
if (systemProperties) {
String s = System.getProperty("http.keepAlive");
if ("true".equalsIgnoreCase(s)) {
@@ -489,11 +564,7 @@ public class HttpClientBuilder {
if (!redirectHandlingDisabled) {
RedirectStrategy redirectStrategy = this.redirectStrategy;
if (redirectStrategy == null) {
- if (laxRedirects) {
- redirectStrategy = new LaxRedirectStrategy();
- } else {
- redirectStrategy = new DefaultRedirectStrategy();
- }
+ redirectStrategy = new DefaultRedirectStrategy();
}
execChain = new RedirectExec(execChain, routePlanner, redirectStrategy);
}
@@ -511,7 +582,50 @@ public class HttpClientBuilder {
setDefaultHttpParams(params);
}
- return new InternalHttpClient(execChain, connManager, routePlanner, params);
+ CookieSpecRegistry cookieSpecRegistry = new CookieSpecRegistry();
+ cookieSpecRegistry.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory());
+ cookieSpecRegistry.register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory());
+ cookieSpecRegistry.register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory());
+ cookieSpecRegistry.register(CookiePolicy.RFC_2109, new RFC2109SpecFactory());
+ cookieSpecRegistry.register(CookiePolicy.RFC_2965, new RFC2965SpecFactory());
+ cookieSpecRegistry.register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
+ if (cookieSpecs != null) {
+ for (Map.Entry<String, CookieSpecFactory> entry: cookieSpecs.entrySet()) {
+ cookieSpecRegistry.register(entry.getKey(), entry.getValue());
+ }
+ }
+
+ AuthSchemeRegistry authSchemeRegistry = new AuthSchemeRegistry();
+ authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
+ authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
+ authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
+ authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
+ authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
+ if (authShemes != null) {
+ for (Map.Entry<String, AuthSchemeFactory> entry: authShemes.entrySet()) {
+ authSchemeRegistry.register(entry.getKey(), entry.getValue());
+ }
+ }
+
+ CookieStore defaultCookieStore = this.cookieStore;
+ if (defaultCookieStore == null) {
+ defaultCookieStore = new BasicCookieStore();
+ }
+
+ CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;
+ if (defaultCredentialsProvider == null) {
+ defaultCredentialsProvider = new BasicCredentialsProvider();
+ }
+
+ return new InternalHttpClient(
+ execChain,
+ connManager,
+ routePlanner,
+ cookieSpecRegistry,
+ authSchemeRegistry,
+ defaultCookieStore,
+ defaultCredentialsProvider,
+ params);
}
static class ListBuilder<E> {
@@ -532,7 +646,7 @@ public class HttpClientBuilder {
if (previous != null) {
this.list.remove(previous);
}
- this.list.addFirst(e);
+ this.list.add(e);
this.uniqueClasses.put(e.getClass(), e);
}
@@ -579,7 +693,7 @@ public class HttpClientBuilder {
// determine the release version from packaged version info
final VersionInfo vi = VersionInfo.loadVersionInfo
- ("org.apache.http.client", DefaultHttpClient.class.getClassLoader());
+ ("org.apache.http.client", HttpClientBuilder.class.getClassLoader());
final String release = (vi != null) ?
vi.getRelease() : VersionInfo.UNAVAILABLE;
HttpProtocolParams.setUserAgent(params,
Copied: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java (from r1352833, httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/InternalHttpClient.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java?p2=httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java&p1=httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/InternalHttpClient.java&r1=1352833&r2=1354913&rev=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/InternalHttpClient.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java Thu Jun 28 11:00:52 2012
@@ -25,7 +25,7 @@
*
*/
-package org.apache.http.impl.client.exec;
+package org.apache.http.impl.client;
import java.io.IOException;
@@ -34,17 +34,21 @@ import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.auth.AuthSchemeRegistry;
import org.apache.http.auth.AuthState;
import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.apache.http.impl.client.AbstractBasicHttpClient;
-import org.apache.http.impl.client.ClientParamsStack;
-import org.apache.http.impl.client.RequestAbortedException;
+import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.impl.client.exec.ClientExecChain;
+import org.apache.http.impl.client.exec.HttpRequestWrapper;
+import org.apache.http.params.DefaultedHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.BasicHttpContext;
@@ -54,17 +58,25 @@ import org.apache.http.protocol.HttpCont
* @since 4.3
*/
@ThreadSafe
-public class InternalHttpClient extends AbstractBasicHttpClient {
+class InternalHttpClient extends AbstractBasicHttpClient {
private final ClientExecChain execChain;
private final ClientConnectionManager connManager;
private final HttpRoutePlanner routePlanner;
+ private final CookieSpecRegistry cookieSpecRegistry;
+ private final AuthSchemeRegistry authSchemeRegistry;
+ private final CookieStore cookieStore;
+ private final CredentialsProvider credentialsProvider;
private final HttpParams params;
public InternalHttpClient(
final ClientExecChain execChain,
final ClientConnectionManager connManager,
final HttpRoutePlanner routePlanner,
+ final CookieSpecRegistry cookieSpecRegistry,
+ final AuthSchemeRegistry authSchemeRegistry,
+ final CookieStore cookieStore,
+ final CredentialsProvider credentialsProvider,
final HttpParams params) {
super();
if (execChain == null) {
@@ -79,6 +91,10 @@ public class InternalHttpClient extends
this.execChain = execChain;
this.connManager = connManager;
this.routePlanner = routePlanner;
+ this.cookieSpecRegistry = cookieSpecRegistry;
+ this.authSchemeRegistry = authSchemeRegistry;
+ this.cookieStore = cookieStore;
+ this.credentialsProvider = credentialsProvider;
this.params = params != null ? params : new SyncBasicHttpParams();
}
@@ -96,13 +112,30 @@ public class InternalHttpClient extends
return this.routePlanner.determineRoute(host, request, context);
}
- private void setupContext(final HttpContext context) {
+ private HttpContext setupContext(final HttpContext localContext) {
+ HttpContext context = localContext != null ? localContext : new BasicHttpContext();
if (context.getAttribute(ClientContext.TARGET_AUTH_STATE) == null) {
context.setAttribute(ClientContext.TARGET_AUTH_STATE, new AuthState());
}
if (context.getAttribute(ClientContext.PROXY_AUTH_STATE) == null) {
context.setAttribute(ClientContext.PROXY_AUTH_STATE, new AuthState());
}
+ if (context.getAttribute(ClientContext.SCHEME_REGISTRY) == null) {
+ context.setAttribute(ClientContext.SCHEME_REGISTRY, this.connManager.getSchemeRegistry());
+ }
+ if (context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY) == null) {
+ context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
+ }
+ if (context.getAttribute(ClientContext.COOKIESPEC_REGISTRY) == null) {
+ context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+ }
+ if (context.getAttribute(ClientContext.COOKIE_STORE) == null) {
+ context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
+ }
+ if (context.getAttribute(ClientContext.CREDS_PROVIDER) == null) {
+ context.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
+ }
+ return context;
}
public HttpResponse execute(
@@ -113,9 +146,7 @@ public class InternalHttpClient extends
throw new IllegalArgumentException("Request must not be null.");
}
try {
- HttpContext execContext = context != null ? context : new BasicHttpContext();
- setupContext(context);
- HttpParams params = new ClientParamsStack(null, getParams(), request.getParams(), null);
+ HttpParams params = new DefaultedHttpParams(request.getParams(), getParams());
HttpHost virtualHost = (HttpHost) params.getParameter(ClientPNames.VIRTUAL_HOST);
HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
@@ -128,8 +159,8 @@ public class InternalHttpClient extends
throw new RequestAbortedException("Request aborted");
}
}
- HttpRoute route = determineRoute(target, request, context);
- return this.execChain.execute(route, wrapper, execContext, execListner);
+ HttpRoute route = determineRoute(target, wrapper, context);
+ return this.execChain.execute(route, wrapper, setupContext(context), execListner);
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException);
}
Propchange: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/conn/TestConnectionReuse.java Thu Jun 28 11:00:52 2012
@@ -36,21 +36,12 @@ import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
-import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.localserver.RandomHandler;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
@@ -88,23 +79,11 @@ public class TestConnectionReuse {
InetSocketAddress saddress = this.localServer.getServiceAddress();
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF-8");
- HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
- HttpProtocolParams.setUseExpectContinue(params, false);
- HttpConnectionParams.setStaleCheckingEnabled(params, false);
-
- SchemeRegistry supportedSchemes = new SchemeRegistry();
- SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", 80, sf));
-
- PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
+ PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
mgr.setMaxTotal(5);
mgr.setDefaultMaxPerRoute(5);
- DefaultHttpClient client = new DefaultHttpClient(mgr, params);
-
+ HttpClient client = new HttpClientBuilder().setConnectionManager(mgr).build();
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
WorkerThread[] workers = new WorkerThread[10];
@@ -159,22 +138,11 @@ public class TestConnectionReuse {
InetSocketAddress saddress = this.localServer.getServiceAddress();
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF-8");
- HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
- HttpProtocolParams.setUseExpectContinue(params, false);
- HttpConnectionParams.setStaleCheckingEnabled(params, false);
-
- SchemeRegistry supportedSchemes = new SchemeRegistry();
- SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", 80, sf));
-
- PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
+ PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
mgr.setMaxTotal(5);
mgr.setDefaultMaxPerRoute(5);
- DefaultHttpClient client = new DefaultHttpClient(mgr, params);
+ HttpClient client = new HttpClientBuilder().setConnectionManager(mgr).build();
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
@@ -220,22 +188,11 @@ public class TestConnectionReuse {
InetSocketAddress saddress = this.localServer.getServiceAddress();
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF-8");
- HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
- HttpProtocolParams.setUseExpectContinue(params, false);
- HttpConnectionParams.setStaleCheckingEnabled(params, false);
-
- SchemeRegistry supportedSchemes = new SchemeRegistry();
- SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", 80, sf));
-
- PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
+ PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
mgr.setMaxTotal(5);
mgr.setDefaultMaxPerRoute(5);
- DefaultHttpClient client = new DefaultHttpClient(mgr, params);
+ HttpClient client = new HttpClientBuilder().setConnectionManager(mgr).build();
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
@@ -282,22 +239,12 @@ public class TestConnectionReuse {
InetSocketAddress saddress = this.localServer.getServiceAddress();
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF-8");
- HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
- HttpProtocolParams.setUseExpectContinue(params, false);
- HttpConnectionParams.setStaleCheckingEnabled(params, false);
-
- SchemeRegistry supportedSchemes = new SchemeRegistry();
- SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", 80, sf));
-
- PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
+ PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
mgr.setMaxTotal(1);
mgr.setDefaultMaxPerRoute(1);
- DefaultHttpClient client = new DefaultHttpClient(mgr, params);
+ HttpClient client = new HttpClientBuilder().setConnectionManager(mgr).build();
+
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
HttpResponse response = client.execute(target, new HttpGet("/random/2000"));
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestDecompressingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestDecompressingHttpClient.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestDecompressingHttpClient.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestDecompressingHttpClient.java Thu Jun 28 11:00:52 2012
@@ -61,6 +61,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+@Deprecated
@RunWith(MockitoJUnitRunner.class)
public class TestDecompressingHttpClient {
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/TestRequestRetryHandler.java Thu Jun 28 11:00:52 2012
@@ -30,6 +30,7 @@ import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
@@ -54,14 +55,11 @@ public class TestRequestRetryHandler {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory()));
ClientConnectionManager connManager = new PoolingClientConnectionManager(schemeRegistry);
-
- assertOnRetry(connManager);
- }
-
- protected void assertOnRetry(ClientConnectionManager connManager) throws Exception {
- DefaultHttpClient client = new DefaultHttpClient(connManager);
TestHttpRequestRetryHandler testRetryHandler = new TestHttpRequestRetryHandler();
- client.setHttpRequestRetryHandler(testRetryHandler);
+
+ HttpClient client = new HttpClientBuilder()
+ .setConnectionManager(connManager)
+ .setRetryHandler(testRetryHandler).build();
HttpUriRequest request = new HttpGet("http://www.example.com/");
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/IntegrationTestBase.java Thu Jun 28 11:00:52 2012
@@ -25,13 +25,13 @@
*/
package org.apache.http.impl.client.integration;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.client.HttpClient;
import org.apache.http.localserver.LocalServerTestBase;
import org.junit.After;
public class IntegrationTestBase extends LocalServerTestBase {
- protected DefaultHttpClient httpclient;
+ protected HttpClient httpclient;
@After
public void shutDownClient() throws Exception {
@@ -39,9 +39,5 @@ public class IntegrationTestBase extends
this.httpclient.getConnectionManager().shutdown();
}
}
-
- protected void initClient() {
- this.httpclient = new DefaultHttpClient();
- }
-
+
}
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java Thu Jun 28 11:00:52 2012
@@ -38,6 +38,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolVersion;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionRequest;
@@ -45,16 +46,14 @@ import org.apache.http.conn.ConnectionPo
import org.apache.http.conn.ConnectionReleaseTrigger;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.SchemeRegistryFactory;
import org.apache.http.message.BasicHeader;
import org.apache.http.mockup.SocketFactoryMockup;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
@@ -72,7 +71,6 @@ public class TestAbortHandling extends I
@Before
public void setUp() throws Exception {
- initClient();
startServer();
}
@@ -111,6 +109,8 @@ public class TestAbortHandling extends I
t.start();
+ this.httpclient = new HttpClientBuilder().build();
+
HttpContext context = new BasicHttpContext();
try {
this.httpclient.execute(getServerHttp(), httpget, context);
@@ -134,9 +134,10 @@ public class TestAbortHandling extends I
final ConMan conMan = new ConMan(connLatch, awaitLatch);
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
final CountDownLatch getLatch = new CountDownLatch(1);
- final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
+ final HttpClient client = new HttpClientBuilder().setConnectionManager(conMan).build();
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new HttpGet("http://www.example.com/a");
+ this.httpclient = client;
new Thread(new Runnable() {
public void run() {
@@ -169,16 +170,14 @@ public class TestAbortHandling extends I
public void testAbortAfterAllocateBeforeRequest() throws Exception {
this.localServer.register("*", new BasicService());
- CountDownLatch releaseLatch = new CountDownLatch(1);
- SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
-
- PoolingClientConnectionManager conMan = new PoolingClientConnectionManager(registry);
+ final CountDownLatch releaseLatch = new CountDownLatch(1);
+ final PoolingClientConnectionManager conMan = new PoolingClientConnectionManager();
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
final CountDownLatch getLatch = new CountDownLatch(1);
- final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
+ final HttpClient client = new HttpClientBuilder().setConnectionManager(conMan).build();
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new CustomGet("a", releaseLatch);
+ this.httpclient = client;
new Thread(new Runnable() {
public void run() {
@@ -211,16 +210,14 @@ public class TestAbortHandling extends I
public void testAbortBeforeExecute() throws Exception {
this.localServer.register("*", new BasicService());
- SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
-
- PoolingClientConnectionManager conMan = new PoolingClientConnectionManager(registry);
+ final PoolingClientConnectionManager conMan = new PoolingClientConnectionManager();
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
final CountDownLatch getLatch = new CountDownLatch(1);
final CountDownLatch startLatch = new CountDownLatch(1);
- final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
+ final HttpClient client = new HttpClientBuilder().setConnectionManager(conMan).build();
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new HttpGet("a");
+ this.httpclient = client;
new Thread(new Runnable() {
public void run() {
@@ -258,17 +255,15 @@ public class TestAbortHandling extends I
final int port = this.localServer.getServiceAddress().getPort();
this.localServer.register("*", new BasicRedirectService(port));
- SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
-
- CountDownLatch connLatch = new CountDownLatch(1);
- CountDownLatch awaitLatch = new CountDownLatch(1);
- ConnMan4 conMan = new ConnMan4(registry, connLatch, awaitLatch);
+ final CountDownLatch connLatch = new CountDownLatch(1);
+ final CountDownLatch awaitLatch = new CountDownLatch(1);
+ final ConnMan4 conMan = new ConnMan4(connLatch, awaitLatch);
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
final CountDownLatch getLatch = new CountDownLatch(1);
- final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
+ final HttpClient client = new HttpClientBuilder().setConnectionManager(conMan).build();
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new HttpGet("a");
+ this.httpclient = client;
new Thread(new Runnable() {
public void run() {
@@ -317,7 +312,7 @@ public class TestAbortHandling extends I
Mockito.any(HttpRoute.class), Mockito.any())).thenReturn(connrequest);
Mockito.when(connmgr.getSchemeRegistry()).thenReturn(schemeRegistry);
- final DefaultHttpClient client = new DefaultHttpClient(connmgr, new BasicHttpParams());
+ final HttpClient client = new HttpClientBuilder().setConnectionManager(connmgr).build();
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new HttpGet("http://www.example.com/a");
@@ -361,9 +356,8 @@ public class TestAbortHandling extends I
private final CountDownLatch connLatch;
private final CountDownLatch awaitLatch;
- public ConnMan4(SchemeRegistry schreg,
- CountDownLatch connLatch, CountDownLatch awaitLatch) {
- super(schreg);
+ public ConnMan4(CountDownLatch connLatch, CountDownLatch awaitLatch) {
+ super();
this.connLatch = connLatch;
this.awaitLatch = awaitLatch;
}
@@ -475,7 +469,6 @@ public class TestAbortHandling extends I
}
public void shutdown() {
- throw new UnsupportedOperationException("just a mockup");
}
}
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java Thu Jun 28 11:00:52 2012
@@ -47,6 +47,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.TargetAuthenticationStrategy;
import org.apache.http.localserver.BasicAuthTokenExtractor;
import org.apache.http.localserver.LocalTestServer;
@@ -83,7 +84,6 @@ public class TestClientAuthentication ex
httpproc.addInterceptor(new ResponseBasicUnauthorized());
this.localServer = new LocalTestServer(httpproc, null);
startServer();
- initClient();
}
static class AuthHandler implements HttpRequestHandler {
@@ -159,8 +159,7 @@ public class TestClientAuthentication ex
this.localServer.register("*", new AuthHandler());
TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
-
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpGet httpget = new HttpGet("/");
@@ -181,7 +180,7 @@ public class TestClientAuthentication ex
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "all-wrong"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpGet httpget = new HttpGet("/");
@@ -202,7 +201,7 @@ public class TestClientAuthentication ex
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpGet httpget = new HttpGet("/");
@@ -233,8 +232,7 @@ public class TestClientAuthentication ex
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
-
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpPut httpput = new HttpPut("/");
httpput.setEntity(new InputStreamEntity(
@@ -256,8 +254,7 @@ public class TestClientAuthentication ex
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
-
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpPut httpput = new HttpPut("/");
httpput.setEntity(new InputStreamEntity(
@@ -284,8 +281,7 @@ public class TestClientAuthentication ex
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
-
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpPost httppost = new HttpPost("/");
httppost.setEntity(new StringEntity("some important stuff", Consts.ASCII));
@@ -307,7 +303,7 @@ public class TestClientAuthentication ex
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpPost httppost = new HttpPost("/");
httppost.setEntity(new InputStreamEntity(
@@ -362,11 +358,12 @@ public class TestClientAuthentication ex
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("test", "test"));
-
TestTargetAuthenticationStrategy authStrategy = new TestTargetAuthenticationStrategy();
- this.httpclient.setCredentialsProvider(credsProvider);
- this.httpclient.setTargetAuthenticationStrategy(authStrategy);
+ this.httpclient = new HttpClientBuilder()
+ .setCredentialsProvider(credsProvider)
+ .setTargetAuthenticationStrategy(authStrategy)
+ .build();
HttpContext context = new BasicHttpContext();
@@ -394,6 +391,8 @@ public class TestClientAuthentication ex
HttpHost target = getServerHttp();
HttpGet httpget = new HttpGet("http://test:test@" + target.toHostString() + "/");
+ this.httpclient = new HttpClientBuilder().build();
+
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
HttpEntity entity = response.getEntity();
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
@@ -408,6 +407,8 @@ public class TestClientAuthentication ex
HttpHost target = getServerHttp();
HttpGet httpget = new HttpGet("http://test:all-wrong@" + target.toHostString() + "/");
+ this.httpclient = new HttpClientBuilder().build();
+
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
HttpEntity entity = response.getEntity();
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java Thu Jun 28 11:00:52 2012
@@ -41,6 +41,7 @@ import org.apache.http.auth.UsernamePass
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.protocol.BasicHttpProcessor;
@@ -82,7 +83,6 @@ public class TestClientAuthenticationFal
this.localServer = new LocalTestServer(httpproc, null);
startServer();
- initClient();
}
static class AuthHandler implements HttpRequestHandler {
@@ -137,8 +137,7 @@ public class TestClientAuthenticationFal
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
-
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpGet httpget = new HttpGet("/");
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java Thu Jun 28 11:00:52 2012
@@ -42,6 +42,7 @@ import org.apache.http.auth.UsernamePass
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.protocol.BasicHttpContext;
@@ -83,7 +84,6 @@ public class TestClientReauthentication
this.localServer = new LocalTestServer(httpproc, null);
startServer();
- initClient();
}
static class AuthHandler implements HttpRequestHandler {
@@ -145,7 +145,7 @@ public class TestClientReauthentication
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = new HttpClientBuilder().setCredentialsProvider(credsProvider).build();
HttpContext context = new BasicHttpContext();
for (int i = 0; i < 10; i++) {
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java Thu Jun 28 11:00:52 2012
@@ -44,7 +44,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
@@ -63,7 +63,6 @@ public class TestClientRequestExecution
@Before
public void setUp() throws Exception {
startServer();
- initClient();
}
private static class SimpleService implements HttpRequestHandler {
@@ -89,6 +88,7 @@ public class TestClientRequestExecution
HttpHost target = new HttpHost("localhost", port);
+ this.httpclient = new HttpClientBuilder().build();
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
String s = "/path";
@@ -110,6 +110,7 @@ public class TestClientRequestExecution
String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s);
+ this.httpclient = new HttpClientBuilder().build();
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
EntityUtils.consume(response.getEntity());
@@ -135,6 +136,7 @@ public class TestClientRequestExecution
String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s);
+ this.httpclient = new HttpClientBuilder().build();
String virtHost = "virtual";
httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
@@ -164,6 +166,7 @@ public class TestClientRequestExecution
String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s);
+ this.httpclient = new HttpClientBuilder().build();
String virtHost = "virtual";
int virtPort = 9876;
httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, virtPort));
@@ -191,6 +194,7 @@ public class TestClientRequestExecution
String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s);
+ this.httpclient = new HttpClientBuilder().build();
String virtHost = "virtual";
this.httpclient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
@@ -215,6 +219,7 @@ public class TestClientRequestExecution
HttpHost target1 = new HttpHost("whatever", 80);
HttpHost target2 = new HttpHost("localhost", port);
+ this.httpclient = new HttpClientBuilder().build();
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target1);
String s = "/path";
@@ -253,33 +258,12 @@ public class TestClientRequestExecution
}
- private static class FaultyHttpClient extends DefaultHttpClient {
-
- private final String failureMsg;
-
- public FaultyHttpClient() {
- this("Oppsie");
- }
-
- public FaultyHttpClient(String failureMsg) {
- this.failureMsg = failureMsg;
- }
-
- @Override
- protected HttpRequestExecutor createRequestExecutor() {
- return new FaultyHttpRequestExecutor(failureMsg);
- }
-
- }
-
@Test
public void testAutoGeneratedHeaders() throws Exception {
int port = this.localServer.getServiceAddress().getPort();
this.localServer.register("*", new SimpleService());
- FaultyHttpClient client = new FaultyHttpClient();
-
- client.addRequestInterceptor(new HttpRequestInterceptor() {
+ HttpRequestInterceptor interceptor = new HttpRequestInterceptor() {
public void process(
final HttpRequest request,
@@ -287,9 +271,9 @@ public class TestClientRequestExecution
request.addHeader("my-header", "stuff");
}
- }) ;
+ };
- client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
+ HttpRequestRetryHandler requestRetryHandler = new HttpRequestRetryHandler() {
public boolean retryRequest(
final IOException exception,
@@ -298,14 +282,20 @@ public class TestClientRequestExecution
return true;
}
- });
+ };
+
+ this.httpclient = new HttpClientBuilder()
+ .addInterceptorFirst(interceptor)
+ .setRequestExecutor(new FaultyHttpRequestExecutor("Oppsie"))
+ .setRetryHandler(requestRetryHandler)
+ .build();
HttpContext context = new BasicHttpContext();
String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s);
- HttpResponse response = client.execute(getServerHttp(), httpget, context);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
EntityUtils.consume(response.getEntity());
HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
@@ -323,10 +313,7 @@ public class TestClientRequestExecution
int port = this.localServer.getServiceAddress().getPort();
this.localServer.register("*", new SimpleService());
- String failureMsg = "a message showing that this failed";
-
- FaultyHttpClient client = new FaultyHttpClient(failureMsg);
- client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
+ HttpRequestRetryHandler requestRetryHandler = new HttpRequestRetryHandler() {
public boolean retryRequest(
final IOException exception,
@@ -335,7 +322,13 @@ public class TestClientRequestExecution
return true;
}
- });
+ };
+
+ this.httpclient = new HttpClientBuilder()
+ .setRequestExecutor(new FaultyHttpRequestExecutor("a message showing that this failed"))
+ .setRetryHandler(requestRetryHandler)
+ .build();
+
HttpContext context = new BasicHttpContext();
String s = "http://localhost:" + port;
@@ -346,12 +339,12 @@ public class TestClientRequestExecution
-1));
try {
- client.execute(getServerHttp(), httppost, context);
+ this.httpclient.execute(getServerHttp(), httppost, context);
} catch (ClientProtocolException ex) {
Assert.assertTrue(ex.getCause() instanceof NonRepeatableRequestException);
NonRepeatableRequestException nonRepeat = (NonRepeatableRequestException)ex.getCause();
Assert.assertTrue(nonRepeat.getCause() instanceof IOException);
- Assert.assertEquals(failureMsg, nonRepeat.getCause().getMessage());
+ Assert.assertEquals("a message showing that this failed", nonRepeat.getCause().getMessage());
throw ex;
}
}
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java Thu Jun 28 11:00:52 2012
@@ -45,7 +45,7 @@ import org.apache.http.conn.ManagedClien
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.DefaultHttpServerConnection;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.pool.PoolStats;
import org.apache.http.protocol.ExecutionContext;
@@ -59,14 +59,14 @@ import org.junit.Test;
public class TestConnectionAutoRelease extends IntegrationTestBase {
private PoolingClientConnectionManager mgr;
-
+
@Before
public void setUp() throws Exception {
startServer();
this.mgr = new PoolingClientConnectionManager();
- this.httpclient = new DefaultHttpClient(this.mgr);
+ this.httpclient = new HttpClientBuilder().setConnectionManager(this.mgr).build();
}
-
+
@Test
public void testReleaseOnEntityConsumeContent() throws Exception {
this.mgr.setDefaultMaxPerRoute(1);
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java Thu Jun 28 11:00:52 2012
@@ -49,14 +49,10 @@ import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.DeflateDecompressingEntity;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.DecompressingHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
@@ -75,9 +71,8 @@ public class TestContentCodings extends
@Before
public void setUp() throws Exception {
startServer();
- initClient();
}
-
+
/**
* Test for when we don't get an entity back; e.g. for a 204 or 304 response; nothing blows
* up with the new behaviour.
@@ -100,14 +95,12 @@ public class TestContentCodings extends
}
});
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
HttpGet request = new HttpGet("/some-resource");
- HttpResponse response = client.execute(getServerHttp(), request);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), request);
Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
Assert.assertNull(response.getEntity());
-
- client.getConnectionManager().shutdown();
}
/**
@@ -123,14 +116,12 @@ public class TestContentCodings extends
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
HttpGet request = new HttpGet("/some-resource");
- HttpResponse response = client.execute(getServerHttp(), request);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), request);
Assert.assertEquals("The entity text is correctly transported", entityText,
EntityUtils.toString(response.getEntity()));
-
- client.getConnectionManager().shutdown();
}
/**
@@ -146,14 +137,12 @@ public class TestContentCodings extends
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
HttpGet request = new HttpGet("/some-resource");
- HttpResponse response = client.execute(getServerHttp(), request);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), request);
Assert.assertEquals("The entity text is correctly transported", entityText,
EntityUtils.toString(response.getEntity()));
-
- client.getConnectionManager().shutdown();
}
/**
@@ -167,14 +156,12 @@ public class TestContentCodings extends
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
HttpGet request = new HttpGet("/some-resource");
- HttpResponse response = client.execute(getServerHttp(), request);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), request);
Assert.assertEquals("The entity text is correctly transported", entityText,
EntityUtils.toString(response.getEntity()));
-
- client.getConnectionManager().shutdown();
}
/**
@@ -195,13 +182,10 @@ public class TestContentCodings extends
*/
int clients = 100;
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
-
- PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
+ PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
cm.setMaxTotal(clients);
- final HttpClient httpClient = new DefaultHttpClient(cm);
+ this.httpclient = new HttpClientBuilder().setConnectionManager(cm).build();
ExecutorService executor = Executors.newFixedThreadPool(clients);
@@ -211,7 +195,7 @@ public class TestContentCodings extends
List<WorkerTask> workers = new ArrayList<WorkerTask>();
for (int i = 0; i < clients; ++i) {
- workers.add(new WorkerTask(httpClient, i % 2 == 0, startGate, endGate));
+ workers.add(new WorkerTask(this.httpclient, i % 2 == 0, startGate, endGate));
}
for (WorkerTask workerTask : workers) {
@@ -245,16 +229,15 @@ public class TestContentCodings extends
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
+
HttpGet request = new HttpGet("/some-resource");
- HttpResponse response = client.execute(getServerHttp(), request);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), request);
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
Assert.assertEquals(entityText, out.toString("utf-8"));
-
- client.getConnectionManager().shutdown();
}
/**
@@ -269,17 +252,15 @@ public class TestContentCodings extends
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
HttpGet request = new HttpGet("/some-resource");
- HttpResponse response = client.execute(getServerHttp(), request);
+ HttpResponse response = this.httpclient.execute(getServerHttp(), request);
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
Assert.assertEquals(entityText, out.toString("utf-8"));
-
- client.getConnectionManager().shutdown();
}
@Test
@@ -288,13 +269,11 @@ public class TestContentCodings extends
this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
+ this.httpclient = new HttpClientBuilder().build();
HttpGet request = new HttpGet("/some-resource");
- String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
+ String response = this.httpclient.execute(getServerHttp(), request, new BasicResponseHandler());
Assert.assertEquals("The entity text is correctly transported", entityText, response);
-
- client.getConnectionManager().shutdown();
}
@Test
@@ -303,13 +282,11 @@ public class TestContentCodings extends
this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
- HttpClient client = new DecompressingHttpClient(new DefaultHttpClient());
-
+ this.httpclient = new HttpClientBuilder().build();
+
HttpGet request = new HttpGet("/some-resource");
- String response = client.execute(getServerHttp(), request, new BasicResponseHandler());
+ String response = this.httpclient.execute(getServerHttp(), request, new BasicResponseHandler());
Assert.assertEquals("The entity text is correctly transported", entityText, response);
-
- client.getConnectionManager().shutdown();
}
/**
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java Thu Jun 28 11:00:52 2012
@@ -45,6 +45,7 @@ import org.apache.http.cookie.SM;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
@@ -63,7 +64,7 @@ public class TestCookie2Support extends
@Before
public void setUp() throws Exception {
startServer();
- initClient();
+ this.httpclient = new HttpClientBuilder().build();
}
private static class CookieVer0Service implements HttpRequestHandler {
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java Thu Jun 28 11:00:52 2012
@@ -46,9 +46,11 @@ import org.apache.http.client.RedirectEx
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.protocol.ClientContext;
import org.apache.http.cookie.SM;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.BasicHttpContext;
@@ -69,7 +71,7 @@ public class TestRedirects extends Integ
@Before
public void setUp() throws Exception {
startServer();
- initClient();
+ this.httpclient = new HttpClientBuilder().build();
}
private static class BasicRedirectService implements HttpRequestHandler {
@@ -599,11 +601,9 @@ public class TestRedirects extends Integ
int port = address.getPort();
String host = address.getHostName();
- this.localServer.register("*",
- new BasicRedirectService(host, port));
+ this.localServer.register("*", new BasicRedirectService(host, port));
CookieStore cookieStore = new BasicCookieStore();
- this.httpclient.setCookieStore(cookieStore);
BasicClientCookie cookie = new BasicClientCookie("name", "value");
cookie.setDomain(host);
@@ -612,6 +612,7 @@ public class TestRedirects extends Integ
cookieStore.addCookie(cookie);
HttpContext context = new BasicHttpContext();
+ context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("/oldlocation/");
@@ -634,8 +635,7 @@ public class TestRedirects extends Integ
int port = address.getPort();
String host = address.getHostName();
- this.localServer.register("*",
- new BasicRedirectService(host, port));
+ this.localServer.register("*", new BasicRedirectService(host, port));
HttpContext context = new BasicHttpContext();
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java Thu Jun 28 11:00:52 2012
@@ -37,12 +37,15 @@ import org.apache.http.HttpStatus;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
+import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.SPNegoScheme;
import org.apache.http.impl.auth.SPNegoSchemeFactory;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
@@ -68,7 +71,6 @@ public class TestSPNegoScheme extends In
@Before
public void setUp() throws Exception {
startServer();
- initClient();
}
/**
@@ -158,12 +160,15 @@ public class TestSPNegoScheme extends In
HttpHost target = new HttpHost("localhost", port);
SPNegoSchemeFactory nsf = new NegotiateSchemeFactoryWithMockGssManager();
-
- this.httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, nsf);
-
+ CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Credentials use_jaas_creds = new UseJaasCredentials();
- this.httpclient.getCredentialsProvider().setCredentials(
- new AuthScope(null, -1, null), use_jaas_creds);
+ credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
+
+ this.httpclient = new HttpClientBuilder()
+ .registerAuthScheme(AuthPolicy.SPNEGO, nsf)
+ .setCredentialsProvider(credentialsProvider)
+ .build();
+
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
String s = "/path";
@@ -187,13 +192,16 @@ public class TestSPNegoScheme extends In
NegotiateSchemeFactoryWithMockGssManager nsf = new NegotiateSchemeFactoryWithMockGssManager();
- this.httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, nsf);
-
+ CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Credentials use_jaas_creds = new UseJaasCredentials();
- this.httpclient.getCredentialsProvider().setCredentials(
- new AuthScope(null, -1, null), use_jaas_creds);
+ credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
+
+ this.httpclient = new HttpClientBuilder()
+ .registerAuthScheme(AuthPolicy.SPNEGO, nsf)
+ .setCredentialsProvider(credentialsProvider)
+ .build();
this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
-
+
String s = "/path";
HttpGet httpget = new HttpGet(s);
HttpResponse response = this.httpclient.execute(httpget);
Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java?rev=1354913&r1=1354912&r2=1354913&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java (original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java Thu Jun 28 11:00:52 2012
@@ -37,7 +37,7 @@ import org.apache.http.client.UserTokenH
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
@@ -92,11 +92,22 @@ public class TestStatefulConnManagement
HttpConnectionParams.setConnectionTimeout(params, 10);
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
- this.httpclient = new DefaultHttpClient(mgr);
mgr.setMaxTotal(workerCount);
mgr.setDefaultMaxPerRoute(workerCount);
- this.httpclient.setParams(params);
+ UserTokenHandler userTokenHandler = new UserTokenHandler() {
+
+ public Object getUserToken(final HttpContext context) {
+ Integer id = (Integer) context.getAttribute("user");
+ return id;
+ }
+
+ };
+
+ this.httpclient = new HttpClientBuilder()
+ .setConnectionManager(mgr)
+ .setUserTokenHandler(userTokenHandler)
+ .build();
HttpContext[] contexts = new HttpContext[workerCount];
HttpWorker[] workers = new HttpWorker[workerCount];
@@ -107,16 +118,6 @@ public class TestStatefulConnManagement
workers[i] = new HttpWorker(context, requestCount, target, this.httpclient);
}
- this.httpclient.setUserTokenHandler(new UserTokenHandler() {
-
- public Object getUserToken(final HttpContext context) {
- Integer id = (Integer) context.getAttribute("user");
- return id;
- }
-
- });
-
-
for (int i = 0; i < workers.length; i++) {
workers[i].start();
}
@@ -214,18 +215,22 @@ public class TestStatefulConnManagement
// We build a client with 2 max active // connections, and 2 max per route.
PoolingClientConnectionManager connMngr = new PoolingClientConnectionManager();
- this.httpclient = new DefaultHttpClient(connMngr);
connMngr.setMaxTotal(maxConn);
connMngr.setDefaultMaxPerRoute(maxConn);
- this.httpclient.setUserTokenHandler(new UserTokenHandler() {
+ UserTokenHandler userTokenHandler = new UserTokenHandler() {
public Object getUserToken(final HttpContext context) {
return context.getAttribute("user");
}
- });
+ };
+ this.httpclient = new HttpClientBuilder()
+ .setConnectionManager(connMngr)
+ .setUserTokenHandler(userTokenHandler)
+ .build();
+
// Bottom of the pool : a *keep alive* connection to Route 1.
HttpContext context1 = new BasicHttpContext();
context1.setAttribute("user", "stuff");