You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2017/03/27 18:22:14 UTC

[2/2] cxf git commit: [CXF-4821] Find the invoke method on the provider implementation class directly

[CXF-4821] Find the invoke method on the provider implementation class directly


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

Branch: refs/heads/master
Commit: 288e48af0142c43058f96725c50c809f505ffe3b
Parents: 4e5119b
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Mar 27 13:05:00 2017 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Mar 27 14:22:08 2017 -0400

----------------------------------------------------------------------
 .../org/apache/cxf/common/util/ReflectionUtil.java | 17 +++++++++++++++++
 .../org/apache/cxf/jaxws/JAXWSMethodInvoker.java   |  2 +-
 .../cxf/jaxws/JAXWSProviderMethodDispatcher.java   | 14 +++++++++++---
 3 files changed, 29 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/288e48af/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java b/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
index 5e3bea4..d859fbf 100644
--- a/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
+++ b/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
@@ -164,6 +164,23 @@ public final class ReflectionUtil {
             }
         }
     }
+    public static Method getMethod(final Class<?> clazz, final String name,
+                                   final Class<?>... parameterTypes) throws NoSuchMethodException {
+        try {
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
+                public Method run() throws Exception {
+                    return clazz.getMethod(name, parameterTypes);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if (e instanceof NoSuchMethodException) {
+                throw (NoSuchMethodException)e;
+            } else {
+                throw new SecurityException(e);
+            }
+        }
+    }
 
     public static Field[] getDeclaredFields(final Class<?> cls) {
         return AccessController.doPrivileged(new PrivilegedAction<Field[]>() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/288e48af/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
index ae75b36..81d7b97 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
@@ -79,7 +79,7 @@ public class JAXWSMethodInvoker extends AbstractJAXWSMethodInvoker {
         final MessageContext oldCtx = WebServiceContextImpl.setMessageContext(ctx);
         List<Object> res = null;
         try {
-            if ((params == null || params.isEmpty()) && m.getDeclaringClass().equals(Provider.class)) {
+            if ((params == null || params.isEmpty()) && serviceObject instanceof Provider) {
                 params = Collections.singletonList(null);
             }
             res = CastUtils.cast((List<?>)super.invoke(exchange, serviceObject, m, params));

http://git-wip-us.apache.org/repos/asf/cxf/blob/288e48af/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSProviderMethodDispatcher.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSProviderMethodDispatcher.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSProviderMethodDispatcher.java
index dfa323e..8b534e4 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSProviderMethodDispatcher.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSProviderMethodDispatcher.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
 
 import javax.xml.ws.Provider;
 
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
 import org.apache.cxf.service.factory.ServiceConstructionException;
@@ -36,9 +37,16 @@ public class JAXWSProviderMethodDispatcher
 
     public JAXWSProviderMethodDispatcher(JaxWsImplementorInfo implInfo) {
         try {
-            invoke = Provider.class.getMethod("invoke", new Class[] {Object.class});
-        } catch (Exception e) {
-            throw new ServiceConstructionException(e);
+            invoke = ReflectionUtil.getMethod(implInfo.getImplementorClass(), "invoke", 
+                                              new Class[] {implInfo.getProviderParameterType()});
+            ReflectionUtil.setAccessible(invoke);
+        } catch (Exception e1) {
+            //fall back to the raw Provider provided invoke method
+            try {
+                invoke = Provider.class.getMethod("invoke", new Class[] {Object.class});
+            } catch (Exception e) {
+                throw new ServiceConstructionException(e);
+            }
         }
     }