cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1004723 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 05 Oct 2010 17:23:23 GMT
Author: sergeyb
Date: Tue Oct  5 17:23:23 2010
New Revision: 1004723

URL: http://svn.apache.org/viewvc?rev=1004723&view=rev
Log:
[CXF-3024] Fixing ResponseBuilder.location to check for query and fragment

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1004723&r1=1004722&r2=1004723&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Tue Oct  5 17:23:23 2010
@@ -93,15 +93,19 @@ public final class ResponseBuilderImpl e
         return setHeader(HttpHeaders.CONTENT_LANGUAGE, language);
     }
 
-    public ResponseBuilder location(URI location) {
-        if (!location.isAbsolute()) {
+    public ResponseBuilder location(URI loc) {
+        if (!loc.isAbsolute()) {
             Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
             if (currentMessage != null) {
+                
                 UriInfo ui = new UriInfoImpl(currentMessage.getExchange().getInMessage(),
null);
-                location = ui.getBaseUriBuilder().path(location.toString()).build();
+                loc = ui.getBaseUriBuilder()
+                        .path(loc.getRawPath())
+                        .replaceQuery(loc.getRawQuery())
+                        .fragment(loc.getRawFragment()).buildFromEncoded();
             }
         }
-        return setHeader(HttpHeaders.LOCATION, location);
+        return setHeader(HttpHeaders.LOCATION, loc);
     }
 
     public ResponseBuilder contentLocation(URI location) {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1004723&r1=1004722&r2=1004723&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue
Oct  5 17:23:23 2010
@@ -23,6 +23,7 @@ package org.apache.cxf.systest.jaxrs;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URI;
 import java.net.URL;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
@@ -58,6 +59,7 @@ import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.StreamingOutput;
+import javax.ws.rs.core.UriBuilder;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -117,6 +119,14 @@ public class BookStore {
     }
     
     @GET
+    @Path("tempredirect")
+    public Response tempRedirect() {
+        URI uri = UriBuilder.fromPath("whatever/redirection")
+            .queryParam("css1", "http://bar").build();
+        return Response.temporaryRedirect(uri).build();
+    }
+    
+    @GET
     @Path("propogateexception")
     public Book propogateException() throws BookNotFoundFault {
         throw new BookNotFoundFault("Book Exception");

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1004723&r1=1004722&r2=1004723&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Oct  5 17:23:23 2010
@@ -28,6 +28,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
 import org.apache.commons.httpclient.Header;
@@ -69,6 +70,17 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testTempRedirectWebClient() throws Exception {
+        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/tempredirect");
+        Response r = client.type("*/*").get();
+        assertEquals(307, r.getStatus());
+        MultivaluedMap<String, Object> map = r.getMetadata();
+        assertEquals("http://localhost:" + PORT + "/whatever/redirection?css1=http%3A//bar",
+                     map.getFirst("Location").toString());
+    }
+    
+    
+    @Test
     public void testOnewayProxy() throws Exception {
         BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
         proxy.onewayRequest();



Mime
View raw message