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 Thu, 06 Jul 2017 10:13:01 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 63a97dcaa -> 7deb5b7a6


[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/7deb5b7a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/7deb5b7a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/7deb5b7a

Branch: refs/heads/3.1.x-fixes
Commit: 7deb5b7a69eabd6cd72d095b9a9a08ffd983a892
Parents: 63a97dc
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Jul 5 17:05:13 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Jul 6 11:12:18 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/7deb5b7a/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 32b6243..11b37d1 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/7deb5b7a/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 92da5f2..1cad2c4 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
@@ -315,6 +315,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/7deb5b7a/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 eef353d..f8b07a7 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
@@ -1349,6 +1349,11 @@ public class BookStore {
         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
{
         return getBookSubResource(id);

http://git-wip-us.apache.org/repos/asf/cxf/blob/7deb5b7a/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 c76674f..0cca403 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
@@ -2216,6 +2216,12 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         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);
         wc.accept("application/xml");


Mime
View raw message