Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 1d20b412a -> ca40783c0


[CXF-5932] Caching method properties early


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

Branch: refs/heads/3.0.x-fixes
Commit: ca40783c03222f52dcea0c5410ea67bea400224e
Parents: 1d20b41
Author: Sergey Beryozkin <[email protected]>
Authored: Wed Aug 6 21:12:51 2014 +0300
Committer: Sergey Beryozkin <[email protected]>
Committed: Wed Aug 6 21:14:18 2014 +0300

----------------------------------------------------------------------
 .../cxf/jaxrs/model/OperationResourceInfo.java  | 58 +++++++++++++++-----
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  9 +--
 .../apache/cxf/jaxrs/utils/JAXRSUtilsTest.java  | 10 +++-
 3 files changed, 53 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ca40783c/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
----------------------------------------------------------------------
diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
index c9c9ac1..9889084 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.model;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -49,7 +50,11 @@ public class OperationResourceInfo {
     private List<Parameter> parameters;
     private boolean oneway; 
     private Set<String> nameBindings = new LinkedHashSet<String>();
-
+    private Class<?>[] actualInParamTypes;
+    private Type[] actualInGenericParamTypes;
+    private Annotation[][] actualInParamAnnotations;
+    private Annotation[] actualOutParamAnnotations;
+    
     public OperationResourceInfo(Method mInvoke, ClassResourceInfo cri) {
         this(mInvoke, mInvoke, cri);
     }
@@ -67,6 +72,7 @@ public class OperationResourceInfo {
         this.oneway = ori.oneway;
         this.classResourceInfo = cri;
         this.nameBindings = ori.nameBindings;
+        initActualMethodProperties();
     }
     
     public OperationResourceInfo(Method mInvoke, Method mAnnotated, 
ClassResourceInfo cri) {
@@ -81,6 +87,7 @@ public class OperationResourceInfo {
         checkEncoded();
         checkDefaultParameterValue();
         checkOneway();
+        initActualMethodProperties();
     }
     
     //CHECKSTYLE:OFF
@@ -101,6 +108,30 @@ public class OperationResourceInfo {
         checkMediaTypes(consumeMediaTypes, produceMediaTypes);
         parameters = params;
         this.oneway = oneway;
+        initActualMethodProperties();
+    }
+    
+    private void initActualMethodProperties() {
+        Method actualMethod = annotatedMethod == null ? methodToInvoke : 
annotatedMethod;
+        actualInParamTypes = actualMethod.getParameterTypes();
+        actualInGenericParamTypes = actualMethod.getGenericParameterTypes();
+        actualInParamAnnotations = actualMethod.getParameterAnnotations();
+        
+        // out annotations
+        Annotation[] invokedAnns = methodToInvoke.getAnnotations();
+        if (methodToInvoke != annotatedMethod && annotatedMethod != null) {
+            Annotation[] superAnns = annotatedMethod.getAnnotations();
+            if (invokedAnns.length > 0) {
+                Annotation[] merged = new Annotation[superAnns.length + 
invokedAnns.length];
+                System.arraycopy(superAnns, 0, merged, 0, superAnns.length);
+                System.arraycopy(invokedAnns, 0, merged, superAnns.length, 
invokedAnns.length);
+                actualOutParamAnnotations = merged;
+            } else {
+                actualOutParamAnnotations = superAnns;
+            }
+        } else {
+            actualOutParamAnnotations = invokedAnns;
+        }
     }
     
     public void addNameBindings(List<String> names) {
@@ -236,20 +267,17 @@ public class OperationResourceInfo {
             defaultParamValue = dv.value();
         }
     }
+    public Annotation[][] getInParameterAnnotations() {
+        return actualInParamAnnotations;
+    }
+    public Type[] getInGenericParameterTypes() {
+        return actualInGenericParamTypes;
+    }
+    public Class<?>[] getInParameterTypes() {
+        return actualInParamTypes;
+    }
     public Annotation[] getOutAnnotations() {
-        Annotation[] invokedAnns = methodToInvoke.getAnnotations();
-        if (methodToInvoke != annotatedMethod && annotatedMethod != null) {
-            Annotation[] superAnns = annotatedMethod.getAnnotations();
-            if (invokedAnns.length > 0) {
-                Annotation[] merged = new Annotation[superAnns.length + 
invokedAnns.length];
-                System.arraycopy(superAnns, 0, merged, 0, superAnns.length);
-                System.arraycopy(invokedAnns, 0, merged, superAnns.length, 
invokedAnns.length);
-                return merged;
-            } else {
-                return superAnns;
-            }
-        } else {
-            return invokedAnns;
-        }
+        return actualOutParamAnnotations;
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ca40783c/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 7f4d1f8..d84c00e 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
@@ -758,15 +758,12 @@ public final class JAXRSUtils {
         throws IOException, WebApplicationException {
         
         
-        Method method = ori.getMethodToInvoke();
-        Method annotatedMethod = ori.getAnnotatedMethod();
-        Method actualMethod = annotatedMethod == null ? method : 
annotatedMethod;
         
-        Class<?>[] parameterTypes = actualMethod.getParameterTypes();
+        Class<?>[] parameterTypes = ori.getInParameterTypes();
         Parameter[] paramsInfo = ori.getParameters().toArray(new 
Parameter[ori.getParameters().size()]);  
         
-        Type[] genericParameterTypes = actualMethod.getGenericParameterTypes();
-        Annotation[][] anns = actualMethod.getParameterAnnotations();
+        Type[] genericParameterTypes = ori.getInGenericParameterTypes();
+        Annotation[][] anns = ori.getInParameterAnnotations();
         List<Object> params = new ArrayList<Object>(parameterTypes.length);
 
         for (int i = 0; i < parameterTypes.length; i++) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/ca40783c/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
----------------------------------------------------------------------
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
index 1e740a9..614a536 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
@@ -1730,7 +1730,8 @@ public class JAXRSUtilsTest extends Assert {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         cri.setResourceProvider(new 
PerRequestResourceProvider(Customer.class));
-        OperationResourceInfo ori = new OperationResourceInfo(null, cri);
+        OperationResourceInfo ori = new 
OperationResourceInfo(Customer.class.getMethod("postConstruct", 
+                                                                               
        new Class[]{}), cri);
         
         Customer c = new Customer();
         
@@ -1919,7 +1920,8 @@ public class JAXRSUtilsTest extends Assert {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         cri.setResourceProvider(new 
PerRequestResourceProvider(Customer.class));
-        OperationResourceInfo ori = new OperationResourceInfo(null, cri);
+        OperationResourceInfo ori = new 
OperationResourceInfo(Customer.class.getMethod("postConstruct", 
+                                                                               
        new Class[]{}), cri);
         
         Message m = createMessage();
         HttpServletResponse response = 
EasyMock.createMock(HttpServletResponse.class);
@@ -1938,7 +1940,9 @@ public class JAXRSUtilsTest extends Assert {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         cri.setResourceProvider(new 
PerRequestResourceProvider(Customer.class));
-        OperationResourceInfo ori = new OperationResourceInfo(null, cri);
+        OperationResourceInfo ori = new 
OperationResourceInfo(Customer.class.getMethod("postConstruct", 
+                                                                               
        new Class[]{}), 
+                                                              cri);
         
         Customer c = new Customer();
         

Reply via email to