hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1370953 [2/5] - in /httpcomponents/httpclient/trunk: ./ fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/main/java/org/apache/http/client/methods/ httpclient/src/main/java/org/apache/http/client/protocol/ httpclient/sr...
Date Wed, 08 Aug 2012 20:35:16 GMT
Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Wed Aug  8 20:35:13 2012
@@ -0,0 +1,718 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import java.net.ProxySelector;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpRequestInterceptor;
+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.ServiceUnavailableRetryStrategy;
+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;
+import org.apache.http.client.protocol.RequestClientConnControl;
+import org.apache.http.client.protocol.RequestDefaultHeaders;
+import org.apache.http.client.protocol.ResponseContentEncoding;
+import org.apache.http.client.protocol.ResponseProcessCookies;
+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.ServiceUnavailableRetryExec;
+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;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.params.SyncBasicHttpParams;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpRequestExecutor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.util.VersionInfo;
+
+/**
+ * {@link HttpClient} builder.
+ * <p>
+ * The following system properties are taken into account by this class
+ *  if the {@link #useSystemProperties()} method is called.
+ * <ul>
+ *  <li>ssl.TrustManagerFactory.algorithm</li>
+ *  <li>javax.net.ssl.trustStoreType</li>
+ *  <li>javax.net.ssl.trustStore</li>
+ *  <li>javax.net.ssl.trustStoreProvider</li>
+ *  <li>javax.net.ssl.trustStorePassword</li>
+ *  <li>java.home</li>
+ *  <li>ssl.KeyManagerFactory.algorithm</li>
+ *  <li>javax.net.ssl.keyStoreType</li>
+ *  <li>javax.net.ssl.keyStore</li>
+ *  <li>javax.net.ssl.keyStoreProvider</li>
+ *  <li>javax.net.ssl.keyStorePassword</li>
+ *  <li>http.proxyHost</li>
+ *  <li>http.proxyPort</li>
+ *  <li>http.nonProxyHosts</li>
+ *  <li>http.keepAlive</li>
+ *  <li>http.maxConnections</li>
+ * </ul>
+ * </p>
+ * <p>
+ * This class sets up the following parameters if not explicitly set:
+ * <ul>
+ * <li>Version: HttpVersion.HTTP_1_1</li>
+ * <li>ContentCharset: HTTP.DEFAULT_CONTENT_CHARSET</li>
+ * <li>NoTcpDelay: true</li>
+ * <li>SocketBufferSize: 8192</li>
+ * <li>UserAgent: Apache-HttpClient/release (java 1.5)</li>
+ * </ul>
+ * <p>
+ * The following parameters can be used to customize the behavior of {@link HttpClient}
+ * produced by this builder:
+ * <ul>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#PROTOCOL_VERSION}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#STRICT_TRANSFER_ENCODING}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#USE_EXPECT_CONTINUE}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#WAIT_FOR_CONTINUE}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#USER_AGENT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_REUSEADDR}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#STALE_CONNECTION_CHECK}</li>
+ *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#FORCED_ROUTE}</li>
+ *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}</li>
+ *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY}</li>
+ *  <li>{@link org.apache.http.cookie.params.CookieSpecPNames#DATE_PATTERNS}</li>
+ *  <li>{@link org.apache.http.cookie.params.CookieSpecPNames#SINGLE_COOKIE_HEADER}</li>
+ *  <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#COOKIE_POLICY}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#HANDLE_AUTHENTICATION}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#HANDLE_REDIRECTS}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#MAX_REDIRECTS}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#ALLOW_CIRCULAR_REDIRECTS}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#VIRTUAL_HOST}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HOST}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HEADERS}</li>
+ *  <li>{@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}</li>
+ * </ul>
+ *
+ * @since 4.3
+ */
+@NotThreadSafe
+public class HttpClientBuilder {
+
+    private HttpRequestExecutor requestExec;
+    private SchemeLayeredSocketFactory sslSocketFactory;
+    private ClientConnectionManager connManager;
+    private ConnectionReuseStrategy reuseStrategy;
+    private ConnectionKeepAliveStrategy keepAliveStrategy;
+    private AuthenticationStrategy targetAuthStrategy;
+    private AuthenticationStrategy proxyAuthStrategy;
+    private UserTokenHandler userTokenHandler;
+
+    private HttpProcessor httpprocessor;
+    private LinkedList<HttpRequestInterceptor> requestFirst;
+    private LinkedList<HttpRequestInterceptor> requestLast;
+    private LinkedList<HttpResponseInterceptor> responseFirst;
+    private LinkedList<HttpResponseInterceptor> responseLast;
+
+    private HttpRequestRetryHandler retryHandler;
+
+    private HttpRoutePlanner routePlanner;
+    private RedirectStrategy redirectStrategy;
+
+    private ConnectionBackoffStrategy connectionBackoffStrategy;
+    private BackoffManager backoffManager;
+
+    private ServiceUnavailableRetryStrategy serviceUnavailStrategy;
+    
+    private HttpParams params;
+
+    private Map<String, AuthSchemeFactory> authShemes;
+    private Map<String, CookieSpecFactory> cookieSpecs;
+    private CookieStore cookieStore;
+    private CredentialsProvider credentialsProvider;
+
+    private boolean systemProperties;
+    private boolean redirectHandlingDisabled;
+    private boolean automaticRetriesDisabled;
+    private boolean contentCompressionDisabled;
+    private boolean cookieManagementDisabled;
+    private boolean authCachingDisabled;
+    private boolean connectionStateDisabled;
+
+    private int maxConnTotal = 0;
+    private int maxConnPerRoute = 0;
+
+    public HttpClientBuilder() {
+        super();
+    }
+
+    public final HttpClientBuilder setRequestExecutor(final HttpRequestExecutor requestExec) {
+        this.requestExec = requestExec;
+        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;
+        return this;
+    }
+
+    public final HttpClientBuilder setKeepAliveStrategy(
+            final ConnectionKeepAliveStrategy keepAliveStrategy) {
+        this.keepAliveStrategy = keepAliveStrategy;
+        return this;
+    }
+
+    public final HttpClientBuilder setUserTokenHandler(final UserTokenHandler userTokenHandler) {
+        this.userTokenHandler = userTokenHandler;
+        return this;
+    }
+
+    public final HttpClientBuilder setTargetAuthenticationStrategy(
+            final AuthenticationStrategy targetAuthStrategy) {
+        this.targetAuthStrategy = targetAuthStrategy;
+        return this;
+    }
+
+    public final HttpClientBuilder setProxyAuthenticationStrategy(
+            final AuthenticationStrategy proxyAuthStrategy) {
+        this.proxyAuthStrategy = proxyAuthStrategy;
+        return this;
+    }
+
+    public final HttpClientBuilder setHttpProcessor(final HttpProcessor httpprocessor) {
+        this.httpprocessor = httpprocessor;
+        return this;
+    }
+
+    public final HttpClientBuilder addInterceptorFirst(final HttpResponseInterceptor itcp) {
+        if (itcp == null) {
+            return this;
+        }
+        if (responseFirst == null) {
+            responseFirst = new LinkedList<HttpResponseInterceptor>();
+        }
+        responseFirst.addFirst(itcp);
+        return this;
+    }
+
+    public final HttpClientBuilder addInterceptorLast(final HttpResponseInterceptor itcp) {
+        if (itcp == null) {
+            return this;
+        }
+        if (responseLast == null) {
+            responseLast = new LinkedList<HttpResponseInterceptor>();
+        }
+        responseLast.addLast(itcp);
+        return this;
+    }
+
+    public final HttpClientBuilder addInterceptorFirst(final HttpRequestInterceptor itcp) {
+        if (itcp == null) {
+            return this;
+        }
+        if (requestFirst == null) {
+            requestFirst = new LinkedList<HttpRequestInterceptor>();
+        }
+        requestFirst.addFirst(itcp);
+        return this;
+    }
+
+    public final HttpClientBuilder addInterceptorLast(final HttpRequestInterceptor itcp) {
+        if (itcp == null) {
+            return this;
+        }
+        if (requestLast == null) {
+            requestLast = new LinkedList<HttpRequestInterceptor>();
+        }
+        requestLast.addLast(itcp);
+        return this;
+    }
+
+    public final HttpClientBuilder setRetryHandler(final HttpRequestRetryHandler retryHandler) {
+        this.retryHandler = retryHandler;
+        return this;
+    }
+
+    public final HttpClientBuilder setRoutePlanner(final HttpRoutePlanner routePlanner) {
+        this.routePlanner = routePlanner;
+        return this;
+    }
+
+    public final HttpClientBuilder setRedirectStrategy(final RedirectStrategy redirectStrategy) {
+        this.redirectStrategy = redirectStrategy;
+        return this;
+    }
+
+    public final HttpClientBuilder setConnectionBackoffStrategy(
+            final ConnectionBackoffStrategy connectionBackoffStrategy) {
+        this.connectionBackoffStrategy = connectionBackoffStrategy;
+        return this;
+    }
+
+    public final HttpClientBuilder setBackoffManager(final BackoffManager backoffManager) {
+        this.backoffManager = backoffManager;
+        return this;
+    }
+    
+    public final HttpClientBuilder setServiceUnavailableRetryStrategy(
+            final ServiceUnavailableRetryStrategy serviceUnavailStrategy) {
+        this.serviceUnavailStrategy = serviceUnavailStrategy;
+        return this;
+    }
+
+    public final HttpClientBuilder setParams(final HttpParams params) {
+        this.params = params;
+        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;
+    }
+
+    public final HttpClientBuilder disableAutomaticRetries() {
+        automaticRetriesDisabled = true;
+        return this;
+    }
+
+    public final HttpClientBuilder disableConnectionState() {
+        connectionStateDisabled = true;
+        return this;
+    }
+
+    public final HttpClientBuilder disableContentCompression() {
+        contentCompressionDisabled = true;
+        return this;
+    }
+
+    public final HttpClientBuilder useSystemProperties() {
+        systemProperties = true;
+        return this;
+    }
+
+    protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
+        return mainExec;
+    }
+
+    protected ClientExecChain decorateProtocolExec(final ClientExecChain protocolExec) {
+        return protocolExec;
+    }
+
+    public HttpClient build() {
+        // Create main request executor
+        HttpRequestExecutor requestExec = this.requestExec;
+        if (requestExec == null) {
+            requestExec = new HttpRequestExecutor();
+        }
+        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(
+                    schemeRegistry);
+            if (systemProperties) {
+                String s = System.getProperty("http.keepAlive");
+                if ("true".equalsIgnoreCase(s)) {
+                    s = System.getProperty("http.maxConnections", "5");
+                    int max = Integer.parseInt(s);
+                    poolingmgr.setDefaultMaxPerRoute(max);
+                    poolingmgr.setMaxTotal(2 * max);
+                }
+            } else {
+                if (maxConnTotal > 0) {
+                    poolingmgr.setMaxTotal(maxConnTotal);
+                }
+                if (maxConnPerRoute > 0) {
+                    poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
+                }
+            }
+            connManager = poolingmgr;
+        }
+        ConnectionReuseStrategy reuseStrategy = this.reuseStrategy;
+        if (reuseStrategy == null) {
+            if (systemProperties) {
+                String s = System.getProperty("http.keepAlive");
+                if ("true".equalsIgnoreCase(s)) {
+                    reuseStrategy = new DefaultConnectionReuseStrategy();
+                } else {
+                    reuseStrategy = new NoConnectionReuseStrategy();
+                }
+            } else {
+                reuseStrategy = new DefaultConnectionReuseStrategy();
+            }
+        }
+        ConnectionKeepAliveStrategy keepAliveStrategy = this.keepAliveStrategy;
+        if (keepAliveStrategy == null) {
+            keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
+        }
+        AuthenticationStrategy targetAuthStrategy = this.targetAuthStrategy;
+        if (targetAuthStrategy == null) {
+            targetAuthStrategy = new TargetAuthenticationStrategy();
+        }
+        AuthenticationStrategy proxyAuthStrategy = this.proxyAuthStrategy;
+        if (proxyAuthStrategy == null) {
+            proxyAuthStrategy = new ProxyAuthenticationStrategy();
+        }
+        UserTokenHandler userTokenHandler = this.userTokenHandler;
+        if (userTokenHandler == null) {
+            if (!connectionStateDisabled) {
+                userTokenHandler = new DefaultUserTokenHandler();
+            } else {
+                userTokenHandler = new NoopUserTokenHandler();
+            }
+        }
+        ClientExecChain execChain = new MainClientExec(
+                requestExec,
+                connManager,
+                reuseStrategy,
+                keepAliveStrategy,
+                targetAuthStrategy,
+                proxyAuthStrategy,
+                userTokenHandler);
+
+        execChain = decorateMainExec(execChain);
+
+        HttpProcessor httpprocessor = this.httpprocessor;
+        if (httpprocessor == null) {
+            ListBuilder<HttpRequestInterceptor> reqlb = new ListBuilder<HttpRequestInterceptor>();
+            reqlb.addAll(requestFirst);
+            reqlb.addAll(
+                    new RequestDefaultHeaders(),
+                    new RequestContent(),
+                    new RequestTargetHost(),
+                    new RequestClientConnControl(),
+                    new RequestUserAgent(),
+                    new RequestExpectContinue());
+            if (!cookieManagementDisabled) {
+                reqlb.add(new RequestAddCookies());
+            }
+            if (!contentCompressionDisabled) {
+                reqlb.add(new RequestAcceptEncoding());
+            }
+            if (!authCachingDisabled) {
+                reqlb.add(new RequestAuthCache());
+            }
+            reqlb.addAll(requestLast);
+
+            ListBuilder<HttpResponseInterceptor> reslb = new ListBuilder<HttpResponseInterceptor>();
+            reslb.addAll(responseFirst);
+            if (!cookieManagementDisabled) {
+                reslb.add(new ResponseProcessCookies());
+            }
+            if (!contentCompressionDisabled) {
+                reslb.add(new ResponseContentEncoding());
+            }
+            reslb.addAll(responseLast);
+            List<HttpRequestInterceptor> reqincps = reqlb.build();
+            List<HttpResponseInterceptor> resincps = reslb.build();
+            httpprocessor = new ImmutableHttpProcessor(
+                    reqincps.toArray(new HttpRequestInterceptor[reqincps.size()]),
+                    resincps.toArray(new HttpResponseInterceptor[resincps.size()]));
+        }
+        execChain = new ProtocolExec(execChain, httpprocessor);
+
+        execChain = decorateProtocolExec(execChain);
+
+        // Add request retry executor, if not disabled
+        if (!automaticRetriesDisabled) {
+            HttpRequestRetryHandler retryHandler = this.retryHandler;
+            if (retryHandler == null) {
+                retryHandler = new DefaultHttpRequestRetryHandler();
+            }
+            execChain = new RetryExec(execChain, retryHandler);
+        }
+
+        // Add redirect executor, if not disabled
+        HttpRoutePlanner routePlanner = this.routePlanner;
+        if (routePlanner == null) {
+            if (systemProperties) {
+                routePlanner = new ProxySelectorRoutePlanner(
+                        connManager.getSchemeRegistry(),
+                        ProxySelector.getDefault());
+            } else {
+                routePlanner = new DefaultHttpRoutePlanner(connManager.getSchemeRegistry());
+            }
+        }
+        if (!redirectHandlingDisabled) {
+            RedirectStrategy redirectStrategy = this.redirectStrategy;
+            if (redirectStrategy == null) {
+                redirectStrategy = new DefaultRedirectStrategy();
+            }
+            execChain = new RedirectExec(execChain, routePlanner, redirectStrategy);
+        }
+
+        // Optionally, add service unavailable retry executor
+        ServiceUnavailableRetryStrategy serviceUnavailStrategy = this.serviceUnavailStrategy;
+        if (serviceUnavailStrategy != null) {
+            execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategy);
+        }
+        // Optionally, add connection back-off executor
+        BackoffManager backoffManager = this.backoffManager;
+        ConnectionBackoffStrategy connectionBackoffStrategy = this.connectionBackoffStrategy;
+        if (backoffManager != null && connectionBackoffStrategy != null) {
+            execChain = new BackoffStrategyExec(execChain, connectionBackoffStrategy, backoffManager);
+        }
+
+        HttpParams params = this.params;
+        if (params == null) {
+            params = new SyncBasicHttpParams();
+            setDefaultHttpParams(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> {
+
+        private final LinkedList<E> list;
+        private final Map<Class<?>, E> uniqueClasses;
+
+        ListBuilder() {
+            this.list = new LinkedList<E>();
+            this.uniqueClasses = new HashMap<Class<?>, E>();
+        }
+
+        public void add(final E e) {
+            if (e == null) {
+                return;
+            }
+            E previous = this.uniqueClasses.remove(e.getClass());
+            if (previous != null) {
+                this.list.remove(previous);
+            }
+            this.list.add(e);
+            this.uniqueClasses.put(e.getClass(), e);
+        }
+
+        public void addAll(final Collection<E> c) {
+            if (c == null) {
+                return;
+            }
+            for (E e: c) {
+                add(e);
+            }
+        }
+
+        public void addAll(E... c) {
+            if (c == null) {
+                return;
+            }
+            for (E e: c) {
+                add(e);
+            }
+        }
+
+        public List<E> build() {
+            return new ArrayList<E>(this.list);
+        }
+
+    }
+
+    /**
+     * Saves the default set of HttpParams in the provided parameter.
+     * These are:
+     * <ul>
+     * <li>{@link CoreProtocolPNames#PROTOCOL_VERSION}: 1.1</li>
+     * <li>{@link CoreProtocolPNames#HTTP_CONTENT_CHARSET}: ISO-8859-1</li>
+     * <li>{@link CoreConnectionPNames#TCP_NODELAY}: true</li>
+     * <li>{@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}: 8192</li>
+     * <li>{@link CoreProtocolPNames#USER_AGENT}: Apache-HttpClient/<release> (java 1.5)</li>
+     * </ul>
+     */
+    public static void setDefaultHttpParams(HttpParams params) {
+        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+        HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
+        HttpConnectionParams.setTcpNoDelay(params, true);
+        HttpConnectionParams.setSocketBufferSize(params, 8192);
+
+        // determine the release version from packaged version info
+        final VersionInfo vi = VersionInfo.loadVersionInfo
+            ("org.apache.http.client", HttpClientBuilder.class.getClassLoader());
+        final String release = (vi != null) ?
+            vi.getRelease() : VersionInfo.UNAVAILABLE;
+        HttpProtocolParams.setUserAgent(params,
+                "Apache-HttpClient/" + release + " (java 1.5)");
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java Wed Aug  8 20:35:13 2012
@@ -0,0 +1,174 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+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.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;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @since 4.3
+ */
+@ThreadSafe
+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) {
+            throw new IllegalArgumentException("HTTP client exec chain may not be null");
+        }
+        if (connManager == null) {
+            throw new IllegalArgumentException("HTTP connection manager may not be null");
+        }
+        if (routePlanner == null) {
+            throw new IllegalArgumentException("HTTP route planner may not be null");
+        }
+        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();
+    }
+
+    private HttpRoute determineRoute(
+            final HttpHost target,
+            final HttpRequest request,
+            final HttpContext context) throws HttpException {
+        HttpHost host = target;
+        if (host == null) {
+            host = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
+        }
+        if (host == null) {
+            throw new IllegalStateException("Target host may not be null");
+        }
+        return this.routePlanner.determineRoute(host, request, 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(
+            final HttpHost target,
+            final HttpRequest request,
+            final HttpContext context) throws IOException, ClientProtocolException {
+        if (request == null) {
+            throw new IllegalArgumentException("Request must not be null.");
+        }
+        HttpExecutionAware execListner = null;
+        if (request instanceof HttpExecutionAware) {
+            execListner = (HttpExecutionAware) request;
+        }
+        try {
+            HttpParams params = new DefaultedHttpParams(request.getParams(), getParams());
+            HttpHost virtualHost = (HttpHost) params.getParameter(ClientPNames.VIRTUAL_HOST);
+
+            HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
+            wrapper.setParams(params);
+            wrapper.setVirtualHost(virtualHost);
+            HttpRoute route = determineRoute(target, wrapper, context);
+            return this.execChain.execute(route, wrapper, setupContext(context), execListner);
+        } catch (HttpException httpException) {
+            throw new ClientProtocolException(httpException);
+        }
+    }
+
+    public HttpParams getParams() {
+        return this.params;
+    }
+
+    public ClientConnectionManager getConnectionManager() {
+        return this.connManager;
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java Wed Aug  8 20:35:13 2012
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ *
+ *  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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.UserTokenHandler;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * Noop implementation of {@link UserTokenHandler} that always returns <code>null</code>.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class NoopUserTokenHandler implements UserTokenHandler {
+
+    public Object getUserToken(final HttpContext context) {
+        return null;
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java Wed Aug  8 20:35:13 2012
@@ -40,6 +40,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
+import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthSchemeRegistry;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthState;
@@ -48,8 +49,6 @@ import org.apache.http.client.params.Aut
 import org.apache.http.client.params.HttpClientParams;
 import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.RequestClientConnControl;
-import org.apache.http.client.protocol.RequestProxyAuthentication;
-import org.apache.http.conn.HttpRoutedConnection;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.BufferedHttpEntity;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
@@ -69,8 +68,6 @@ import org.apache.http.protocol.HttpCont
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.ImmutableHttpProcessor;
-import org.apache.http.protocol.RequestContent;
-import org.apache.http.protocol.RequestTargetHost;
 import org.apache.http.protocol.RequestUserAgent;
 import org.apache.http.util.EntityUtils;
 
@@ -91,11 +88,8 @@ public class ProxyClient {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
         this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
-                new RequestContent(),
-                new RequestTargetHost(),
                 new RequestClientConnControl(),
-                new RequestUserAgent(),
-                new RequestProxyAuthentication()
+                new RequestUserAgent()
         } );
         this.requestExec = new HttpRequestExecutor();
         this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
@@ -131,45 +125,46 @@ public class ProxyClient {
         HttpContext context = new BasicHttpContext();
         HttpResponse response = null;
 
+        String host = target.getHostName();
+        int port = target.getPort();
+        if (port < 0) {
+            port = 80;
+        }
+
+        StringBuilder buffer = new StringBuilder(host.length() + 6);
+        buffer.append(host);
+        buffer.append(':');
+        buffer.append(Integer.toString(port));
+
+        String authority = buffer.toString();
+        ProtocolVersion ver = HttpProtocolParams.getVersion(this.params);
+        HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
+        connect.setParams(this.params);
+
+        BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(new AuthScope(proxy), credentials);
+
+        // Populate the execution context
+        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
+        context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ExecutionContext.HTTP_REQUEST, connect);
+        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
+        context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
+        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
+
+        this.requestExec.preProcess(connect, this.httpProcessor, context);
+
         for (;;) {
             if (!conn.isOpen()) {
                 Socket socket = new Socket(proxy.getHostName(), proxy.getPort());
                 conn.bind(socket, this.params);
             }
-            String host = target.getHostName();
-            int port = target.getPort();
-            if (port < 0) {
-                port = 80;
-            }
 
-            StringBuilder buffer = new StringBuilder(host.length() + 6);
-            buffer.append(host);
-            buffer.append(':');
-            buffer.append(Integer.toString(port));
-
-            String authority = buffer.toString();
-            ProtocolVersion ver = HttpProtocolParams.getVersion(this.params);
-            HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
-            connect.setParams(this.params);
-
-            BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-            credsProvider.setCredentials(new AuthScope(proxy), credentials);
-
-            // Populate the execution context
-            context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
-            context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
-            context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-            context.setAttribute(ExecutionContext.HTTP_REQUEST, connect);
-            context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
-            context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
-            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
-
-            this.requestExec.preProcess(connect, this.httpProcessor, context);
+            this.authenticator.generateAuthResponse(connect, this.proxyAuthState, context);
 
             response = this.requestExec.execute(connect, conn, context);
-
             response.setParams(this.params);
-            this.requestExec.postProcess(response, this.httpProcessor, context);
 
             int status = response.getStatusLine().getStatusCode();
             if (status < 200) {
@@ -180,7 +175,7 @@ public class ProxyClient {
             if (HttpClientParams.isAuthenticating(this.params)) {
                 if (this.authenticator.isAuthenticationRequested(proxy, response,
                         this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                    if (this.authenticator.authenticate(proxy, response,
+                    if (this.authenticator.handleAuthChallenge(proxy, response,
                             this.proxyAuthStrategy, this.proxyAuthState, context)) {
                         // Retry request
                         if (this.reuseStrategy.keepAlive(response, context)) {
@@ -190,6 +185,8 @@ public class ProxyClient {
                         } else {
                             conn.close();
                         }
+                        // discard previous auth header
+                        connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
                     } else {
                         break;
                     }
@@ -216,7 +213,7 @@ public class ProxyClient {
         return conn.getSocket();
     }
 
-    static class ProxyConnection extends DefaultHttpClientConnection implements HttpRoutedConnection {
+    static class ProxyConnection extends DefaultHttpClientConnection {
 
         private final HttpRoute route;
 

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestAbortedException.java (from r1369849, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestAbortedException.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestAbortedException.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java&r1=1369849&r2=1370953&rev=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestAbortedException.java Wed Aug  8 20:35:13 2012
@@ -27,39 +27,29 @@
 
 package org.apache.http.impl.client;
 
-import org.apache.http.annotation.NotThreadSafe;
+import java.io.InterruptedIOException;
 
-import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.annotation.Immutable;
 
 /**
- * A request with the route along which it should be sent.
+ * Signals that the request has been aborted.
  *
- * @since 4.0
+ * @since 4.3
  */
-@NotThreadSafe // RequestWrapper is @NotThreadSafe
-public class RoutedRequest {
+@Immutable
+public class RequestAbortedException extends InterruptedIOException {
 
-    protected final RequestWrapper request; // @NotThreadSafe
-    protected final HttpRoute route; // @Immutable
+    private static final long serialVersionUID = 4973849966012490112L;
 
-    /**
-     * Creates a new routed request.
-     *
-     * @param req   the request
-     * @param route   the route
-     */
-    public RoutedRequest(final RequestWrapper req, final HttpRoute route) {
-        super();
-        this.request = req;
-        this.route   = route;
+    public RequestAbortedException(final String message) {
+        super(message);
     }
 
-    public final RequestWrapper getRequest() {
-        return request;
-    }
-
-    public final HttpRoute getRoute() {
-        return route;
+    public RequestAbortedException(final String message, final Throwable cause) {
+        super(message);
+        if (cause != null) {
+            initCause(cause);
+        }
     }
 
 }

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java Wed Aug  8 20:35:13 2012
@@ -0,0 +1,126 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import java.io.IOException;
+
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpException;
+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.AuthState;
+import org.apache.http.client.AuthenticationStrategy;
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.RedirectStrategy;
+import org.apache.http.client.RequestDirector;
+import org.apache.http.client.UserTokenHandler;
+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.ConnectionKeepAliveStrategy;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.HttpRoutePlanner;
+import org.apache.http.impl.client.exec.ClientExecChain;
+import org.apache.http.impl.client.exec.HttpRequestWrapper;
+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.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpRequestExecutor;
+
+@ThreadSafe
+class RequestDirectorAdaptor implements RequestDirector {
+
+    private final HttpRoutePlanner routePlanner;
+    private final HttpParams params;
+    private final ClientExecChain execChain;
+
+    public RequestDirectorAdaptor(
+            final HttpRequestExecutor requestExecutor,
+            final ClientConnectionManager connman,
+            final ConnectionReuseStrategy reustrat,
+            final ConnectionKeepAliveStrategy kastrat,
+            final HttpRoutePlanner rouplan,
+            final HttpProcessor httpProcessor,
+            final HttpRequestRetryHandler retryHandler,
+            final RedirectStrategy redirectStrategy,
+            final AuthenticationStrategy targetAuthStrategy,
+            final AuthenticationStrategy proxyAuthStrategy,
+            final UserTokenHandler userTokenHandler,
+            final HttpParams params) {
+        this.routePlanner = rouplan;
+        this.params = params;
+        MainClientExec mainExecutor = new MainClientExec(
+                requestExecutor, connman, reustrat, kastrat,
+                targetAuthStrategy, proxyAuthStrategy, userTokenHandler);
+        ProtocolExec protocolFacade = new ProtocolExec(mainExecutor, httpProcessor);
+        RetryExec retryFacade = new RetryExec(protocolFacade, retryHandler);
+        RedirectExec redirectFacade = new RedirectExec(retryFacade, rouplan, redirectStrategy);
+        this.execChain = redirectFacade;
+    }
+
+    public HttpResponse execute(
+            HttpHost target,
+            final HttpRequest request,
+            final HttpContext context) throws HttpException, IOException {
+        if (target == null) {
+            target = (HttpHost) this.params.getParameter(ClientPNames.DEFAULT_HOST);
+        }
+        if (target == null) {
+            throw new IllegalStateException("Target host must not be null, or set in parameters");
+        }
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
+        wrapper.setParams(this.params);
+        HttpHost virtualHost = (HttpHost) this.params.getParameter(ClientPNames.VIRTUAL_HOST);
+        wrapper.setVirtualHost(virtualHost);
+        HttpExecutionAware execListner = null;
+        if (request instanceof HttpExecutionAware) {
+            execListner = (HttpExecutionAware) request;
+            if (execListner.isAborted()) {
+                throw new RequestAbortedException("Request aborted");
+            }
+        }
+        HttpRoute route = this.routePlanner.determineRoute(target, request, context);
+
+        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());
+        }
+
+        return this.execChain.execute(route, wrapper, context, execListner);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestDirectorAdaptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RequestWrapper.java Wed Aug  8 20:35:13 2012
@@ -37,6 +37,7 @@ import org.apache.http.ProtocolException
 import org.apache.http.ProtocolVersion;
 import org.apache.http.RequestLine;
 import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.exec.HttpRequestWrapper;
 import org.apache.http.message.AbstractHttpMessage;
 import org.apache.http.message.BasicRequestLine;
 import org.apache.http.params.HttpProtocolParams;
@@ -49,10 +50,12 @@ import org.apache.http.params.HttpProtoc
  * This class is also capable of resetting the request headers to
  * the state of the original request.
  *
- *
  * @since 4.0
+ * 
+ * @deprecated (4.3) use {@link HttpRequestWrapper}.
  */
 @NotThreadSafe
+@Deprecated 
 public class RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {
 
     private final HttpRequest original;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java Wed Aug  8 20:35:13 2012
@@ -35,7 +35,10 @@ import org.apache.http.conn.routing.Http
  * A request with the route along which it should be sent.
  *
  * @since 4.0
+ * 
+ * @deprecated (4.3) do not use.
  */
+@Deprecated
 @NotThreadSafe // RequestWrapper is @NotThreadSafe
 public class RoutedRequest {
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java?rev=1370953&r1=1370952&r2=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java Wed Aug  8 20:35:13 2012
@@ -101,8 +101,11 @@ import org.apache.http.params.HttpParams
  * </p>
  *
  * @since 4.2
+ * 
+ * @deprecated (4.3) use {@link HttpClientBuilder}
  */
 @ThreadSafe
+@Deprecated
 public class SystemDefaultHttpClient extends DefaultHttpClient {
 
     public SystemDefaultHttpClient(final HttpParams params) {

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java Wed Aug  8 20:35:13 2012
@@ -0,0 +1,107 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client.exec;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.apache.http.HttpException;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.client.BackoffManager;
+import org.apache.http.client.ConnectionBackoffStrategy;
+import org.apache.http.client.methods.HttpExecutionAware;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @since 4.3
+ */
+@ThreadSafe
+public class BackoffStrategyExec implements ClientExecChain {
+
+    private final ClientExecChain requestExecutor;
+    private final ConnectionBackoffStrategy connectionBackoffStrategy;
+    private final BackoffManager backoffManager;
+
+    public BackoffStrategyExec(
+            final ClientExecChain requestExecutor,
+            final ConnectionBackoffStrategy connectionBackoffStrategy,
+            final BackoffManager backoffManager) {
+        super();
+        if (requestExecutor == null) {
+            throw new IllegalArgumentException("HTTP client request executor may not be null");
+        }
+        if (connectionBackoffStrategy == null) {
+            throw new IllegalArgumentException("Connection backoff strategy may not be null");
+        }
+        if (backoffManager == null) {
+            throw new IllegalArgumentException("Backoff manager may not be null");
+        }
+        this.requestExecutor = requestExecutor;
+        this.connectionBackoffStrategy = connectionBackoffStrategy;
+        this.backoffManager = backoffManager;
+    }
+
+    public HttpResponseWrapper execute(
+            final HttpRoute route,
+            final HttpRequestWrapper request,
+            final HttpContext context,
+            final HttpExecutionAware execAware) throws IOException, HttpException {
+        if (route == null) {
+            throw new IllegalArgumentException("HTTP route may not be null");
+        }
+        if (request == null) {
+            throw new IllegalArgumentException("HTTP request may not be null");
+        }
+        if (context == null) {
+            throw new IllegalArgumentException("HTTP context may not be null");
+        }
+        HttpResponseWrapper out = null;
+        try {
+            out = this.requestExecutor.execute(route, request, context, execAware);
+        } catch (Exception ex) {
+            if (out != null) {
+                out.close();
+            }
+            if (this.connectionBackoffStrategy.shouldBackoff(ex)) {
+                this.backoffManager.backOff(route);
+            }
+            if (ex instanceof RuntimeException) throw (RuntimeException) ex;
+            if (ex instanceof HttpException) throw (HttpException) ex;
+            if (ex instanceof IOException) throw (IOException) ex;
+            throw new UndeclaredThrowableException(ex);
+        }
+        if (this.connectionBackoffStrategy.shouldBackoff(out)) {
+            this.backoffManager.backOff(route);
+        } else {
+            this.backoffManager.probe(route);
+        }
+        return out;
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/BackoffStrategyExec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ClientExecChain.java (from r1369849, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ClientExecChain.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ClientExecChain.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java&r1=1369849&r2=1370953&rev=1370953&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/RoutedRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/ClientExecChain.java Wed Aug  8 20:35:13 2012
@@ -25,41 +25,34 @@
  *
  */
 
-package org.apache.http.impl.client;
+package org.apache.http.impl.client.exec;
 
-import org.apache.http.annotation.NotThreadSafe;
+import java.io.IOException;
 
+import org.apache.http.HttpException;
+import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.protocol.HttpContext;
 
 /**
- * A request with the route along which it should be sent.
+ * This interface represents an element in the HTTP request execution chain. Each element can
+ * either be a decorator around another element that implements a cross cutting aspect or
+ * a self-contained executor capable of producing a response for the given request.
+ * <p/>
+ * Important: please note it is required for decorators that implement post execution aspects
+ * or response post-processing of any sort to release resources associated with the response
+ * by calling {@link HttpResponseWrapper#releaseConnection()} or {@link HttpResponseWrapper#close()}
+ * methods in case of an I/O, protocol or runtime exception, or in case the response is not
+ * propagated to the caller.
  *
- * @since 4.0
+ * @since 4.3
  */
-@NotThreadSafe // RequestWrapper is @NotThreadSafe
-public class RoutedRequest {
+public interface ClientExecChain {
 
-    protected final RequestWrapper request; // @NotThreadSafe
-    protected final HttpRoute route; // @Immutable
-
-    /**
-     * Creates a new routed request.
-     *
-     * @param req   the request
-     * @param route   the route
-     */
-    public RoutedRequest(final RequestWrapper req, final HttpRoute route) {
-        super();
-        this.request = req;
-        this.route   = route;
-    }
-
-    public final RequestWrapper getRequest() {
-        return request;
-    }
-
-    public final HttpRoute getRoute() {
-        return route;
-    }
+    HttpResponseWrapper execute(
+            HttpRoute route,
+            HttpRequestWrapper request,
+            HttpContext context,
+            HttpExecutionAware execAware) throws IOException, HttpException;
 
 }

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java?rev=1370953&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java Wed Aug  8 20:35:13 2012
@@ -0,0 +1,229 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client.exec;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.http.annotation.NotThreadSafe;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.RequestLine;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.message.AbstractHttpMessage;
+import org.apache.http.message.BasicRequestLine;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HTTP;
+
+/**
+ * A wrapper class for {@link HttpRequest} that can be used to change properties of the current
+ * request without modifying the original object.
+ *
+ * @since 4.3
+ */
+@NotThreadSafe
+public class HttpRequestWrapper extends AbstractHttpMessage implements HttpRequest {
+
+    private final HttpRequest original;
+
+    private URI uri;
+    private String method;
+    private ProtocolVersion version;
+    private HttpHost virtualHost;
+
+    private HttpRequestWrapper(
+            final ProtocolVersion version,
+            final URI uri,
+            final String method,
+            final HttpRequest request) {
+        super();
+        this.original = request;
+        this.uri = uri;
+        this.method = method;
+        this.version = version;
+        setParams(request.getParams());
+        setHeaders(request.getAllHeaders());
+    }
+
+    public ProtocolVersion getProtocolVersion() {
+        if (this.version != null) {
+            return this.version;
+        } else {
+            return HttpProtocolParams.getVersion(getParams());
+        }
+    }
+
+    public void setProtocolVersion(final ProtocolVersion version) {
+        this.version = version;
+    }
+
+    public URI getURI() {
+        return this.uri;
+    }
+
+    public void setURI(final URI uri) {
+        this.uri = uri;
+    }
+
+    public RequestLine getRequestLine() {
+        String uritext = null;
+        if (this.uri != null) {
+            uritext = uri.toASCIIString();
+        }
+        if (uritext == null || uritext.length() == 0) {
+            uritext = "/";
+        }
+        return new BasicRequestLine(this.method, uritext, getProtocolVersion());
+    }
+
+    public String getMethod() {
+        return this.method;
+    }
+
+    public HttpRequest getOriginal() {
+        return this.original;
+    }
+
+    public HttpHost getVirtualHost() {
+        return this.virtualHost;
+    }
+
+    public void setVirtualHost(final HttpHost virtualHost) {
+        this.virtualHost = virtualHost;
+    }
+
+    public boolean isRepeatable() {
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return this.method + " " + this.uri + " " + this.headergroup;
+    }
+
+    static class HttpEntityEnclosingRequestWrapper extends HttpRequestWrapper
+        implements HttpEntityEnclosingRequest {
+
+        private HttpEntity entity;
+        private boolean consumed;
+
+        public HttpEntityEnclosingRequestWrapper(
+                final ProtocolVersion version,
+                final URI uri,
+                final String method,
+                final HttpEntityEnclosingRequest request)
+            throws ProtocolException {
+            super(version, uri, method, request);
+            setEntity(request.getEntity());
+        }
+
+        public HttpEntity getEntity() {
+            return this.entity;
+        }
+
+        public void setEntity(final HttpEntity entity) {
+            this.entity = entity != null ? new EntityWrapper(entity) : null;
+        }
+
+        public boolean expectContinue() {
+            Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+            return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
+        }
+
+        @Override
+        public boolean isRepeatable() {
+            return this.entity == null || this.entity.isRepeatable() || !this.consumed;
+        }
+
+        class EntityWrapper extends HttpEntityWrapper {
+
+            EntityWrapper(final HttpEntity entity) {
+                super(entity);
+            }
+
+            @Deprecated
+            @Override
+            public void consumeContent() throws IOException {
+                consumed = true;
+                super.consumeContent();
+            }
+
+            @Override
+            public InputStream getContent() throws IOException {
+                return super.getContent();
+            }
+
+            @Override
+            public void writeTo(final OutputStream outstream) throws IOException {
+                consumed = true;
+                super.writeTo(outstream);
+            }
+        }
+
+    }
+
+    public static HttpRequestWrapper wrap(final HttpRequest request) throws ProtocolException {
+        if (request == null) {
+            return null;
+        }
+        ProtocolVersion version;
+        URI uri;
+        String method;
+        if (request instanceof HttpUriRequest) {
+            version = ((HttpUriRequest) request).getProtocolVersion();
+            uri = ((HttpUriRequest) request).getURI();
+            method = ((HttpUriRequest) request).getMethod();
+        } else {
+            RequestLine requestLine = request.getRequestLine();
+            version = request.getProtocolVersion();
+            try {
+                uri = new URI(requestLine.getUri());
+            } catch (URISyntaxException ex) {
+                throw new ProtocolException("Invalid request URI: " + requestLine.getUri(), ex);
+            }
+            method = request.getRequestLine().getMethod();
+        }
+        if (request instanceof HttpEntityEnclosingRequest) {
+            return new HttpEntityEnclosingRequestWrapper(version, uri, method,
+                    (HttpEntityEnclosingRequest) request);
+        } else {
+            return new HttpRequestWrapper(version, uri, method, request);
+        }
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/exec/HttpRequestWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message