cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r979783 - in /cxf/trunk: parent/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/
Date Tue, 27 Jul 2010 17:43:43 GMT
Author: dkulp
Date: Tue Jul 27 17:43:43 2010
New Revision: 979783

URL: http://svn.apache.org/viewvc?rev=979783&view=rev
Log:
Update to jaxrs 1.1.1 api jar (tck signature tests require this)
Fix some issues in URIBuilder

Modified:
    cxf/trunk/parent/pom.xml
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=979783&r1=979782&r2=979783&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Tue Jul 27 17:43:43 2010
@@ -335,7 +335,7 @@
             <dependency>
                 <groupId>javax.ws.rs</groupId>
                 <artifactId>jsr311-api</artifactId>
-                <version>1.1</version>
+                <version>1.1.1</version>
             </dependency>
 
             <dependency>

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java?rev=979783&r1=979782&r2=979783&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PathSegmentImpl.java
Tue Jul 27 17:43:43 2010
@@ -55,5 +55,9 @@ public class PathSegmentImpl implements 
     public String getOriginalPath() {
         return path;
     }
+    
+    public String toString() {
+        return path;
+    }
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=979783&r1=979782&r2=979783&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Tue Jul 27 17:43:43 2010
@@ -48,6 +48,7 @@ public class UriBuilderImpl extends UriB
     private int port;
     private String host;
     private List<PathSegment> paths = new ArrayList<PathSegment>();
+    private boolean leadingSlash;
     private String fragment;
     private String schemeSpecificPart; 
     private MultivaluedMap<String, String> query = new MetadataMap<String, String>();
@@ -126,7 +127,13 @@ public class UriBuilderImpl extends UriB
             }
             return new URI(b.toString());
         } else if (!isSchemeOpaque()) {
-            return new URI(scheme, userInfo, host, port, thePath, theQuery, fragment);
+            if ((scheme != null || host != null || userInfo != null)
+                && !thePath.isEmpty() && !thePath.startsWith("/")) {
+                thePath = "/" + thePath;
+            }
+            
+            return new URI(scheme, userInfo, host, port, 
+                           thePath, theQuery, fragment);
         } else {
             return new URI(scheme, schemeSpecificPart, fragment);
         }
@@ -149,6 +156,9 @@ public class UriBuilderImpl extends UriB
         int idx = ind;
         for (String var : uniqueVars) {
             Object oval = values[idx++];
+            if (oval == null) {
+                throw new IllegalArgumentException("No object for " + var);
+            }
             varValueMap.put(var, oval.toString());
         }
         return templ.substitute(varValueMap);
@@ -249,6 +259,9 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder host(String theHost) throws IllegalArgumentException {
+        if ("".equals(theHost)) {
+            throw new IllegalArgumentException("Host cannot be empty");
+        }
         this.host = theHost;
         return this;
     }
@@ -314,7 +327,9 @@ public class UriBuilderImpl extends UriB
         if (path == null) {
             throw new IllegalArgumentException("path is null");
         }
