cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1137960 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java test/java/org/apache/cxf/jaxrs/resources/TestResource.java
Date Tue, 21 Jun 2011 11:27:59 GMT
Author: sergeyb
Date: Tue Jun 21 11:27:59 2011
New Revision: 1137960

URL: http://svn.apache.org/viewvc?rev=1137960&view=rev
Log:
[CXF-3608] Preferring more specific subresource locators to resource methods

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=1137960&r1=1137959&r2=1137960&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
Tue Jun 21 11:27:59 2011
@@ -53,26 +53,24 @@ public class OperationResourceInfoCompar
             }
         }
         
-        if (e1.getHttpMethod() != null && e2.getHttpMethod() == null
-            || e1.getHttpMethod() == null && e2.getHttpMethod() != null) {
-            // subresource method takes precedence over a subresource locator
-            return e1.getHttpMethod() != null ? -1 : 1;
-        }
-        
         if (headMethod) {
             if (HEAD_METHOD.equals(e1.getHttpMethod())) {
                 return -1;
             } else if (HEAD_METHOD.equals(e2.getHttpMethod())) {
                 return 1;
             }
-                
         }
-
             
         int result = URITemplate.compareTemplates(
                           e1.getURITemplate(),
                           e2.getURITemplate());
         
+        if (result == 0 && (e1.getHttpMethod() != null && e2.getHttpMethod()
== null
+                || e1.getHttpMethod() == null && e2.getHttpMethod() != null)) {
+            // resource method takes precedence over a subresource locator
+            return e1.getHttpMethod() != null ? -1 : 1;
+        }
+        
         if (result == 0) {
         
             result = JAXRSUtils.compareSortedMediaTypes(

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1137960&r1=1137959&r2=1137960&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Tue Jun 21 11:27:59 2011
@@ -211,6 +211,25 @@ public class SelectMethodCandidatesTest 
     
     @Test
     public void testFindTargetSubResource() throws Exception {
+        doTestFindTargetSubResource("/1/2/3/d/resource", "resourceMethod");
+    }
+    
+    @Test
+    public void testFindTargetSubResource2() throws Exception {
+        doTestFindTargetSubResource("/1/2/3/d/resource/sub", "subresource");
+    }
+    
+    @Test
+    public void testFindTargetSubResource3() throws Exception {
+        doTestFindTargetSubResource("/1/2/3/d/resource2/2/2", "resourceMethod2");
+    }
+    
+    @Test
+    public void testFindTargetSubResource4() throws Exception {
+        doTestFindTargetSubResource("/1/2/3/d/resource2/1/2", "subresource2");
+    }
+    
+    public void doTestFindTargetSubResource(String path, String method) throws Exception
{
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.TestResource.class);
         sf.create();
@@ -219,14 +238,14 @@ public class SelectMethodCandidatesTest 
         String acceptContentTypes = "text/xml,*/*";
         
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/resource",
values,
+        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, path, values,
                                                                     new MessageImpl());
         OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource, 
                                     null, 
                                     "GET", values, contentTypes, 
                                     JAXRSUtils.sortMediaTypes(acceptContentTypes), true);
         assertNotNull(ori);
-        assertEquals("resourceMethod needs to be selected", "resourceMethod",
+        assertEquals("resourceMethod needs to be selected", method,
                      ori.getMethodToInvoke().getName());
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java?rev=1137960&r1=1137959&r2=1137960&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
Tue Jun 21 11:27:59 2011
@@ -42,6 +42,18 @@ public class TestResource {
         return "";
     }
     
+    @Path("/resource2/1/{b}")
+    public TestResource subresource2() {
+        return this;
+    }
+    
+    @Path("/resource2/{a}/{b}")
+    @GET
+    @Produces("application/json")
+    public String resourceMethod2() {
+        return "";
+    }
+    
     @GET
     @Produces("application/xml")
     @Path("/resource1")



Mime
View raw message