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-6623] Support for nested BeanParam
Date Fri, 09 Oct 2015 11:28:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/master c0526a6e5 -> e1cb88a13


[CXF-6623] Support for nested BeanParam


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

Branch: refs/heads/master
Commit: e1cb88a130fb39435695a7c93ea83033d22fffe3
Parents: c0526a6
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Oct 9 12:27:49 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Oct 9 12:27:49 2015 +0100

----------------------------------------------------------------------
 .../jaxrs/provider/ServerProviderFactory.java   | 15 +++++++++++
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  4 +--
 .../cxf/jaxrs/client/ClientProxyImpl.java       | 25 +++++++++++++++---
 .../org/apache/cxf/systest/jaxrs/BookStore.java | 27 ++++++++++++++++++++
 .../jaxrs/JAXRSClientServerBookTest.java        |  5 ++++
 5 files changed, 70 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e1cb88a1/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 077fad5..bd6f7d2 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
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.jaxrs.provider;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -30,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.Priorities;
 import javax.ws.rs.RuntimeType;
 import javax.ws.rs.container.ContainerRequestFilter;
@@ -160,6 +163,18 @@ public final class ServerProviderFactory extends ProviderFactory {
     
     public void addBeanParamInfo(BeanParamInfo bpi) {
         beanParams.put(bpi.getResourceClass(), bpi);
+        for (Method m : bpi.getResourceClass().getMethods()) {
+            if (m.getAnnotation(BeanParam.class) != null) {
+                BeanParamInfo methodBpi = new BeanParamInfo(m.getParameterTypes()[0], getBus());
+                addBeanParamInfo(methodBpi);
+            }
+        }
+        for (Field f : bpi.getResourceClass().getDeclaredFields()) {
+            if (f.getAnnotation(BeanParam.class) != null) {
+                BeanParamInfo fieldBpi = new BeanParamInfo(f.getType(), getBus());
+                addBeanParamInfo(fieldBpi);
+            }
+        }
     }
     
     public BeanParamInfo getBeanParamInfo(Class<?> beanClass) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/e1cb88a1/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index d4d64cd..ab2a55c 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -258,7 +258,7 @@ public final class JAXRSUtils {
                                                      m.getParameterTypes()[0]);
             Object o;
             
-            if (p.getType() == ParameterType.BEAN && bri instanceof ClassResourceInfo)
{
+            if (p.getType() == ParameterType.BEAN) {
                 o = createBeanParamValue(message, m.getParameterTypes()[0], ori);    
             } else {
                 o = createHttpParameterValue(p, 
@@ -277,7 +277,7 @@ public final class JAXRSUtils {
                                                      f.getType());
             Object o = null;
             
-            if (p.getType() == ParameterType.BEAN && bri instanceof ClassResourceInfo)
{
+            if (p.getType() == ParameterType.BEAN) {
                 o = createBeanParamValue(message, f.getType(), ori);    
             } else {
                 o = createHttpParameterValue(p, 

http://git-wip-us.apache.org/repos/asf/cxf/blob/e1cb88a1/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index 6edd18e..0651b73 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -39,6 +39,7 @@ import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.CookieParam;
 import javax.ws.rs.FormParam;
 import javax.ws.rs.HeaderParam;
@@ -485,18 +486,29 @@ public class ClientProxyImpl extends AbstractClient implements
     
     private Map<String, BeanPair> getValuesFromBeanParam(Object bean, Class<? extends
Annotation> annClass) {
         Map<String, BeanPair> values = new HashMap<String, BeanPair>();
-        
+        getValuesFromBeanParam(bean, annClass, values);
+        return values;
+    }
+    
+    private Map<String, BeanPair> getValuesFromBeanParam(Object bean, 
+                                                         Class<? extends Annotation>
annClass,
+                                                         Map<String, BeanPair> values)
{
         for (Method m : bean.getClass().getMethods()) {
             if (m.getName().startsWith("set")) {
                 try {
                     String propertyName = m.getName().substring(3);
                     Annotation annotation = m.getAnnotation(annClass);
-                    if (annotation != null) {
+                    boolean beanParam = m.getAnnotation(BeanParam.class) != null;
+                    if (annotation != null || beanParam) {
                         Method getter = bean.getClass().getMethod("get" + propertyName, new
Class[]{});
                         Object value = getter.invoke(bean, new Object[]{});
                         if (value != null) {
-                            String annotationValue = AnnotationUtils.getAnnotationValue(annotation);
-                            values.put(annotationValue, new BeanPair(value, m.getParameterAnnotations()[0]));
+                            if (annotation != null) {
+                                String annotationValue = AnnotationUtils.getAnnotationValue(annotation);
+                                values.put(annotationValue, new BeanPair(value, m.getParameterAnnotations()[0]));
+                            } else {
+                                getValuesFromBeanParam(value, annClass, values);
+                            }
                         }
                     } else {
                         String fieldName = StringUtils.uncapitalize(propertyName);
@@ -511,6 +523,11 @@ public class ClientProxyImpl extends AbstractClient implements
                                 String annotationValue = AnnotationUtils.getAnnotationValue(annotation);
                                 values.put(annotationValue, new BeanPair(value, f.getAnnotations()));
                             }    
+                        } else if (f.getAnnotation(BeanParam.class) != null) {
+                            Object value = ReflectionUtil.accessDeclaredField(f, bean, Object.class);
+                            if (value != null) {
+                                getValuesFromBeanParam(value, annClass, values);
+                            }
                         }
                     }
                 } catch (Throwable t) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/e1cb88a1/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 5e957b6..757afad 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
@@ -335,6 +335,10 @@ public class BookStore {
     public Book getBeanParamBook(@BeanParam BookBean bean) {
         
         long id = bean.getId() + bean.getId2() + bean.getId3(); 
+        if (bean.getNested().getId4() != id) {
+            throw new RuntimeException();
+        }
+        
         
         return books.get(id);
     }
@@ -1751,6 +1755,7 @@ public class BookStore {
         @QueryParam("id_2")
         private long id2;
         private long id3;
+        private BookBeanNested nested;
 
         public long getId() {
             return id;
@@ -1781,6 +1786,28 @@ public class BookStore {
             return id3;
         }
 
+        public BookBeanNested getNested() {
+            return nested;
+        }
+
+        @BeanParam
+        public void setNested(BookBeanNested nested) {
+            this.nested = nested;
+        }
+
+        
+    }
+    
+    public static class BookBeanNested {
+        private long id4;
+
+        public long getId4() {
+            return id4;
+        }
+        @QueryParam("id4")
+        public void setId4(long id4) {
+            this.id4 = id4;
+        }
         
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/e1cb88a1/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 9109acf..dd6b4fe 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
@@ -389,6 +389,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         wc.path("100");
         wc.query("id_2", "20");
         wc.query("id3", "3");
+        wc.query("id4", "123");
         Book book = wc.get(Book.class);
         assertEquals(123L, book.getId());
     }
@@ -452,9 +453,13 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     @Test
     public void testProxyBeanParam() throws Exception {
         BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        WebClient.getConfig(store).getHttpConduit().getClient().setReceiveTimeout(10000000L);
         BookStore.BookBean bean = new BookStore.BookBean();
         bean.setId(100L);
         bean.setId2(23L);
+        BookStore.BookBeanNested nested = new BookStore.BookBeanNested();
+        nested.setId4(123);
+        bean.setNested(nested);
                 
         Book book = store.getBeanParamBook(bean);
         assertEquals(123L, book.getId());


Mime
View raw message