hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1414682 - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/examples/org/apache/http/examples/client/ httpclient/src/main/java/org/apache/http/client/params/ httpclient/src/main/java...
Date Wed, 28 Nov 2012 13:46:10 GMT
Author: olegk
Date: Wed Nov 28 13:46:07 2012
New Revision: 1414682

URL: http://svn.apache.org/viewvc?rev=1414682&view=rev
Log:
Deprecated HttpParams and related classes in favor of new configuration API (fixed remaining
deprecation warnings)

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpClientParamConfig.java
  (contents, props changed)
      - copied, changed from r1414680, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java
Removed:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java
Modified:
    httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
    httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultRoutePlanner.java

Modified: httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
(original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
Wed Nov 28 13:46:07 2012
@@ -33,9 +33,10 @@ import java.security.NoSuchAlgorithmExce
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.HttpHost;
+import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.ChallengeState;
 import org.apache.http.auth.Credentials;
+import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.auth.NTCredentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
@@ -57,6 +58,7 @@ import org.apache.http.impl.client.Basic
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.builder.HttpClientBuilder;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.BasicHttpContext;
 
 /**
@@ -133,12 +135,22 @@ public class Executor {
     }
 
     public Executor authPreemptive(final HttpHost host) {
-        this.authCache.put(host, new BasicScheme(ChallengeState.TARGET));
+        BasicScheme basicScheme = new BasicScheme();
+        try {
+            basicScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "BASIC "));
+        } catch (MalformedChallengeException ingnore) {
+        }
+        this.authCache.put(host, basicScheme);
         return this;
     }
 
     public Executor authPreemptiveProxy(final HttpHost host) {
-        this.authCache.put(host, new BasicScheme(ChallengeState.PROXY));
+        BasicScheme basicScheme = new BasicScheme();
+        try {
+            basicScheme.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC "));
+        } catch (MalformedChallengeException ingnore) {
+        }
+        this.authCache.put(host, basicScheme);
         return this;
     }
 

Modified: httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
(original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
Wed Nov 28 13:46:07 2012
@@ -53,6 +53,7 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.client.methods.HttpTrace;
+import org.apache.http.client.params.HttpClientParamConfig;
 import org.apache.http.conn.params.ConnRoutePNames;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.ContentType;
@@ -64,6 +65,7 @@ import org.apache.http.params.CoreProtoc
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
 
+@SuppressWarnings("deprecation")
 public class Request {
 
     public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
@@ -142,6 +144,7 @@ public class Request {
     }
 
     public Response execute() throws ClientProtocolException, IOException {
+        this.request.setConfig(HttpClientParamConfig.getRequestConfig(this.localParams));
         return new Response(Executor.CLIENT.execute(this.request));
     }
 
@@ -204,13 +207,19 @@ public class Request {
         return this;
     }
 
-    //// HTTP config parameter operations
-
+    /**
+     * @deprecated (4.3)
+     */
+    @Deprecated
     public Request config(final String param, final Object object) {
         this.localParams.setParameter(param, object);
         return this;
     }
 
+    /**
+     * @deprecated (4.3)
+     */
+    @Deprecated
     public Request removeConfig(final String param) {
         this.localParams.removeParameter(param);
         return this;
@@ -219,7 +228,8 @@ public class Request {
     //// HTTP protocol parameter operations
 
     public Request version(final HttpVersion version) {
-        return config(CoreProtocolPNames.PROTOCOL_VERSION, version);
+        this.request.setProtocolVersion(version);
+        return this;
     }
 
     public Request elementCharset(final String charset) {
@@ -231,7 +241,8 @@ public class Request {
     }
 
     public Request userAgent(final String agent) {
-        return config(CoreProtocolPNames.USER_AGENT, agent);
+        this.request.setHeader(HTTP.USER_AGENT, agent);
+        return this;
     }
 
     //// HTTP connection parameter operations

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
Wed Nov 28 13:46:07 2012
@@ -32,7 +32,6 @@ import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
-import java.net.UnknownHostException;
 
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -40,16 +39,15 @@ import org.apache.http.HttpHost;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
 import org.apache.http.conn.ConnectTimeoutException;
-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.conn.socket.ConnectionSocketFactory;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.impl.conn.SchemeRegistryFactory;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
 
 /**
@@ -60,18 +58,20 @@ import org.apache.http.util.EntityUtils;
 public class ClientExecuteSOCKS {
 
     public static void main(String[] args)throws Exception {
-        SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
-        schemeRegistry.register(new Scheme("http", 80, new MySchemeSocketFactory()));
-        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
+        Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
+            .register("http", new MyConnectionSocketFactory())
+            .build();
+        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg);
         CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();
         try {
-            httpclient.getParams().setParameter("socks.host", "mysockshost");
-            httpclient.getParams().setParameter("socks.port", 1234);
+            InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234);
+            HttpClientContext context = HttpClientContext.create();
+            context.setAttribute("socks.address", socksaddr);
 
             HttpHost target = new HttpHost("www.apache.org", 80, "http");
             HttpGet request = new HttpGet("/");
 
-            System.out.println("executing request to " + target + " via SOCKS proxy");
+            System.out.println("executing request to " + target + " via SOCKS proxy " + socksaddr);
             CloseableHttpResponse response = httpclient.execute(target, request);
             try {
                 HttpEntity entity = response.getEntity();
@@ -95,45 +95,32 @@ public class ClientExecuteSOCKS {
         }
     }
 
-    static class MySchemeSocketFactory implements SchemeSocketFactory {
+    static class MyConnectionSocketFactory implements ConnectionSocketFactory {
 
-        public Socket createSocket(final HttpParams params) throws IOException {
-            if (params == null) {
-                throw new IllegalArgumentException("HTTP parameters may not be null");
-            }
-            String proxyHost = (String) params.getParameter("socks.host");
-            Integer proxyPort = (Integer) params.getParameter("socks.port");
-
-            InetSocketAddress socksaddr = new InetSocketAddress(proxyHost, proxyPort.intValue());
+        public Socket createSocket(final HttpContext context) throws IOException {
+            InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socks.address");
             Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr);
             return new Socket(proxy);
         }
 
         public Socket connectSocket(
+                final int connectTimeout,
                 final Socket socket,
+                final HttpHost host,
                 final InetSocketAddress remoteAddress,
                 final InetSocketAddress localAddress,
-                final HttpParams params)
-                    throws IOException, UnknownHostException, ConnectTimeoutException {
-            if (remoteAddress == null) {
-                throw new IllegalArgumentException("Remote address may not be null");
-            }
-            if (params == null) {
-                throw new IllegalArgumentException("HTTP parameters may not be null");
-            }
+                final HttpContext context) throws IOException, ConnectTimeoutException {
             Socket sock;
             if (socket != null) {
                 sock = socket;
             } else {
-                sock = createSocket(params);
+                sock = createSocket(context);
             }
             if (localAddress != null) {
-                sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
                 sock.bind(localAddress);
             }
-            int timeout = HttpConnectionParams.getConnectionTimeout(params);
             try {
-                sock.connect(remoteAddress, timeout);
+                sock.connect(remoteAddress, connectTimeout);
             } catch (SocketTimeoutException ex) {
                 throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName()
+ "/"
                         + remoteAddress.getAddress() + " timed out");
@@ -141,10 +128,6 @@ public class ClientExecuteSOCKS {
             return sock;
         }
 
-        public boolean isSecure(final Socket sock) throws IllegalArgumentException {
-            return false;
-        }
-
     }
 
 }
\ No newline at end of file

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpClientParamConfig.java
(from r1414680, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpClientParamConfig.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpClientParamConfig.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java&r1=1414680&r2=1414682&rev=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpClientParamConfig.java
Wed Nov 28 13:46:07 2012
@@ -42,9 +42,9 @@ import org.apache.http.params.HttpProtoc
  * @since 4.3
  */
 @Deprecated
-public final class HttpParamConfig {
+public final class HttpClientParamConfig {
 
-    private HttpParamConfig() {
+    private HttpClientParamConfig() {
     }
 
     @SuppressWarnings("unchecked")

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

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

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/params/HttpClientParamConfig.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=1414682&r1=1414681&r2=1414682&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 Nov 28 13:46:07 2012
@@ -30,8 +30,6 @@ package org.apache.http.impl.client;
 import java.io.IOException;
 import java.net.Socket;
 
-import javax.net.ssl.SSLSession;
-
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
@@ -39,29 +37,35 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolVersion;
+import org.apache.http.HttpVersion;
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthSchemeRegistry;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthState;
 import org.apache.http.auth.Credentials;
-import org.apache.http.client.params.AuthPolicy;
-import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.params.HttpClientParamConfig;
 import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.RequestClientConnControl;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.conn.HttpConnectionFactory;
+import org.apache.http.conn.SocketClientConnection;
 import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.RouteInfo.LayerType;
+import org.apache.http.conn.routing.RouteInfo.TunnelType;
 import org.apache.http.entity.BufferedHttpEntity;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpClientConnection;
 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.conn.DefaultClientConnectionFactory;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParamConfig;
 import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
@@ -69,10 +73,15 @@ import org.apache.http.protocol.HttpProc
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.ImmutableHttpProcessor;
 import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.util.Args;
 import org.apache.http.util.EntityUtils;
 
+@SuppressWarnings("deprecation")
 public class ProxyClient {
 
+    private final HttpConnectionFactory<SocketClientConnection> connFactory;
+    private final ConnectionConfig connectionConfig;
+    private final RequestConfig requestConfig;
     private final HttpProcessor httpProcessor;
     private final HttpRequestExecutor requestExec;
     private final ProxyAuthenticationStrategy proxyAuthStrategy;
@@ -80,13 +89,18 @@ public class ProxyClient {
     private final AuthState proxyAuthState;
     private final AuthSchemeRegistry authSchemeRegistry;
     private final ConnectionReuseStrategy reuseStrategy;
-    private final HttpParams params;
 
-    public ProxyClient(final HttpParams params) {
+    /**
+     * @since 4.3
+     */
+    public ProxyClient(
+            final HttpConnectionFactory<SocketClientConnection> connFactory,
+            final ConnectionConfig connectionConfig,
+            final RequestConfig requestConfig) {
         super();
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
+        this.connFactory = connFactory != null ? connFactory : DefaultClientConnectionFactory.INSTANCE;
+        this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
+        this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
         this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
                 new RequestClientConnControl(),
                 new RequestUserAgent()
@@ -96,23 +110,41 @@ public class ProxyClient {
         this.authenticator = new HttpAuthenticator();
         this.proxyAuthState = new AuthState();
         this.authSchemeRegistry = new AuthSchemeRegistry();
-        this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
-        this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
-        this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
-        this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
-        this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
+        this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
+        this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
+        this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
+        this.authSchemeRegistry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
+        this.authSchemeRegistry.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory());
         this.reuseStrategy = new DefaultConnectionReuseStrategy();
-        this.params = params;
+    }
+
+    /**
+     * @deprecated (4.3) use {@link ProxyClient#ProxyClient(RequestConfig)}
+     * @param params
+     */
+    @Deprecated
+    public ProxyClient(final HttpParams params) {
+        this(null,
+                HttpParamConfig.getConnectionConfig(params),
+                HttpClientParamConfig.getRequestConfig(params));
     }
 
     public ProxyClient() {
-        this(new BasicHttpParams());
+        this(null, null, null);
     }
 
+    /**
+     * @deprecated (4.3) do not use.
+     */
+    @Deprecated
     public HttpParams getParams() {
-        return this.params;
+        return new BasicHttpParams();
     }
 
+    /**
+     * @deprecated (4.3) do not use.
+     */
+    @Deprecated
     public AuthSchemeRegistry getAuthSchemeRegistry() {
         return this.authSchemeRegistry;
     }
@@ -121,78 +153,74 @@ public class ProxyClient {
             final HttpHost proxy,
             final HttpHost target,
             final Credentials credentials) throws IOException, HttpException {
-        ProxyConnection conn = new ProxyConnection(new HttpRoute(proxy));
+        Args.notNull(proxy, "Proxy host");
+        Args.notNull(target, "Target host");
+        Args.notNull(credentials, "Credentials");
+        HttpHost host = target;
+        if (host.getPort() <= 0) {
+            host = new HttpHost(host.getHostName(), 80, host.getSchemeName());
+        }
+        HttpRoute route = new HttpRoute(
+                host,
+                this.requestConfig.getLocalAddress(),
+                proxy, false, TunnelType.TUNNELLED, LayerType.PLAIN);
+
+        SocketClientConnection conn = this.connFactory.create(this.connectionConfig);
         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);
+        HttpRequest connect = new BasicHttpRequest(
+                "CONNECT", host.toHostString(), HttpVersion.HTTP_1_1);
 
         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.ROUTE, route);
         context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
         context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
         context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
+        context.setAttribute(ClientContext.REQUEST_CONFIG, this.requestConfig);
 
         this.requestExec.preProcess(connect, this.httpProcessor, context);
 
         for (;;) {
             if (!conn.isOpen()) {
                 Socket socket = new Socket(proxy.getHostName(), proxy.getPort());
-                conn.bind(socket, this.params);
+                conn.bind(socket);
             }
 
             this.authenticator.generateAuthResponse(connect, this.proxyAuthState, context);
 
             response = this.requestExec.execute(connect, conn, context);
-            response.setParams(this.params);
 
             int status = response.getStatusLine().getStatusCode();
             if (status < 200) {
                 throw new HttpException("Unexpected response to CONNECT request: " +
                         response.getStatusLine());
             }
-
-            if (HttpClientParams.isAuthenticating(this.params)) {
-                if (this.authenticator.isAuthenticationRequested(proxy, response,
+            if (this.authenticator.isAuthenticationRequested(proxy, response,
+                    this.proxyAuthStrategy, this.proxyAuthState, context)) {
+                if (this.authenticator.handleAuthChallenge(proxy, response,
                         this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                    if (this.authenticator.handleAuthChallenge(proxy, response,
-                            this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                        // Retry request
-                        if (this.reuseStrategy.keepAlive(response, context)) {
-                            // Consume response content
-                            HttpEntity entity = response.getEntity();
-                            EntityUtils.consume(entity);
-                        } else {
-                            conn.close();
-                        }
-                        // discard previous auth header
-                        connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
+                    // Retry request
+                    if (this.reuseStrategy.keepAlive(response, context)) {
+                        // Consume response content
+                        HttpEntity entity = response.getEntity();
+                        EntityUtils.consume(entity);
                     } else {
-                        break;
+                        conn.close();
                     }
+                    // discard previous auth header
+                    connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
                 } else {
                     break;
                 }
+            } else {
+                break;
             }
         }
 
@@ -213,32 +241,4 @@ public class ProxyClient {
         return conn.getSocket();
     }
 
-    static class ProxyConnection extends DefaultHttpClientConnection {
-
-        private final HttpRoute route;
-
-        ProxyConnection(final HttpRoute route) {
-            super();
-            this.route = route;
-        }
-
-        public HttpRoute getRoute() {
-            return this.route;
-        }
-
-        public boolean isSecure() {
-            return false;
-        }
-
-        public SSLSession getSSLSession() {
-            return null;
-        }
-
-        @Override
-        public Socket getSocket() {
-            return super.getSocket();
-        }
-
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
Wed Nov 28 13:46:07 2012
@@ -31,7 +31,7 @@ import java.io.IOException;
 import java.lang.reflect.UndeclaredThrowableException;
 
 import org.apache.http.HttpException;
-import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.client.BackoffManager;
 import org.apache.http.client.ConnectionBackoffStrategy;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -42,7 +42,7 @@ import org.apache.http.conn.routing.Http
 /**
  * @since 4.3
  */
-@ThreadSafe
+@Immutable
 class BackoffStrategyExec implements ClientExecChain {
 
     private final ClientExecChain requestExecutor;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
Wed Nov 28 13:46:07 2012
@@ -34,7 +34,6 @@ import org.apache.http.annotation.NotThr
 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;
@@ -56,7 +55,6 @@ class HttpRequestWrapper extends Abstrac
     private final HttpRequest original;
 
     private URI uri;
-    private HttpHost virtualHost;
 
     private HttpRequestWrapper(final HttpRequest request) {
         super();
@@ -100,14 +98,6 @@ class HttpRequestWrapper extends Abstrac
         return this.original;
     }
 
-    public HttpHost getVirtualHost() {
-        return this.virtualHost;
-    }
-
-    public void setVirtualHost(final HttpHost virtualHost) {
-        this.virtualHost = virtualHost;
-    }
-
     public boolean isRepeatable() {
         return true;
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
Wed Nov 28 13:46:07 2012
@@ -44,7 +44,7 @@ import org.apache.http.client.methods.Cl
 import org.apache.http.client.methods.Configurable;
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.params.ClientPNames;
-import org.apache.http.client.params.HttpParamConfig;
+import org.apache.http.client.params.HttpClientParamConfig;
 import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.config.Lookup;
@@ -105,7 +105,7 @@ class InternalHttpClient extends Closeab
         this.authSchemeRegistry = authSchemeRegistry;
         this.cookieStore = cookieStore;
         this.credentialsProvider = credentialsProvider;
-        this.defaultConfig = defaultConfig != null ? defaultConfig : RequestConfig.DEFAULT;
+        this.defaultConfig = defaultConfig;
         this.params = new BasicHttpParams();
     }
 
@@ -160,22 +160,19 @@ class InternalHttpClient extends Closeab
             execListner = (HttpExecutionAware) request;
         }
         try {
-            HttpParams params = request.getParams();
-            HttpHost virtualHost = (HttpHost) params.getParameter(ClientPNames.VIRTUAL_HOST);
-
             HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
-            wrapper.setVirtualHost(virtualHost);
             HttpClientContext localcontext = setupContext(context);
             HttpRoute route = determineRoute(target, wrapper, localcontext);
             RequestConfig config = null;
             if (request instanceof Configurable) {
                 config = ((Configurable) request).getConfig();
-            } else {
-                config = HttpParamConfig.getRequestConfig(params);
             }
             if (config == null) {
                 config = this.defaultConfig;
             }
+            if (config == null) {
+                config = HttpClientParamConfig.getRequestConfig(params);
+            }
             localcontext.setRequestConfig(config);
             return this.execChain.execute(route, wrapper, localcontext, execListner);
         } catch (HttpException httpException) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
Wed Nov 28 13:46:07 2012
@@ -41,7 +41,7 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
-import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthProtocolState;
 import org.apache.http.auth.AuthState;
@@ -77,7 +77,7 @@ import org.apache.http.util.EntityUtils;
 /**
  * @since 4.3
  */
-@ThreadSafe
+@Immutable
 class MainClientExec implements ClientExecChain {
 
     private final Log log = LogFactory.getLog(getClass());

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
Wed Nov 28 13:46:07 2012
@@ -36,23 +36,26 @@ import org.apache.commons.logging.LogFac
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.ProtocolException;
-import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.auth.AuthState;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.methods.CloseableHttpResponse;
 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.client.protocol.HttpClientContext;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpProcessor;
 
 /**
  * @since 4.3
  */
-@ThreadSafe
+@Immutable
+@SuppressWarnings("deprecation")
 class ProtocolExec implements ClientExecChain {
 
     private final Log log = LogFactory.getLog(getClass());
@@ -133,7 +136,8 @@ class ProtocolExec implements ClientExec
         // Re-write request URI if needed
         rewriteRequestURI(request, route);
 
-        HttpHost virtualHost = request.getVirtualHost();
+        HttpParams params = request.getParams();
+        HttpHost virtualHost = (HttpHost) params.getParameter(ClientPNames.VIRTUAL_HOST);
         // HTTPCLIENT-1092 - add the port if necessary
         if (virtualHost != null && virtualHost.getPort() == -1) {
             int port = target.getPort();

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
Wed Nov 28 13:46:07 2012
@@ -139,7 +139,6 @@ class RedirectExec implements ClientExec
                                 proxyAuthState.reset();
                             }
                         }
-                        request.setVirtualHost(null);
                     }
 
                     currentRoute = this.routePlanner.determineRoute(newTarget, currentRequest,
context);

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
Wed Nov 28 13:46:07 2012
@@ -34,7 +34,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.http.Header;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
-import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -46,7 +46,7 @@ import org.apache.http.conn.routing.Http
 /**
  * @since 4.3
  */
-@NotThreadSafe // e.g. managedConn
+@Immutable
 class RetryExec implements ClientExecChain {
 
     private final Log log = LogFactory.getLog(getClass());

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
Wed Nov 28 13:46:07 2012
@@ -33,7 +33,7 @@ import java.io.InterruptedIOException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpException;
-import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.client.ServiceUnavailableRetryStrategy;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpExecutionAware;
@@ -46,7 +46,7 @@ import org.apache.http.conn.routing.Http
  *
  * @since 4.3
  */
-@ThreadSafe
+@Immutable
 class ServiceUnavailableRetryExec implements ClientExecChain {
 
     private final Log log = LogFactory.getLog(getClass());

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java
Wed Nov 28 13:46:07 2012
@@ -37,7 +37,6 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.protocol.HttpContext;
 
-import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.routing.HttpRoutePlanner;
 import org.apache.http.conn.scheme.Scheme;
@@ -83,15 +82,6 @@ public class DefaultHttpRoutePlanner imp
         schemeRegistry = schreg;
     }
 
-    private SchemeRegistry getSchemeRegistry(final HttpContext context) {
-        SchemeRegistry reg = (SchemeRegistry) context.getAttribute(
-                ClientContext.SCHEME_REGISTRY);
-        if (reg == null) {
-            reg = this.schemeRegistry;
-        }
-        return reg;
-    }
-    
     public HttpRoute determineRoute(HttpHost target,
                                     HttpRequest request,
                                     HttpContext context)
@@ -123,8 +113,7 @@ public class DefaultHttpRoutePlanner imp
 
         final Scheme schm;
         try {
-            SchemeRegistry registry = getSchemeRegistry(context);
-            schm = registry.getScheme(target.getSchemeName());
+            schm = this.schemeRegistry.getScheme(target.getSchemeName());
         } catch (IllegalStateException ex) {
             throw new HttpException(ex.getMessage());
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
Wed Nov 28 13:46:07 2012
@@ -36,6 +36,7 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.conn.SchemePortResolver;
+import org.apache.http.conn.params.ConnRouteParams;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.conn.routing.HttpRoutePlanner;
 import org.apache.http.protocol.HttpContext;
@@ -49,6 +50,7 @@ import org.apache.http.protocol.HttpCont
  * @since 4.3
  */
 @Immutable
+@SuppressWarnings("deprecation")
 public class DefaultRoutePlanner implements HttpRoutePlanner {
 
     private final SchemePortResolver schemePortResolver;
@@ -69,6 +71,13 @@ public class DefaultRoutePlanner impleme
         if (request == null) {
             throw new IllegalArgumentException("Request may not be null");
         }
+
+        // If we have a forced route, we can do without a target.
+        HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
+        if (route != null) {
+            return route;
+        }
+
         HttpClientContext clientContext = HttpClientContext.adapt(context);
         RequestConfig config = clientContext.getRequestConfig();
         InetAddress local = config.getLocalAddress();

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultRoutePlanner.java?rev=1414682&r1=1414681&r2=1414682&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultRoutePlanner.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/SystemDefaultRoutePlanner.java
Wed Nov 28 13:46:07 2012
@@ -50,13 +50,6 @@ import org.apache.http.protocol.HttpCont
  * {@link org.apache.http.conn.params.ConnRoutePNames parameters},
  * though not the {@link
  * org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}.
- * <p>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}</li>
- *  <li>{@link org.apache.http.conn.params.ConnRoutePNames#FORCED_ROUTE}</li>
- * </ul>
  *
  * @since 4.3
  */



Mime
View raw message