hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1350257 - in /httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src: main/java/org/apache/http/client/protocol/ main/java/org/apache/http/impl/client/ test/java/org/apache/http/client/protocol/
Date Thu, 14 Jun 2012 14:19:41 GMT
Author: olegk
Date: Thu Jun 14 14:19:41 2012
New Revision: 1350257

URL: http://svn.apache.org/viewvc?rev=1350257&view=rev
Log:
RequestAddCookies and RequestClientConnControl protocol interceptors no longer rely on presence
of HTTP connection in the context to generate request headers; actual route info is used instead

Modified:
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java?rev=1350257&r1=1350256&r2=1350257&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
Thu Jun 14 14:19:41 2012
@@ -36,10 +36,19 @@ package org.apache.http.client.protocol;
 public interface ClientContext {
 
     /**
+     * Attribute name of a {@link org.apache.http.conn.routing.RouteInfo}
+     * object that represents the actual connection route.
+     *
+     * @since 4.3
+     */
+    public static final String ROUTE   = "http.route";
+
+    /**
      * Attribute name of a {@link org.apache.http.conn.scheme.Scheme}
      * object that represents the actual protocol scheme registry.
      */
     public static final String SCHEME_REGISTRY   = "http.scheme-registry";
+
     /**
      * Attribute name of a {@link org.apache.http.cookie.CookieSpecRegistry}
      * object that represents the actual cookie specification registry.

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=1350257&r1=1350256&r2=1350257&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
Thu Jun 14 14:19:41 2012
@@ -47,8 +47,9 @@ import org.apache.http.ProtocolException
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.params.HttpClientParams;
-import org.apache.http.conn.HttpRoutedConnection;
-import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.RouteInfo;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.cookie.Cookie;
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.CookieSpec;
@@ -111,7 +112,7 @@ public class RequestAddCookies implement
             return;
         }
 
-        // Obtain the target host (required)
+        // Obtain the target host, possibly virtual (required)
         HttpHost targetHost = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
         if (targetHost == null) {
@@ -119,11 +120,10 @@ public class RequestAddCookies implement
             return;
         }
 
-        // Obtain the client connection (required)
-        HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
-                ExecutionContext.HTTP_CONNECTION);
-        if (conn == null) {
-            this.log.debug("HTTP connection not set in the context");
+        // Obtain the route (required)
+        RouteInfo route = (RouteInfo) context.getAttribute(ClientContext.ROUTE);
+        if (route == null) {
+            this.log.debug("Connection route not set in the context");
             return;
         }
 
@@ -147,9 +147,13 @@ public class RequestAddCookies implement
         String hostName = targetHost.getHostName();
         int port = targetHost.getPort();
         if (port < 0) {
-            HttpRoute route = conn.getRoute();
             if (route.getHopCount() == 1) {
-                port = conn.getRemotePort();
+                SchemeRegistry schemeRegistry = (SchemeRegistry) context.getAttribute(
+                        ClientContext.SCHEME_REGISTRY);
+                if (schemeRegistry != null) {
+                    Scheme scheme = schemeRegistry.getScheme(targetHost);
+                    port = scheme.resolvePort(port);
+                }
             } else {
                 // Target port will be selected by the proxy.
                 // Use conventional ports for known schemes
@@ -158,17 +162,15 @@ public class RequestAddCookies implement
                     port = 80;
                 } else if (scheme.equalsIgnoreCase("https")) {
                     port = 443;
-                } else {
-                    port = 0;
                 }
             }
         }
 
         CookieOrigin cookieOrigin = new CookieOrigin(
                 hostName,
-                port,
+                port >= 0 ? port : 0,
                 requestURI.getPath(),
-                conn.isSecure());
+                route.isSecure());
 
         // Get an instance of the selected cookie policy
         CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java?rev=1350257&r1=1350256&r2=1350257&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
Thu Jun 14 14:19:41 2012
@@ -36,9 +36,7 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.conn.HttpRoutedConnection;
-import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.conn.routing.RouteInfo;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 
@@ -73,15 +71,12 @@ public class RequestClientConnControl im
         }
 
         // Obtain the client connection (required)
-        HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
-                ExecutionContext.HTTP_CONNECTION);
-        if (conn == null) {
-            this.log.debug("HTTP connection not set in the context");
+        RouteInfo route = (RouteInfo) context.getAttribute(ClientContext.ROUTE);
+        if (route == null) {
+            this.log.debug("Connection route not set in the context");
             return;
         }
 
-        HttpRoute route = conn.getRoute();
-
         if (route.getHopCount() == 1 || route.isTunnelled()) {
             if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
                 request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1350257&r1=1350256&r2=1350257&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Thu Jun 14 14:19:41 2012
@@ -505,11 +505,9 @@ public class DefaultRequestDirector impl
                     target = route.getTargetHost();
                 }
 
-                HttpHost proxy = route.getProxyHost();
-
                 // Populate the execution context
                 context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
-                context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+                context.setAttribute(ClientContext.ROUTE, route);
                 context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
 
                 // Run request protocol interceptors

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java?rev=1350257&r1=1350256&r2=1350257&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
Thu Jun 14 14:19:41 2012
@@ -26,7 +26,6 @@
 
 package org.apache.http.client.protocol;
 
-import java.net.InetAddress;
 import java.util.Date;
 
 import org.apache.http.Header;
@@ -37,10 +36,12 @@ import org.apache.http.HttpRequestInterc
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.params.AllClientPNames;
 import org.apache.http.client.params.CookiePolicy;
-import org.apache.http.conn.HttpRoutedConnection;
 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.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.CookieSpec;
 import org.apache.http.cookie.CookieSpecRegistry;
@@ -62,7 +63,6 @@ import org.apache.http.protocol.HttpCont
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 
 @SuppressWarnings("boxing")
 public class TestRequestAddCookies {
@@ -127,13 +127,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -164,13 +160,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -191,13 +183,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, null);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -218,13 +206,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, null);
 
@@ -245,13 +229,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, null);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -294,13 +274,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -323,13 +299,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -344,17 +316,16 @@ public class TestRequestAddCookies {
         this.target = new HttpHost("localhost.local");
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-        Mockito.when(conn.getRemoteAddress()).thenReturn(InetAddress.getByName("localhost"));
-        Mockito.when(conn.getRemotePort()).thenReturn(1234);
+        Scheme http = new Scheme("http", 1234, PlainSocketFactory.getSocketFactory());
+        SchemeRegistry schemeRegistry = new SchemeRegistry();
+        schemeRegistry.register(http);
 
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+        context.setAttribute(ClientContext.SCHEME_REGISTRY, schemeRegistry);
 
         HttpRequestInterceptor interceptor = new RequestAddCookies();
         interceptor.process(request, context);
@@ -375,14 +346,9 @@ public class TestRequestAddCookies {
         this.target = new HttpHost("localhost.local");
         HttpRoute route = new HttpRoute(this.target, null, new HttpHost("localhost", 8888),
false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-        Mockito.when(conn.getRemotePort()).thenReturn(1234);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -406,15 +372,9 @@ public class TestRequestAddCookies {
         HttpRoute route = new HttpRoute(this.target, null, new HttpHost("localhost", 8888),
true,
                 TunnelType.TUNNELLED, LayerType.LAYERED);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.TRUE);
-        Mockito.when(conn.getRemoteAddress()).thenReturn(InetAddress.getByName("localhost"));
-        Mockito.when(conn.getRemotePort()).thenReturn(1234);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -444,13 +404,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -479,13 +435,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -522,13 +474,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
@@ -560,13 +508,9 @@ public class TestRequestAddCookies {
 
         HttpRoute route = new HttpRoute(this.target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
-
         HttpContext context = new BasicHttpContext();
         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
         context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
         context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java?rev=1350257&r1=1350256&r2=1350257&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
Thu Jun 14 14:19:41 2012
@@ -32,17 +32,14 @@ import org.apache.http.Header;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.conn.HttpRoutedConnection;
 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.message.BasicHttpRequest;
 import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.junit.Test;
-import org.mockito.Mockito;
 
 public class TestRequestClientConnControl {
 
@@ -75,10 +72,7 @@ public class TestRequestClientConnContro
         HttpHost target = new HttpHost("localhost", 80, "http");
         HttpRoute route = new HttpRoute(target, null, false);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
 
         HttpRequestInterceptor interceptor = new RequestClientConnControl();
         interceptor.process(request, context);
@@ -100,10 +94,7 @@ public class TestRequestClientConnContro
         HttpRoute route = new HttpRoute(target, null, proxy, true,
                 TunnelType.TUNNELLED, LayerType.LAYERED);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
 
         HttpRequestInterceptor interceptor = new RequestClientConnControl();
         interceptor.process(request, context);
@@ -125,10 +116,7 @@ public class TestRequestClientConnContro
         HttpRoute route = new HttpRoute(target, null, proxy, false,
                 TunnelType.PLAIN, LayerType.PLAIN);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
 
         HttpRequestInterceptor interceptor = new RequestClientConnControl();
         interceptor.process(request, context);
@@ -151,10 +139,7 @@ public class TestRequestClientConnContro
         HttpRoute route = new HttpRoute(target, null, proxy, true,
                 TunnelType.TUNNELLED, LayerType.LAYERED);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
 
         HttpRequestInterceptor interceptor = new RequestClientConnControl();
         interceptor.process(request, context);
@@ -177,10 +162,7 @@ public class TestRequestClientConnContro
         HttpRoute route = new HttpRoute(target, null, proxy, false,
                 TunnelType.PLAIN, LayerType.PLAIN);
 
-        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
-        Mockito.when(conn.getRoute()).thenReturn(route);
-
-        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ClientContext.ROUTE, route);
 
         HttpRequestInterceptor interceptor = new RequestClientConnControl();
         interceptor.process(request, context);



Mime
View raw message