cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7419] Supporting subsesource locators returning classes
Date Wed, 05 Jul 2017 16:05:28 GMT
Repository: cxf
Updated Branches:
  refs/heads/master cb607e912 -> 4e46cb7d8


[CXF-7419] Supporting subsesource locators returning classes


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4e46cb7d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4e46cb7d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4e46cb7d

Branch: refs/heads/master
Commit: 4e46cb7d8d4ccb47aeff85b5b2804728ea4b736d
Parents: cb607e9
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Jul 5 17:05:13 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Jul 5 17:05:13 2017 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java   | 13 ++++++++++++-
 .../java/org/apache/cxf/jaxrs/utils/ResourceUtils.java |  3 +++
 .../java/org/apache/cxf/systest/jaxrs/BookStore.java   |  5 +++++
 .../cxf/systest/jaxrs/JAXRSClientServerBookTest.java   |  6 ++++++
 4 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/4e46cb7d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
index b002f50..c0ca2ff 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.ResourceContext;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -45,6 +46,7 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.InterceptorChain.State;
 import org.apache.cxf.jaxrs.impl.AsyncResponseImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -224,7 +226,16 @@ public class JAXRSInvoker extends AbstractInvoker {
 
                 result = checkResultObject(result, subResourcePath);
 
-                subCri = cri.getSubResource(methodToInvoke.getReturnType(),
+                Class<?> subResponseType = null;
+                if (result.getClass() == Class.class) {
+                    ResourceContext rc = new ResourceContextImpl(inMessage, ori);
+                    result = rc.getResource((Class<?>)result);
+                    subResponseType = InjectionUtils.getActualType(methodToInvoke.getGenericReturnType());
+                } else {
+                    subResponseType = methodToInvoke.getReturnType();
+                }
+                
+                subCri = cri.getSubResource(subResponseType,
                     ClassHelper.getRealClass(exchange.getBus(), result), result);
                 if (subCri == null) {
                     org.apache.cxf.common.i18n.Message errorM =

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e46cb7d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index 40d9780..31b38a5 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -316,6 +316,9 @@ public final class ResourceUtils {
                 if (httpMethod == null) {
                     // subresource locator
                     Class<?> subClass = m.getReturnType();
+                    if (subClass == Class.class) {
+                        subClass = InjectionUtils.getActualType(m.getGenericReturnType());
+                    }
                     if (enableStatic) {
                         ClassResourceInfo subCri = cri.findResource(subClass, subClass);
                         if (subCri == null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e46cb7d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index ff7a84b..38b8da9 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -1348,6 +1348,11 @@ public class BookStore {
     public Book2 getBookSubResourceInstanceRC(@Context ResourceContext rc) {
         return rc.initResource(book2Sub);
     }
+    
+    @Path("/booksubresource/class/context")
+    public Class<Book2> getBookSubResourceClass() {
+        return Book2.class;
+    }
 
     @Path("/booksubresourceobject/{bookId}/")
     public Object getBookSubResourceObject(@PathParam("bookId") String id) throws BookNotFoundFault
{

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e46cb7d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index b0ec144..d551e81 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -2215,6 +2215,12 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         String address = "http://localhost:" + PORT + "/bookstore/booksubresource/instance/context/rc";
         doTestGetBookWithResourceContext(address);
     }
+    
+    @Test
+    public void testGetBookWithResourceContextClass() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/booksubresource/class/context/rc";
+        doTestGetBookWithResourceContext(address);
+    }
 
     private void doTestGetBookWithResourceContext(String address) throws Exception {
         WebClient wc = WebClient.create(address);


Mime
View raw message