Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 88752 invoked from network); 27 Jul 2010 17:45:02 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 Jul 2010 17:45:02 -0000 Received: (qmail 6492 invoked by uid 500); 27 Jul 2010 17:45:02 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 6414 invoked by uid 500); 27 Jul 2010 17:45:01 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 6407 invoked by uid 99); 27 Jul 2010 17:45:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Jul 2010 17:45:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Jul 2010 17:45:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C738C23888D7; Tue, 27 Jul 2010 17:43:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100727174343.C738C23888D7@eris.apache.org> 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 @@ javax.ws.rs jsr311-api - 1.1 + 1.1.1 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 paths = new ArrayList(); + private boolean leadingSlash; private String fragment; private String schemeSpecificPart; private MultivaluedMap query = new MetadataMap(); @@ -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 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 maps = new HashMap(); + 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 maps = new HashMap(); + 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 + } + } }