cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1333927 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Date Fri, 04 May 2012 13:05:56 GMT
Author: sergeyb
Date: Fri May  4 13:05:55 2012
New Revision: 1333927

URL: http://svn.apache.org/viewvc?rev=1333927&view=rev
Log:
Merged revisions 1333913 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes

................
  r1333913 | sergeyb | 2012-05-04 13:40:33 +0100 (Fri, 04 May 2012) | 9 lines
  
  Merged revisions 1333910 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1333910 | sergeyb | 2012-05-04 13:35:39 +0100 (Fri, 04 May 2012) | 1 line
    
    [CXF-4281] Update to UriBuilder.replacePath implementation
  ........
................

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.5.x-fixes:r1333913
  Merged /cxf/trunk:r1333910

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=1333927&r1=1333926&r2=1333927&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Fri May  4 13:05:55 2012
@@ -386,9 +386,7 @@ public class UriBuilderImpl extends UriB
         if (path == null) {
             throw new IllegalArgumentException("path is null");
         }
-        // this is the cheapest way to figure out if a given path is a full-fledged 
-        // URI with the http(s) scheme but a more formal approach may be needed 
-        if (path.startsWith("http")) {
+        if (isAbsoluteUriPath(path)) {
             uri(URI.create(path));
             return this;
         }
@@ -577,14 +575,34 @@ public class UriBuilderImpl extends UriB
     @Override
     public UriBuilder replacePath(String path) {
         if (path == null) {
-            paths.clear();
-            matrix.clear();
+            clearPathAndMatrix();
+        } else if (isAbsoluteUriPath(path)) {
+            clearPathAndMatrix();
+            uri(URI.create(path));
         } else {
             setPathAndMatrix(path);
         }
         return this;
     }
 
+    private void clearPathAndMatrix() {
+        paths.clear();
+        matrix.clear();
+    }
+    
+    private boolean isAbsoluteUriPath(String path) {
+        // This is the cheapest way to figure out if a given path is an absolute 
+        // URI with the http(s) scheme, more expensive way is to always convert 
+        // a path to URI and check if it starts from some scheme or not
+        
+        // Given that the list of schemes can be open-ended it is recommended that
+        // UriBuilder.fromUri is called instead for schemes like 'file', 'jms', etc
+        // be supported though the use of non-http schemes for *building* new URIs
+        // is pretty limited in the context of working with JAX-RS services
+         
+        return path.startsWith("http");
+    }
+    
     @Override
     public UriBuilder replaceQuery(String queryValue) throws IllegalArgumentException {
         if (queryValue != null) {

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java?rev=1333927&r1=1333926&r2=1333927&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Fri May  4 13:05:55 2012
@@ -978,6 +978,26 @@ public class UriBuilderImplTest extends 
     }
 
     @Test
+    public void testFromEncodedDuplicateVarReplacePath() {
+        String expected = "http://localhost:8080/1/2/3/1";
+        URI uri = UriBuilder.fromPath("")
+                            .replacePath("http://localhost:8080")
+                            .path("/{a}/{b}/{c}/{a}")
+                            .buildFromEncoded("1", "2", "3");
+
+        assertEquals(expected, uri.toString());        
+    }
+    
+    @Test
+    public void testNullScheme() {
+        String expected = "//localhost:8080";
+        URI uri = UriBuilder.fromUri("http://localhost:8080")
+                            .scheme(null)
+                            .build();
+        assertEquals(expected, uri.toString());        
+    }
+
+    @Test
     public void testNullMapValue() {
         try {
             Map<String, String> maps = new HashMap<String, String>();



Mime
View raw message