hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1076792 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/protocol/ test/java/org/apache/http/client/protocol/
Date Thu, 03 Mar 2011 20:59:53 GMT
Author: olegk
Date: Thu Mar  3 20:59:52 2011
New Revision: 1076792

URL: http://svn.apache.org/viewvc?rev=1076792&view=rev
Log:
Made behaviour of protocol interceptors more somewhat consistent; added test cases for RequestAddCookies

Added:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestProxyAuthentication.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
Thu Mar  3 20:59:52 2011
@@ -99,7 +99,7 @@ public class RequestAddCookies implement
         CookieStore cookieStore = (CookieStore) context.getAttribute(
                 ClientContext.COOKIE_STORE);
         if (cookieStore == null) {
-            this.log.info("Cookie store not available in HTTP context");
+            this.log.debug("Cookie store not specified in HTTP context");
             return;
         }
 
@@ -107,7 +107,7 @@ public class RequestAddCookies implement
         CookieSpecRegistry registry = (CookieSpecRegistry) context.getAttribute(
                 ClientContext.COOKIESPEC_REGISTRY);
         if (registry == null) {
-            this.log.info("CookieSpec registry not available in HTTP context");
+            this.log.debug("CookieSpec registry not specified in HTTP context");
             return;
         }
 
@@ -115,14 +115,16 @@ public class RequestAddCookies implement
         HttpHost targetHost = (HttpHost) context.getAttribute(
                 ExecutionContext.HTTP_TARGET_HOST);
         if (targetHost == null) {
-            throw new IllegalStateException("Target host not specified in HTTP context");
+            this.log.debug("Target host not set in the context");
+            return;
         }
 
         // Obtain the client connection (required)
         HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
                 ExecutionContext.HTTP_CONNECTION);
         if (conn == null) {
-            throw new IllegalStateException("Client connection not specified in HTTP context");
+            this.log.debug("HTTP connection not set in the context");
+            return;
         }
 
         String policy = HttpClientParams.getCookiePolicy(request.getParams());

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
Thu Mar  3 20:59:52 2011
@@ -72,12 +72,14 @@ public class RequestAuthCache implements
 
         AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
         if (authCache == null) {
+            this.log.debug("Auth cache not set in the context");
             return;
         }
 
         CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
                 ClientContext.CREDS_PROVIDER);
         if (credsProvider == null) {
+            this.log.debug("Credentials provider not set in the context");
             return;
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
Thu Mar  3 20:59:52 2011
@@ -29,6 +29,8 @@ package org.apache.http.client.protocol;
 
 import java.io.IOException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.http.annotation.Immutable;
 
 import org.apache.http.HttpException;
@@ -50,6 +52,8 @@ import org.apache.http.protocol.HttpCont
 @Immutable
 public class RequestClientConnControl implements HttpRequestInterceptor {
 
+    private final Log log = LogFactory.getLog(getClass());
+
     private static final String PROXY_CONN_DIRECTIVE = "Proxy-Connection";
 
     public RequestClientConnControl() {
@@ -72,7 +76,8 @@ public class RequestClientConnControl im
         HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
                 ExecutionContext.HTTP_CONNECTION);
         if (conn == null) {
-            throw new IllegalStateException("Client connection not specified in HTTP context");
+            this.log.debug("HTTP connection not set in the context");
+            return;
         }
 
         HttpRoute route = conn.getRoute();

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
Thu Mar  3 20:59:52 2011
@@ -80,7 +80,8 @@ public class RequestProxyAuthentication 
         HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
                 ExecutionContext.HTTP_CONNECTION);
         if (conn == null) {
-            throw new IllegalStateException("Client connection not specified in HTTP context");
+            this.log.debug("HTTP connection not set in the context");
+            return;
         }
         HttpRoute route = conn.getRoute();
         if (route.isTunnelled()) {
@@ -91,6 +92,7 @@ public class RequestProxyAuthentication 
         AuthState authState = (AuthState) context.getAttribute(
                 ClientContext.PROXY_AUTH_STATE);
         if (authState == null) {
+            this.log.debug("Proxy auth state not set in the context");
             return;
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
Thu Mar  3 20:59:52 2011
@@ -83,6 +83,7 @@ public class RequestTargetAuthentication
         AuthState authState = (AuthState) context.getAttribute(
                 ClientContext.TARGET_AUTH_STATE);
         if (authState == null) {
+            this.log.debug("Target auth state not set in the context");
             return;
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
Thu Mar  3 20:59:52 2011
@@ -75,20 +75,21 @@ public class ResponseProcessCookies impl
         CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
                 ClientContext.COOKIE_SPEC);
         if (cookieSpec == null) {
+            this.log.debug("Cookie spec not specified in HTTP context");
             return;
         }
         // Obtain cookie store
         CookieStore cookieStore = (CookieStore) context.getAttribute(
                 ClientContext.COOKIE_STORE);
         if (cookieStore == null) {
-            this.log.info("CookieStore not available in HTTP context");
+            this.log.debug("Cookie store not specified in HTTP context");
             return;
         }
         // Obtain actual CookieOrigin instance
         CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
                 ClientContext.COOKIE_ORIGIN);
         if (cookieOrigin == null) {
-            this.log.info("CookieOrigin not available in HTTP context");
+            this.log.debug("Cookie origin not specified in HTTP context");
             return;
         }
         HeaderIterator it = response.headerIterator(SM.SET_COOKIE);

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java?rev=1076792&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
Thu Mar  3 20:59:52 2011
@@ -0,0 +1,319 @@
+/*
+ * ====================================================================
+ *
+ *  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.client.protocol;
+
+import org.apache.http.Header;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+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.cookie.CookieOrigin;
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.CookieSpecRegistry;
+import org.apache.http.cookie.SM;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.cookie.BasicClientCookie;
+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.RFC2109Spec;
+import org.apache.http.impl.cookie.RFC2109SpecFactory;
+import org.apache.http.impl.cookie.RFC2965SpecFactory;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestRequestAddCookies {
+
+    private HttpHost target;
+    private CookieStore cookieStore;
+    private CookieSpecRegistry cookieSpecRegistry;
+
+    @Before
+    public void setUp() {
+        this.target = new HttpHost("localhost", 80);
+        this.cookieStore = new BasicCookieStore();
+        BasicClientCookie cookie1 = new BasicClientCookie("name1", "value1");
+        cookie1.setDomain("localhost");
+        cookie1.setPath("/");
+        this.cookieStore.addCookie(cookie1);
+        BasicClientCookie cookie2 = new BasicClientCookie("name2", "value2");
+        cookie2.setDomain("localhost");
+        cookie2.setPath("/");
+        this.cookieStore.addCookie(cookie2);
+
+        this.cookieSpecRegistry = new CookieSpecRegistry();
+        this.cookieSpecRegistry.register(
+                CookiePolicy.BEST_MATCH,
+                new BestMatchSpecFactory());
+        this.cookieSpecRegistry.register(
+                CookiePolicy.BROWSER_COMPATIBILITY,
+                new BrowserCompatSpecFactory());
+        this.cookieSpecRegistry.register(
+                CookiePolicy.NETSCAPE,
+                new NetscapeDraftSpecFactory());
+        this.cookieSpecRegistry.register(
+                CookiePolicy.RFC_2109,
+                new RFC2109SpecFactory());
+        this.cookieSpecRegistry.register(
+                CookiePolicy.RFC_2965,
+                new RFC2965SpecFactory());
+        this.cookieSpecRegistry.register(
+                CookiePolicy.IGNORE_COOKIES,
+                new IgnoreSpecFactory());
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testRequestParameterCheck() throws Exception {
+        HttpContext context = new BasicHttpContext();
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(null, context);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testContextParameterCheck() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, null);
+    }
+
+    @Test
+    public void testAddCookies() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        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.COOKIE_STORE, this.cookieStore);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(1, headers1.length);
+        Assert.assertEquals("name1=value1; name2=value2", headers1[0].getValue());
+        Header[] headers2 = request.getHeaders(SM.COOKIE2);
+        Assert.assertNotNull(headers2);
+        Assert.assertEquals(1, headers2.length);
+        Assert.assertEquals("$Version=1", headers2[0].getValue());
+
+        CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
+                ClientContext.COOKIE_ORIGIN);
+        Assert.assertNotNull(cookieOrigin);
+        Assert.assertEquals("localhost", cookieOrigin.getHost());
+        Assert.assertEquals(80, cookieOrigin.getPort());
+        Assert.assertEquals("/", cookieOrigin.getPath());
+        Assert.assertFalse(cookieOrigin.isSecure());
+    }
+
+    @Test
+    public void testCookiesForConnectRequest() throws Exception {
+        HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
+
+        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.COOKIE_STORE, this.cookieStore);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(0, headers1.length);
+        Header[] headers2 = request.getHeaders(SM.COOKIE2);
+        Assert.assertNotNull(headers2);
+        Assert.assertEquals(0, headers2.length);
+    }
+
+    @Test
+    public void testNoCookieStore() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        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.COOKIE_STORE, null);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(0, headers1.length);
+        Header[] headers2 = request.getHeaders(SM.COOKIE2);
+        Assert.assertNotNull(headers2);
+        Assert.assertEquals(0, headers2.length);
+    }
+
+    @Test
+    public void testNoCookieSpecRegistry() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        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.COOKIE_STORE, this.cookieStore);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, null);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(0, headers1.length);
+        Header[] headers2 = request.getHeaders(SM.COOKIE2);
+        Assert.assertNotNull(headers2);
+        Assert.assertEquals(0, headers2.length);
+    }
+
+    @Test
+    public void testNoTargetHost() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        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.COOKIE_STORE, this.cookieStore);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(0, headers1.length);
+        Header[] headers2 = request.getHeaders(SM.COOKIE2);
+        Assert.assertNotNull(headers2);
+        Assert.assertEquals(0, headers2.length);
+    }
+
+    @Test
+    public void testNoHttpConnection() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        HttpContext context = new BasicHttpContext();
+        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
+        context.setAttribute(ExecutionContext.HTTP_CONNECTION, null);
+        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(0, headers1.length);
+        Header[] headers2 = request.getHeaders(SM.COOKIE2);
+        Assert.assertNotNull(headers2);
+        Assert.assertEquals(0, headers2.length);
+    }
+
+    @Test
+    public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+        request.getParams().setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
+
+        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.COOKIE_STORE, this.cookieStore);
+        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+
+        HttpRequestInterceptor interceptor = new RequestAddCookies();
+        interceptor.process(request, context);
+
+        CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
+                ClientContext.COOKIE_SPEC);
+        Assert.assertTrue(cookieSpec instanceof RFC2109Spec);
+
+        Header[] headers1 = request.getHeaders(SM.COOKIE);
+        Assert.assertNotNull(headers1);
+        Assert.assertEquals(2, headers1.length);
+        Assert.assertEquals("$Version=0; name1=value1", headers1[0].getValue());
+        Assert.assertEquals("$Version=0; name2=value2", headers1[1].getValue());
+
+        CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
+                ClientContext.COOKIE_ORIGIN);
+        Assert.assertNotNull(cookieOrigin);
+        Assert.assertEquals("localhost", cookieOrigin.getHost());
+        Assert.assertEquals(80, cookieOrigin.getPort());
+        Assert.assertEquals("/", cookieOrigin.getPath());
+        Assert.assertFalse(cookieOrigin.isSecure());
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
Thu Mar  3 20:59:52 2011
@@ -213,4 +213,34 @@ public class TestRequestAuthCache {
         Assert.assertNull(this.proxyState.getCredentials());
     }
 
+    @Test
+    public void testAuthSchemeAlreadySet() throws Exception {
+        HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        HttpContext context = new BasicHttpContext();
+        context.setAttribute(ClientContext.CREDS_PROVIDER, this.credProvider);
+        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
+        context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, this.proxy);
+        context.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetState);
+        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);
+
+        AuthCache authCache = new BasicAuthCache();
+        authCache.put(this.target, this.authscheme1);
+        authCache.put(this.proxy, this.authscheme2);
+
+        context.setAttribute(ClientContext.AUTH_CACHE, authCache);
+
+        this.targetState.setAuthScheme(new BasicScheme());
+        this.targetState.setCredentials(new UsernamePasswordCredentials("user3", "secret3"));
+        this.proxyState.setAuthScheme(new BasicScheme());
+        this.proxyState.setCredentials(new UsernamePasswordCredentials("user4", "secret4"));
+
+        HttpRequestInterceptor interceptor = new RequestAuthCache();
+        interceptor.process(request, context);
+        Assert.assertNotSame(this.authscheme1, this.targetState.getAuthScheme());
+        Assert.assertNotSame(this.creds1, this.targetState.getCredentials());
+        Assert.assertNotSame(this.authscheme2, this.proxyState.getAuthScheme());
+        Assert.assertNotSame(this.creds2, this.proxyState.getCredentials());
+    }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestClientConnControl.java
Thu Mar  3 20:59:52 2011
@@ -53,14 +53,6 @@ public class TestRequestClientConnContro
         interceptor.process(null, context);
     }
 
-    @Test(expected=IllegalStateException.class)
-    public void testConnectionInContextCheck() throws Exception {
-        HttpRequest request = new BasicHttpRequest("GET", "/");
-        HttpContext context = new BasicHttpContext();
-        HttpRequestInterceptor interceptor = new RequestClientConnControl();
-        interceptor.process(request, context);
-    }
-
     @Test
     public void testConnectionKeepAliveForConnectRequest() throws Exception {
         HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestProxyAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestProxyAuthentication.java?rev=1076792&r1=1076791&r2=1076792&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestProxyAuthentication.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestProxyAuthentication.java
Thu Mar  3 20:59:52 2011
@@ -66,14 +66,6 @@ public class TestRequestProxyAuthenticat
         interceptor.process(request, null);
     }
 
-    @Test(expected=IllegalStateException.class)
-    public void testConnectionInContextCheck() throws Exception {
-        HttpRequest request = new BasicHttpRequest("GET", "/");
-        HttpContext context = new BasicHttpContext();
-        HttpRequestInterceptor interceptor = new RequestProxyAuthentication();
-        interceptor.process(request, context);
-    }
-
     @Test
     public void testProxyAuthOverPlainConnection() throws Exception {
         HttpRequest request = new BasicHttpRequest("GET", "/");



Mime
View raw message