cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r906882 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
Date Fri, 05 Feb 2010 09:48:14 GMT
Author: sergeyb
Date: Fri Feb  5 09:48:13 2010
New Revision: 906882

URL: http://svn.apache.org/viewvc?rev=906882&view=rev
Log:
CXF-2652 : UriInfo.getAbsolutePath was failing if encoded chars were included in the original
request URI

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=906882&r1=906881&r2=906882&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Fri
Feb  5 09:48:13 2010
@@ -88,7 +88,12 @@
     }
 
     public String getPath(boolean decode) {
-        return doGetPath(decode, true);
+        String value = doGetPath(decode, true);
+        if (value.length() > 1 && value.startsWith("/")) { 
+            return value.substring(1);
+        } else {
+            return value;
+        }
     }
 
     public List<PathSegment> getPathSegments() {
@@ -192,7 +197,7 @@
         if (MessageUtils.isRequestor(message)) {
             return address;
         }
-        String path = doGetPath(true, false);
+        String path = doGetPath(false, false);
         if (path.startsWith("/") && address.endsWith("/")) {
             address = address.substring(0, address.length() - 1);
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java?rev=906882&r1=906881&r2=906882&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
Fri Feb  5 09:48:13 2010
@@ -60,6 +60,20 @@
     }
     
     @Test
+    public void testGetAbsolutePathWithEncodedChars() {
+        
+        UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz%20foo", "/bar"),
+                                        null);
+        assertEquals("Wrong absolute path", "http://localhost:8080/baz%20foo/bar", 
+                     u.getAbsolutePath().toString());
+        u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/%20foo", "/bar%20foo"),
+                                        null);
+        assertEquals("Wrong absolute path", "http://localhost:8080/baz/%20foo/bar%20foo",

+                     u.getAbsolutePath().toString());
+        
+    }
+    
+    @Test
     public void testGetQueryParameters() {
         UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"),
                                         null);
@@ -87,10 +101,20 @@
     @Test
     public void testGetRequestURI() {
         
-        UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/baz/bar",
"n=1%202"),
+        UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo",
"n=1%202"),
+                            null);
+
+        assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo?n=1%202",
+                     u.getRequestUri().toString());
+    }
+    
+    @Test
+    public void testGetRequestURIWithEncodedChars() {
+        
+        UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo/%20bar",
"n=1%202"),
                             null);
 
-        assertEquals("Wrong request uri", "http://localhost:8080/baz/bar?n=1%202",
+        assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo/%20bar?n=1%202",
                      u.getRequestUri().toString());
     }
     
@@ -150,7 +174,7 @@
         UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/bar/baz", 
                                                     "/baz"),
                                         null);
-        assertEquals("Wrong path", "/baz", u.getPath());
+        assertEquals("Wrong path", "baz", u.getPath());
         
         u = new UriInfoImpl(mockMessage("http://localhost:8080/bar/baz", 
                             "/bar/baz"), null);
@@ -162,11 +186,11 @@
         
         u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/baz/bar%201"),
                                         null);
-        assertEquals("Wrong path", "/bar 1", u.getPath());
+        assertEquals("Wrong path", "bar 1", u.getPath());
         
         u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/baz/bar%201"),
                             null);
-        assertEquals("Wrong path", "/bar%201", u.getPath(false));
+        assertEquals("Wrong path", "bar%201", u.getPath(false));
       
         
     }



Mime
View raw message