Author: sergeyb
Date: Tue Jun 21 11:32:53 2011
New Revision: 1137961
URL: http://svn.apache.org/viewvc?rev=1137961&view=rev
Log:
Merged revisions 1137960 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1137960 | sergeyb | 2011-06-21 12:27:59 +0100 (Tue, 21 Jun 2011) | 1 line
[CXF-3608] Preferring more specific subresource locators to resource methods
........
Modified:
cxf/branches/2.4.x-fixes/ (props changed)
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 21 11:32:53 2011
@@ -1 +1 @@
-/cxf/trunk:1137793
+/cxf/trunk:1137793,1137960
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jun 21 11:32:53 2011
@@ -1 +1 @@
-/cxf/trunk:1-1134023,1134142,1134248,1134281,1134523,1134526,1135106,1135457,1135484,1135899,1136380,1136417,1136837,1136860,1136933,1136942-1136953,1136960,1137509,1137658-1137678,1137793
+/cxf/trunk:1-1134023,1134142,1134248,1134281,1134523,1134526,1135106,1135457,1135484,1135899,1136380,1136417,1136837,1136860,1136933,1136942-1136953,1136960,1137509,1137658-1137678,1137793,1137960
Modified:
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=1137961&r1=1137960&r2=1137961&view=diff
==============================================================================
---
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
(original)
+++
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
Tue Jun 21 11:32:53 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/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1137961&r1=1137960&r2=1137961&view=diff
==============================================================================
---
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Tue Jun 21 11:32:53 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/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java?rev=1137961&r1=1137960&r2=1137961&view=diff
==============================================================================
---
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
(original)
+++
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
Tue Jun 21 11:32:53 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")