Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 449e39521 -> 6b2066573


[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/a6b87b4d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a6b87b4d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a6b87b4d

Branch: refs/heads/3.1.x-fixes
Commit: a6b87b4d8b1c6a35493732611bc9e71fb7a052a0
Parents: 449e395
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:56 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/a6b87b4d/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 6b41895..3684d6b 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/a6b87b4d/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 8c56fbc..bc5cd59 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/a6b87b4d/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 841f82c..40be623 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);
+            }
         }
     }
 

Reply via email to