cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r720053 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ systests/src/test/java/org/apache/cxf...
Date Sun, 23 Nov 2008 21:55:00 GMT
Author: sergeyb
Date: Sun Nov 23 13:55:00 2008
New Revision: 720053

URL: http://svn.apache.org/viewvc?rev=720053&view=rev
Log:
JAXRS : support for PathSegment path parameters

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/PathSegmentImplTest.java
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/utils/JAXRSUtils.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=720053&r1=720052&r2=720053&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
Sun Nov 23 13:55:00 2008
@@ -29,23 +29,22 @@
 public class PathSegmentImpl implements PathSegment {
 
     private String path;
-    private boolean decode;
-    
+        
     public PathSegmentImpl(String path) {
         this(path, true);
     }
     
     public PathSegmentImpl(String path, boolean decode) {
-        this.path = path;
-        this.decode = decode;
+        this.path = decode ? JAXRSUtils.uriDecode(path) : path;
     }
     
     public MultivaluedMap<String, String> getMatrixParameters() {
-        return JAXRSUtils.getMatrixParams(path, decode);
+        return JAXRSUtils.getMatrixParams(path, false);
     }
 
     public String getPath() {
-        return path;
+        int index = path.indexOf(';');
+        return index != -1 ? path.substring(0, index) : path;
     }
 
 }

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=720053&r1=720052&r2=720053&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 Sun
Nov 23 13:55:00 2008
@@ -552,12 +552,17 @@
             return InjectionUtils.handleBean(paramType, values);
         } else {
             List<String> results = values.get(parameterName);
-            return InjectionUtils.createParameterObject(results, 
+            if (PathSegment.class.isAssignableFrom(paramType)
+                && results != null && results.size() > 0) {
+                return new PathSegmentImpl(results.get(0), decoded);
+            } else {
+                return InjectionUtils.createParameterObject(results, 
                                                         paramType, 
                                                         genericType,
                                                         defaultValue,
                                                         true,
                                                         decoded);
+            }
         }
     }
     

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/PathSegmentImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/PathSegmentImplTest.java?rev=720053&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/PathSegmentImplTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/PathSegmentImplTest.java
Sun Nov 23 13:55:00 2008
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.impl;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PathSegmentImplTest extends Assert {
+    
+    @Test
+    public void testPlainPathSegment() { 
+        PathSegment ps = new PathSegmentImpl("bar");
+        assertEquals("bar", ps.getPath());
+        assertEquals(0, ps.getMatrixParameters().size());
+    }
+    
+    @Test
+    public void testPathSegmentWithMatrixParams() { 
+        PathSegment ps = new PathSegmentImpl("bar;a=1;a=2;b=3%202", false);
+        assertEquals("bar", ps.getPath());
+        MultivaluedMap<String, String> params = ps.getMatrixParameters();
+        assertEquals(2, params.size());
+        assertEquals(2, params.get("a").size());
+        assertEquals("1", params.get("a").get(0));
+        assertEquals("2", params.get("a").get(1));
+        assertEquals("3%202", params.getFirst("b"));
+    }
+    
+    @Test
+    public void testPathSegmentWithDecodedMatrixParams() { 
+        PathSegment ps = new PathSegmentImpl("bar%20foo;a=1%202");
+        assertEquals("bar foo", ps.getPath());
+        MultivaluedMap<String, String> params = ps.getMatrixParameters();
+        assertEquals(1, params.size());
+        assertEquals(1, params.get("a").size());
+        assertEquals("1 2", params.get("a").get(0));
+    }
+}

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=720053&r1=720052&r2=720053&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 Sun Nov 23
13:55:00 2008
@@ -37,6 +37,8 @@
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
@@ -94,6 +96,18 @@
     }
     
     @GET
+    @Path("/segment/{pathsegment}/")
+    public Book getBookBySegment(@PathParam("pathsegment") PathSegment segment) throws Exception
{
+        if (!"matrix".equals(segment.getPath())) {
+            throw new RuntimeException();
+        }
+        MultivaluedMap<String, String> map = segment.getMatrixParameters();
+        String s1 = map.getFirst("first").toString();
+        String s2 = map.getFirst("second").toString();
+        return doGetBook(s1 + s2);
+    }
+    
+    @GET
     @Path("/bookquery")
     public Book getBookByURLQuery(@QueryParam("urlid") String urlValue) throws Exception
{
         String url2 = new URL(urlValue).toString();

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=720053&r1=720052&r2=720053&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
Sun Nov 23 13:55:00 2008
@@ -206,6 +206,14 @@
     }
     
     @Test
+    public void testGetBookBySegment() throws Exception {
+        getAndCompareAsStrings("http://localhost:9080/bookstore/segment/matrix;first=12;second=3",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+        
+    }
+    
+    @Test
     public void testGetBookElement() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/books/element",
                                "resources/expected_get_book123.txt",



Mime
View raw message