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-7017] Supporting BeanParam in subresources
Date Thu, 25 Aug 2016 16:08:34 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes ac6934471 -> 9ca732471


[CXF-7017] Supporting BeanParam in subresources


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

Branch: refs/heads/3.1.x-fixes
Commit: 9ca732471f228fa5c2dfaac8af3cf21d05227780
Parents: ac69344
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Aug 25 17:06:43 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Aug 25 17:08:11 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/model/ClassResourceInfo.java      | 48 +++++++++++---------
 .../jaxrs/provider/ServerProviderFactory.java   |  3 +-
 .../org/apache/cxf/systest/jaxrs/BookStore.java | 24 +++++++++-
 .../jaxrs/JAXRSClientServerBookTest.java        |  6 +++
 4 files changed, 57 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9ca73247/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
index 67959d2..61e240b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
@@ -136,13 +136,12 @@ public class ClassResourceInfo extends BeanResourceInfo {
     }
     
     public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass)
{
-        instanceClass = enableStatic ? typedClass : instanceClass;
         return getSubResource(typedClass, instanceClass, null, enableStatic, null);
     }
     
     public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass,
Object instance) {
         instanceClass = enableStatic ? typedClass : instanceClass;
-        return getSubResource(typedClass, instanceClass, instance, enableStatic, null);
+        return getSubResource(typedClass, instanceClass, instance, enableStatic, JAXRSUtils.getCurrentMessage());
     }
     
     public ClassResourceInfo getSubResource(Class<?> typedClass, 
@@ -157,6 +156,9 @@ public class ClassResourceInfo extends BeanResourceInfo {
             cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, this,
false, resolveContexts,
                                                         getBus());
             if (cri != null) {
+                if (message != null) {
+                    cri.initBeanParamInfo(ServerProviderFactory.getInstance(message));
+                }
                 subResources.putIfAbsent(key, cri);
             }
         }
@@ -297,29 +299,31 @@ public class ClassResourceInfo extends BeanResourceInfo {
     }
     
     public void initBeanParamInfo(ServerProviderFactory factory) {
-        Set<OperationResourceInfo> oris = getMethodDispatcher().getOperationResourceInfos();
-        for (OperationResourceInfo ori : oris) {
-            List<Parameter> params = ori.getParameters();
-            for (Parameter param : params) {
-                if (param.getType() == ParameterType.BEAN) {
-                    Class<?> cls = ori.getMethodToInvoke().getParameterTypes()[param.getIndex()];
-                    BeanParamInfo bpi = new BeanParamInfo(cls, getBus());
-                    factory.addBeanParamInfo(bpi);
+        if (factory != null) {
+            Set<OperationResourceInfo> oris = getMethodDispatcher().getOperationResourceInfos();
+            for (OperationResourceInfo ori : oris) {
+                List<Parameter> params = ori.getParameters();
+                for (Parameter param : params) {
+                    if (param.getType() == ParameterType.BEAN) {
+                        Class<?> cls = ori.getMethodToInvoke().getParameterTypes()[param.getIndex()];
+                        BeanParamInfo bpi = new BeanParamInfo(cls, getBus());
+                        factory.addBeanParamInfo(bpi);
+                    }
                 }
             }
-        }
-        List<Method> methods =  super.getParameterMethods();
-        for (Method m : methods) {
-            if (m.getAnnotation(BeanParam.class) != null) {
-                BeanParamInfo bpi = new BeanParamInfo(m.getParameterTypes()[0], getBus());
-                factory.addBeanParamInfo(bpi);
+            List<Method> methods =  super.getParameterMethods();
+            for (Method m : methods) {
+                if (m.getAnnotation(BeanParam.class) != null) {
+                    BeanParamInfo bpi = new BeanParamInfo(m.getParameterTypes()[0], getBus());
+                    factory.addBeanParamInfo(bpi);
+                }
             }
-        }
-        List<Field> fields = super.getParameterFields();
-        for (Field f : fields) {
-            if (f.getAnnotation(BeanParam.class) != null) {
-                BeanParamInfo bpi = new BeanParamInfo(f.getType(), getBus());
-                factory.addBeanParamInfo(bpi);
+            List<Field> fields = super.getParameterFields();
+            for (Field f : fields) {
+                if (f.getAnnotation(BeanParam.class) != null) {
+                    BeanParamInfo bpi = new BeanParamInfo(f.getType(), getBus());
+                    factory.addBeanParamInfo(bpi);
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/9ca73247/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
index 97311af..8354f13 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
@@ -31,6 +31,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.BeanParam;
 import javax.ws.rs.Priorities;
@@ -91,7 +92,7 @@ public final class ServerProviderFactory extends ProviderFactory {
     private ApplicationInfo application;
     private Set<DynamicFeature> dynamicFeatures = new LinkedHashSet<DynamicFeature>();
     
-    private Map<Class<?>, BeanParamInfo> beanParams = new HashMap<Class<?>,
BeanParamInfo>();
+    private Map<Class<?>, BeanParamInfo> beanParams = new ConcurrentHashMap<Class<?>,
BeanParamInfo>();
     private ProviderInfo<ContainerRequestFilter> wadlGenerator;
         
     private ServerProviderFactory(Bus bus) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/9ca73247/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 c3c9683..6e9c6c4 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
@@ -111,6 +111,7 @@ import org.junit.Assert;
 @Path("/bookstore")
 @GZIP(threshold = 1)
 public class BookStore {
+    
     private Map<Long, Book> books = new HashMap<Long, Book>();
     private Map<Long, CD> cds = new HashMap<Long, CD>();
     private long bookId = 123;
@@ -352,6 +353,11 @@ public class BookStore {
         return books.get(id);
     }
     
+    @Path("/beanparamsub")
+    public BookStoreSub getBeanParamBookSub() {
+        return new BookStoreSub(this);
+    }
+    
     @GET
     @Path("/twoBeanParams/{id}")
     @Produces("application/xml")
@@ -1839,6 +1845,10 @@ public class BookStore {
         
     }
     
+    public static class BookBeanExtended extends BookBean {
+        
+    }
+    
     public static class BookBeanNested {
         private long id4;
 
@@ -2046,7 +2056,19 @@ public class BookStore {
             arg6.write(sb.toString().getBytes());
         }
     
-    }    
+    }
+    public static class BookStoreSub {
+        BookStore bookStore;
+        public BookStoreSub(BookStore bookStore) {
+            this.bookStore = bookStore;
+        }
+        @GET
+        @Path("/beanparam/{id}")
+        @Produces("application/xml")
+        public Book getBeanParamBook(@BeanParam BookBeanExtended bean) {
+            return bookStore.getBeanParamBook(bean);
+        }
+    }
 }
 
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/9ca73247/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 648c1ca..8726685 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
@@ -394,6 +394,12 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testUseParamBeanWebClientSubResource() {
+        String address = "http://localhost:" + PORT + "/bookstore/beanparamsub/beanparam";
+        doTestUseParamBeanWebClient(address);
+    }
+    
+    @Test
     public void testUseParamBeanWebClient2() {
         String address = "http://localhost:" + PORT + "/bookstore/beanparam2";
         doTestUseParamBeanWebClient(address);


Mime
View raw message