cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
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 GMT
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<String> 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<String> 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<String> checkPathSegment(List<String> values, Class<?>
type, boolean pathParam) {
+        if (!pathParam || !PathSegment.class.isAssignableFrom(type)) {
+            return values;
+        }
+        List<String> newValues = new ArrayList<String>();
+        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<String> 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<String, String> values = new MetadataMap<String, String>();
+        
+        assertTrue(uriTemplate.match("/customers;123456/123/orders;456/3", values));
+    }
+    
+    @Test
     public void testMatchBasicTwoParametersVariation1() throws Exception {
         URITemplate uriTemplate = new URITemplate("/customers/{name}/{department}");
         MultivaluedMap<String, String> values = new MetadataMap<String, String>();

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<String, String> map = segment.getMatrixParameters();
@@ -110,6 +110,15 @@
     }
     
     @GET
+    @Path("/segment/list/{pathsegment:.+}/")
+    public Book getBookBySegment(@PathParam("pathsegment") List<PathSegment> 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);
     }



Mime
View raw message