Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3EA0411C7D for ; Wed, 6 Aug 2014 18:13:13 +0000 (UTC) Received: (qmail 83551 invoked by uid 500); 6 Aug 2014 18:13:13 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 83493 invoked by uid 500); 6 Aug 2014 18:13:13 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 83482 invoked by uid 99); 6 Aug 2014 18:13:13 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Aug 2014 18:13:13 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DCB739247F9; Wed, 6 Aug 2014 18:13:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <33d400938c244ed49806cffb92cb8096@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: [CXF-5932] Caching method properties early Date: Wed, 6 Aug 2014 18:13:12 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master b9f47488b -> 0d5ee5483 [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/0d5ee548 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0d5ee548 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0d5ee548 Branch: refs/heads/master Commit: 0d5ee54837b71b2f3c99a6640cd0d80e101859d8 Parents: b9f4748 Author: Sergey Beryozkin Authored: Wed Aug 6 21:12:51 2014 +0300 Committer: Sergey Beryozkin Committed: Wed Aug 6 21:12:51 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/0d5ee548/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 parameters; private boolean oneway; private Set nameBindings = new LinkedHashSet(); - + 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 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/0d5ee548/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 params = new ArrayList(parameterTypes.length); for (int i = 0; i < parameterTypes.length; i++) { http://git-wip-us.apache.org/repos/asf/cxf/blob/0d5ee548/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();