cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [06/33] cxf git commit: Updating WADLGenerator to check BeanParam fields too
Date Sun, 05 Jun 2016 17:02:34 GMT
Updating WADLGenerator to check BeanParam fields too


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

Branch: refs/heads/master-jaxrs-2.1
Commit: 847e00fe7b438a70f25694d02bca614ad6c0ec55
Parents: 32ca726
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue May 31 12:57:28 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue May 31 12:57:28 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/utils/InjectionUtils.java  | 12 ++++++++
 .../cxf/jaxrs/client/ClientProxyImpl.java       | 13 +--------
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 29 +++++++++++++++++++-
 .../apache/cxf/jaxrs/model/wadl/BookStore.java  |  2 +-
 4 files changed, 42 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/847e00fe/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index fa42c6f..2414476 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
@@ -72,6 +72,7 @@ import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.common.util.PrimitiveUtils;
 import org.apache.cxf.common.util.ProxyClassLoader;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
@@ -113,6 +114,17 @@ public final class InjectionUtils {
         
     }
 
+    public static Field getDeclaredField(Class<?> cls, String fieldName) {
+        if (cls == null || cls == Object.class) {
+            return null;
+        }
+        Field f = ReflectionUtil.getDeclaredField(cls, fieldName);
+        if (f != null) {
+            return f;
+        }
+        return getDeclaredField(cls.getSuperclass(), fieldName);
+    }
+    
     public static boolean isConcreteClass(Class<?> cls) {
         return !cls.isInterface() && !Modifier.isAbstract(cls.getModifiers());
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/847e00fe/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 4f25895..4f56836 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
@@ -534,7 +534,7 @@ public class ClientProxyImpl extends AbstractClient implements
                         }
                     } else {
                         String fieldName = StringUtils.uncapitalize(propertyName);
-                        Field f = getDeclaredField(bean.getClass(), fieldName);
+                        Field f = InjectionUtils.getDeclaredField(bean.getClass(), fieldName);
                         if (f == null) {
                             continue;
                         }
@@ -560,17 +560,6 @@ public class ClientProxyImpl extends AbstractClient implements
         return values;
     }
     
-    private static Field getDeclaredField(Class<?> cls, String fieldName) {
-        if (cls == null || cls == Object.class) {
-            return null;
-        }
-        Field f = ReflectionUtil.getDeclaredField(cls, fieldName);
-        if (f != null) {
-            return f;
-        }
-        return getDeclaredField(cls.getSuperclass(), fieldName);
-    }
-    
     private void handleMatrixes(Method m,
                                 Object[] params,
                                 MultivaluedMap<ParameterType, Parameter> map,

http://git-wip-us.apache.org/repos/asf/cxf/blob/847e00fe/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 02f03b2..14d323b 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -49,6 +49,7 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Logger;
 
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.FormParam;
@@ -831,11 +832,13 @@ public class WadlGenerator implements ContainerRequestFilter {
                                        ParameterType ...parameterTypes) {
         for (Method m : beanType.getMethods()) {
             if (m.getName().startsWith("set")) {
+                String propertyName = StringUtils.uncapitalize(m.getName().substring(3));
+                Field f = InjectionUtils.getDeclaredField(beanType, propertyName);
+                
                 for (ParameterType parameterType : parameterTypes) {
                     Class<? extends Annotation> annClass = getAnnotationFromParamType(parameterType);
                     Annotation annotation = m.getAnnotation(annClass);
                     if (annotation != null) {
-                        String propertyName = StringUtils.uncapitalize(m.getName().substring(3));
                         Parameter pm = new Parameter(parameterType, propertyName);
                         pm.setEncoded(m.getAnnotation(Encoded.class) != null);
                         DefaultValue dv = m.getAnnotation(DefaultValue.class);
@@ -850,12 +853,36 @@ public class WadlGenerator implements ContainerRequestFilter {
                                      propertyName,
                                      new Annotation[]{}, 
                                      isJson);
+                    } else if (f != null) {
+                        annotation = f.getAnnotation(annClass);
+                        if (annotation != null) {
+                            Parameter pm = new Parameter(parameterType, propertyName);
+                            pm.setEncoded(f.getAnnotation(Encoded.class) != null);
+                            DefaultValue dv = f.getAnnotation(DefaultValue.class);
+                            if (dv != null) {
+                                pm.setDefaultValue(dv.value());
+                            }
+                            doWriteParam(ori,
+                                         sb,
+                                         pm, 
+                                         f.getType(), 
+                                         f.getGenericType(), 
+                                         propertyName,
+                                         new Annotation[]{}, 
+                                         isJson);
+                        }
                         
                     }
                 }
+                if (m.getAnnotation(BeanParam.class) != null) {
+                    doWriteJaxrsBeanParam(sb, ori, m.getParameterTypes()[0], isJson, parameterTypes);
+                } else if (f != null && f.getAnnotation(BeanParam.class) != null)
{
+                    doWriteJaxrsBeanParam(sb, ori, f.getType(), isJson, parameterTypes);
+                }
             }
         }
     }
+    
     private Class<? extends Annotation> getAnnotationFromParamType(ParameterType pt)
{
         return PARAMETER_TYPE_MAP.get(pt);
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/847e00fe/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
index 1db729c..2414ed0 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
@@ -179,6 +179,7 @@ public class BookStore extends AbstractStore<Book> implements BookDescription
{
     
     public static class TheBeanParam {
         private int a;
+        @QueryParam("b")
         private int b;
         public int getA() {
             return a;
@@ -190,7 +191,6 @@ public class BookStore extends AbstractStore<Book> implements BookDescription
{
         public int getB() {
             return b;
         }
-        @QueryParam("b")
         public void setB(int bb) {
             this.b = bb;
         }


Mime
View raw message