cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r790134 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Date Wed, 01 Jul 2009 12:16:10 GMT
Author: sergeyb
Date: Wed Jul  1 12:16:10 2009
New Revision: 790134

URL: http://svn.apache.org/viewvc?rev=790134&view=rev
Log:
[CXF-2326] JAX-RS sub-resources can not access parent template variables

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.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/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=790134&r1=790133&r2=790134&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Jul
 1 12:16:10 2009
@@ -24,7 +24,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
@@ -44,6 +43,8 @@
 import org.apache.cxf.jaxrs.model.MethodInvocationInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -138,7 +139,7 @@
         if (ori.isSubResourceLocator()) {
             try {
                 Message msg = exchange.getInMessage();
-                MultivaluedMap<String, String> values = new MetadataMap<String,
String>();
+                MultivaluedMap<String, String> values = getTemplateValues(msg);
                 String subResourcePath = (String)msg.get(JAXRSInInterceptor.RELATIVE_PATH);
                 String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD);
                 String contentType = (String)msg.get(Message.CONTENT_TYPE);
@@ -192,6 +193,17 @@
         return result;
     }
 
+    @SuppressWarnings("unchecked")
+    protected MultivaluedMap getTemplateValues(Message msg) {
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+        MultivaluedMap<String, String> oldValues = 
+            (MultivaluedMap<String, String>)msg.get(URITemplate.TEMPLATE_PARAMETERS);
+        if (oldValues != null) {
+            values.putAll(oldValues);
+        }
+        return values;
+    }
+    
     private boolean setServiceLoaderAsContextLoader(Message inMessage) {
         Object en = inMessage.getContextualProperty(SERVICE_LOADER_AS_CONTEXT);
         return Boolean.TRUE.equals(en) || "true".equals(en);
@@ -245,10 +257,13 @@
             values = Collections.emptyList();
         } else {
             values = new ArrayList<String>(params.size() - 1);
-            // if we have {bar}/{foo}/{bar} then we have a problem
-            for (Map.Entry<String, List<String>> entry : params.entrySet()) {
-                if (!entry.getKey().equals(URITemplate.FINAL_MATCH_GROUP)) {
-                    values.addAll(entry.getValue());
+            for (Parameter pm : ori.getParameters()) {
+                if (pm.getType() == ParameterType.PATH) {
+                    List<String> paramValues = params.get(pm.getName());
+                    if (paramValues != null) {
+                        values.addAll(paramValues);
+                    }
+                    
                 }
             }
         }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java?rev=790134&r1=790133&r2=790134&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java Wed Jul  1
12:16:10 2009
@@ -24,6 +24,7 @@
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
@@ -71,6 +72,17 @@
     public Chapter get() {
         return this;
     }
+    
+    @GET
+    @Path("/ids")
+    @Produces("application/xml;charset=ISO-8859-1")
+    public Chapter getWithBookId(@PathParam("bookId") int bookId,
+                                 @PathParam("chapterid") int chapterId) {
+        if (bookId != 123 || chapterId != 1) {
+            throw new RuntimeException();
+        }
+        return this;
+    }
 
     
     @GET

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=790134&r1=790133&r2=790134&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
Wed Jul  1 12:16:10 2009
@@ -487,6 +487,15 @@
     }
     
     @Test
+    public void testGetChapterWithParentIds() throws Exception {
+        
+        getAndCompareAsStrings(
+            "http://localhost:9080/bookstore/booksubresource/123/chapters/sub/1/recurse2/ids",
+            "resources/expected_get_chapter1.txt",
+            "application/xml", "application/xml;charset=iso-8859-1", 200);
+    }
+    
+    @Test
     public void testGetBook123ReturnString() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/booknames/123",
                                "resources/expected_get_book123_returnstring.txt",



Mime
View raw message