-        
+        if (paths.isEmpty()) {
+            leadingSlash = path.startsWith("/");
+        }
         List<PathSegment> segments = JAXRSUtils.getPathSegments(path, false, false);
         if (!paths.isEmpty() && !matrix.isEmpty()) {
             PathSegment ps = paths.remove(paths.size() - 1);
@@ -330,6 +345,9 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder port(int thePort) throws IllegalArgumentException {
+        if (thePort < 0) {
+            throw new IllegalArgumentException("Port cannot be negative");
+        }
         this.port = thePort;
         return this;
     }
@@ -392,6 +410,7 @@ public class UriBuilderImpl extends UriB
     }
 
     private void setPathAndMatrix(String path) {
+        leadingSlash = path.startsWith("/");
         paths = JAXRSUtils.getPathSegments(path, false, false);
         if (!paths.isEmpty()) {
             matrix = paths.get(paths.size() - 1).getMatrixParameters();
@@ -408,7 +427,9 @@ public class UriBuilderImpl extends UriB
             String p = ps.getPath();
             if (p.length() != 0 || !iter.hasNext()) {
                 p = fromEncoded ? new URITemplate(p).encodeLiteralCharacters() : p;
-                if (!p.startsWith("/")) {
+                if (sb.length() == 0 && leadingSlash) {
+                    sb.append('/');
+                } else if (!p.startsWith("/") && sb.length() > 0) {
                     sb.append('/');
                 }
                 sb.append(p);
@@ -504,6 +525,9 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder segment(String... segments) throws IllegalArgumentException {
+        if (segments == null) {
+            throw new IllegalArgumentException("Segments should not be null");
+        }
         for (String segment : segments) {
             path(segment);
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java?rev=979783&r1=979782&r2=979783&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Tue Jul 27 17:43:43 2010
@@ -34,6 +34,7 @@ import org.apache.cxf.jaxrs.resources.Ur
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class UriBuilderImplTest extends Assert {
@@ -730,4 +731,193 @@ public class UriBuilderImplTest extends 
             JAXRSUtils.getStructuredParams(uri2.getRawQuery(), "&", false);
         assertEquals("Unexpected queries", queries1, queries2);
     }
+    
+    
+    @Test
+    public void testTck1() {
+        String value = "test1#test2";
+        String expected = "test1%23test2";
+        String path = "{arg1}";
+        URI uri = UriBuilder.fromPath(path).build(value);
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    public void testNullValue() {
+        String value = null;
+        String path = "{arg1}";
+        try {
+            UriBuilder.fromPath(path).build(value);
+            fail("Should be IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+    @Test
+    public void testFragment() {
+        String expected = "test#abc";
+        String path = "test";
+        URI uri = UriBuilder.fromPath(path).fragment("abc").build();
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testFragmentTemplate() {
+        String expected = "abc#xyz";
+        URI uri = UriBuilder
+            .fromPath("{arg1}")
+            .fragment("{arg2}")
+            .build("abc", "xyx");
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testSegments() {
+        String path1 = "ab";
+        String[] path2 = {"a1", "x/y", "3b "};
+        String expected = "ab/a1/x%2Fy/3b%20";
+
+        URI uri = UriBuilder.fromPath(path1).segment(path2).build();
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testSegments2() {
+        String path1 = "";
+        String[] path2 = {"a1", "/", "3b "};
+        String expected = "a1/%2F/3b%20";
+
+        URI uri = UriBuilder.fromPath(path1).segment(path2).build();
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testReplaceQuery3() {
+        String expected = "http://localhost:8080?name1=xyz";
+
+        URI uri = UriBuilder.fromPath("http://localhost:8080")
+            .queryParam("name", "x=", "y?", "x y", "&").replaceQuery("name1=xyz").build();
+        assertEquals(expected, uri.toString());        
+    }
+    
+    @Test
+    public void testNullSegment() {
+        try {
+            UriBuilder.fromPath("/").segment((String)null).build();
+            fail("Should be IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+    @Test
+    public void testNullQueryParam() {
+        try {
+            UriBuilder.fromPath("http://localhost:8080").queryParam("hello", (String)null);
+            fail("Should be IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+
+    @Test
+    @Ignore
+    public void testReplaceQuery4() {
+        String expected = "http://localhost:8080";
+
+        URI uri = UriBuilder.fromPath("http://localhost:8080")
+            .queryParam("name", "x=", "y?", "x y", "&").replaceQuery(null).build();
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testReplaceQuery5() {
+        String expected = "http://localhost:8080?name1=x&name2=%20&name3=x+y&name4=23&name5=x%20y";
+
+        URI uri = UriBuilder.fromPath("http://localhost:8080")
+            .queryParam("name", "x=", "y?", "x y", "&")
+            .replaceQuery("name1=x&name2=%20&name3=x+y&name4=23&name5=x y").build();
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testQueryParam() {
+        String expected = "http://localhost:8080?name=x%3D&name=y?&name=x+y&name=%26";
+
+        URI uri =  UriBuilder.fromPath("http://localhost:8080")
+            .queryParam("name", "x=", "y?", "x y", "&").build();
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    public void testInvalidPort() {
+        try {
+            UriBuilder.fromUri("http://localhost:8080/some/path?name=foo").port(-10).build();
+            fail("Should be IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+    @Test
+    public void testInvalidHost() {
+        try {
+            UriBuilder.fromUri("http://localhost:8080/some/path?name=foo").host("").build();
+            fail("Should be IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+    @Test
+    @Ignore
+    public void testFromEncoded() {
+        String expected = "http://localhost:8080/a/%25/=/%25G0/%25/=";
+
+        URI uri = UriBuilder.fromPath("http://localhost:8080")
+            .path("/{v}/{w}/{x}/{y}/{z}/{x}")
+            .buildFromEncoded("a", "%25", "=", "%G0", "%", "23"); 
+        assertEquals(expected, uri.toString());        
+
+        expected = "http://localhost:8080/xy/%20/%25/xy";
+        uri = UriBuilder.fromPath("http://localhost:8080")
+            .path("/{x}/{y}/{z}/{x}")
+            .buildFromEncoded("xy", " ", "%");
+        assertEquals(expected, uri.toString());        
+    }
+    @Test
+    @Ignore
+    public void testNullMapValue() {
+        try {
+            Map<String, String> maps = new HashMap<String, String>();
+            maps.put("x", null);
+            maps.put("y", "/path-absolute/test1");
+            maps.put("z", "fred@example.com");
+            maps.put("w", "path-rootless/test2");
+            maps.put("u", "extra");
+
+            URI uri = UriBuilder.fromPath("")
+                .path("{w}/{x}/{y}/{z}/{x}")
+                .buildFromMap(maps);
+            
+            fail("Should be IllegalArgumentException.  Not return " + uri.toString());
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+    @Test
+    @Ignore
+    public void testMissingMapValue() {
+        try {
+            Map<String, String> maps = new HashMap<String, String>();
+            maps.put("x", null);
+            maps.put("y", "/path-absolute/test1");
+            maps.put("z", "fred@example.com");
+            maps.put("w", "path-rootless/test2");
+            maps.put("u", "extra");
+
+            URI uri = UriBuilder.fromPath("")
+                .path("{w}/{v}/{x}/{y}/{z}/{x}")
+                .buildFromMap(maps);
+            
+            fail("Should be IllegalArgumentException.  Not return " + uri.toString());
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
 }



Mime
View raw message