Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 45375 invoked from network); 4 Dec 2008 17:21:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Dec 2008 17:21:50 -0000 Received: (qmail 55491 invoked by uid 500); 4 Dec 2008 17:22:02 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 55445 invoked by uid 500); 4 Dec 2008 17:22:02 -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 55436 invoked by uid 99); 4 Dec 2008 17:22:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Dec 2008 09:22:02 -0800 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT 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; Thu, 04 Dec 2008 17:20:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5B42523888A4; Thu, 4 Dec 2008 09:21:29 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r723378 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/... Date: Thu, 04 Dec 2008 17:21:28 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081204172129.5B42523888A4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Thu Dec 4 09:21:28 2008 New Revision: 723378 URL: http://svn.apache.org/viewvc?rev=723378&view=rev Log: JAXRS : support for list/set of path segments Modified: 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/model/URITemplate.java cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java 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=723378&r1=723377&r2=723378&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 Thu Dec 4 09:21:28 2008 @@ -44,7 +44,11 @@ public String getPath() { int index = path.indexOf(';'); - return index != -1 ? path.substring(0, index) : path; + String value = index != -1 ? path.substring(0, index) : path; + if (value.startsWith("/")) { + value = value.length() == 1 ? "" : value.substring(1); + } + return value; } public String getOriginalPath() { Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=723378&r1=723377&r2=723378&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java Thu Dec 4 09:21:28 2008 @@ -113,6 +113,7 @@ } private static String escapeCharacters(String expression) { + StringBuilder sb = new StringBuilder(); for (int i = 0; i < expression.length(); i++) { char ch = expression.charAt(i); @@ -145,11 +146,10 @@ StringBuilder sb = new StringBuilder(); for (int i = 0; i < uList.size(); i++) { sb.append('/'); - if (pList.size() > i && pList.get(i).getPath().indexOf('{') != -1) { - // if it's URI template variable then keep the original value - sb.append(HttpUtils.fromPathSegment(uList.get(i))); - } else { + if (pList.size() > i && pList.get(i).getPath().indexOf('{') == -1) { sb.append(uList.get(i).getPath()); + } else { + sb.append(HttpUtils.fromPathSegment(uList.get(i))); } } uri = sb.toString(); Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=723378&r1=723377&r2=723378&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Thu Dec 4 09:21:28 2008 @@ -226,6 +226,7 @@ public static Object injectIntoList(Type genericType, List values, boolean decoded, boolean pathParam) { Class realType = InjectionUtils.getActualType(genericType); + values = checkPathSegment(values, realType, pathParam); List theValues = new ArrayList(); for (String r : values) { if (decoded) { @@ -245,6 +246,9 @@ public static Object injectIntoSet(Type genericType, List values, boolean sorted, boolean decoded, boolean pathParam) { Class realType = InjectionUtils.getActualType(genericType); + + values = checkPathSegment(values, realType, pathParam); + Set theValues = sorted ? new TreeSet() : new HashSet(); for (String r : values) { if (decoded) { @@ -258,6 +262,25 @@ return theValues; } + private static List checkPathSegment(List values, Class type, boolean pathParam) { + if (!pathParam || !PathSegment.class.isAssignableFrom(type)) { + return values; + } + List newValues = new ArrayList(); + for (String v : values) { + String[] segments = v.split("/"); + for (String s : segments) { + if (s.length() != 0) { + newValues.add(s); + } + } + if (v.endsWith("/")) { + newValues.add(""); + } + } + return newValues; + } + public static Object createParameterObject(List paramValues, Class paramType, Type genericType, Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=723378&r1=723377&r2=723378&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Thu Dec 4 09:21:28 2008 @@ -127,7 +127,7 @@ : new String[]{"*/*"}; } } catch (Exception ex) { - System.out.println(); + // ignore } } return values; Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=723378&r1=723377&r2=723378&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java Thu Dec 4 09:21:28 2008 @@ -88,6 +88,14 @@ } @Test + public void testMatchWithMatrixOnClearPath4() throws Exception { + URITemplate uriTemplate = new URITemplate("/customers"); + MultivaluedMap values = new MetadataMap(); + + assertTrue(uriTemplate.match("/customers;123456/123/orders;456/3", values)); + } + + @Test public void testMatchBasicTwoParametersVariation1() throws Exception { URITemplate uriTemplate = new URITemplate("/customers/{name}/{department}"); MultivaluedMap values = new MetadataMap(); Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=723378&r1=723377&r2=723378&view=diff ============================================================================== --- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original) +++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Thu Dec 4 09:21:28 2008 @@ -100,7 +100,7 @@ @GET @Path("/segment/{pathsegment}/") public Book getBookBySegment(@PathParam("pathsegment") PathSegment segment) throws Exception { - if (!"matrix".equals(segment.getPath())) { + if (!"matrix2".equals(segment.getPath())) { throw new RuntimeException(); } MultivaluedMap map = segment.getMatrixParameters(); @@ -110,6 +110,15 @@ } @GET + @Path("/segment/list/{pathsegment:.+}/") + public Book getBookBySegment(@PathParam("pathsegment") List list) + throws Exception { + return doGetBook(list.get(0).getPath() + + list.get(1).getPath() + + list.get(2).getPath()); + } + + @GET @Path("/segment/matrix") public Book getBookByMatrixParams(@MatrixParam("first") String s1, @MatrixParam("second") String s2) throws Exception { Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=723378&r1=723377&r2=723378&view=diff ============================================================================== --- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original) +++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Thu Dec 4 09:21:28 2008 @@ -215,18 +215,18 @@ @Test public void testGetBookBySegment() throws Exception { - getAndCompareAsStrings("http://localhost:9080/bookstore/segment/matrix;first=12;second=3", + getAndCompareAsStrings("http://localhost:9080/bookstore/segment/matrix2;first=12;second=3", "resources/expected_get_book123.txt", "application/xml", 200); getAndCompareAsStrings("http://localhost:9080/bookstore;bar/segment;foo/" - + "matrix;first=12;second=3;third", + + "matrix2;first=12;second=3;third", "resources/expected_get_book123.txt", "application/xml", 200); } @Test - public void testGetBookByHeader() throws Exception { - getAndCompareAsStrings("http://localhost:9080/bookstore/bookheaders", + public void testGetBookByListOfSegments() throws Exception { + getAndCompareAsStrings("http://localhost:9080/bookstore/segment/list/1/2/3", "resources/expected_get_book123.txt", "application/xml", 200); } @@ -236,8 +236,15 @@ getAndCompareAsStrings("http://localhost:9080/bookstore/segment/matrix;first=12;second=3", "resources/expected_get_book123.txt", "application/xml", 200); - getAndCompareAsStrings("http://localhost:9080/bookstore;bar/segment;foo;" - + "first=12;second=3/matrix;third", + getAndCompareAsStrings("http://localhost:9080/bookstore;bar;first=12/segment;foo;" + + "second=3/matrix;third", + "resources/expected_get_book123.txt", + "application/xml", 200); + } + + @Test + public void testGetBookByHeader() throws Exception { + getAndCompareAsStrings("http://localhost:9080/bookstore/bookheaders", "resources/expected_get_book123.txt", "application/xml", 200); }