cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5657] Preserving the cookies during the auto-redirects
Date Fri, 28 Mar 2014 16:33:05 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes ac8a4ab64 -> 84c6bac40


[CXF-5657] Preserving the cookies during the auto-redirects


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/84c6bac4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/84c6bac4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/84c6bac4

Branch: refs/heads/2.7.x-fixes
Commit: 84c6bac409d08b4b3b4e4e3d040d9382f59216e8
Parents: ac8a4ab
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Mar 28 16:11:10 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Mar 28 16:32:36 2014 +0000

----------------------------------------------------------------------
 .../java/org/apache/cxf/transport/http/HTTPConduit.java |  1 +
 .../java/org/apache/cxf/systest/jaxrs/BookStore.java    | 12 +++++++++---
 .../cxf/systest/jaxrs/JAXRSClientServerBookTest.java    |  6 ++++++
 3 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/84c6bac4/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
index 5a6c199..736023b 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
@@ -1443,6 +1443,7 @@ public abstract class HTTPConduit
                 } catch (URISyntaxException e) {
                     throw new IOException(e);
                 }
+                cookies.writeToMessageHeaders(outMessage);
                 retransmit(newURL);
                 return true;
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/84c6bac4/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index cd201c2..c9f46ff 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -43,6 +43,7 @@ import javax.annotation.PreDestroy;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.BeanParam;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
@@ -65,6 +66,7 @@ import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -169,14 +171,18 @@ public class BookStore {
     @GET
     @Path("/redirect")
     public Response getBookRedirect(@QueryParam("redirect") Boolean done,
-                                    @QueryParam("sameuri") Boolean sameuri) {
+                                    @QueryParam("sameuri") Boolean sameuri,
+                                    @CookieParam("a") String cookie) {
         if (done == null) {
             String uri = sameuri.equals(Boolean.TRUE) 
                 ? ui.getAbsolutePathBuilder().queryParam("redirect", "true").build().toString()
                 : "http://otherhost/redirect";
-            return Response.status(303).header("Location", uri).build();
+            return Response.status(303).cookie(NewCookie.valueOf("a=b")).header("Location",
uri).build();
         } else {
-            return Response.ok(new Book("CXF", 123L), "application/xml").build();
+            return Response.ok(new Book("CXF", 123L), "application/xml")
+                .header("RequestURI", this.ui.getRequestUri().toString())
+                .header("TheCookie", cookie)
+                .build();
         }
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/84c6bac4/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index c67bcb3..8990b06 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -115,9 +115,15 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=true";
         WebClient wc = WebClient.create(address);
         WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
+        WebClient.getConfig(wc).getRequestContext().put(
+            org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
         Response r = wc.get();
         Book book = r.readEntity(Book.class);
         assertEquals(123L, book.getId());
+        String requestUri = r.getStringHeaders().getFirst("RequestURI");
+        assertEquals("http://localhost:" + PORT + "/bookstore/redirect?redirect=true", requestUri);
+        String theCookie = r.getStringHeaders().getFirst("TheCookie");
+        assertEquals("b", theCookie);
     }
     
     @Test


Mime
View raw message