Author: jochen
Date: Fri Jul 14 00:22:02 2006
New Revision: 421821
URL: http://svn.apache.org/viewvc?rev=421821&view=rev
Log:
ReflectiveXmlRpcHandler.execute fails to properly lookup method
PR: XMLRPC-94
Submitted-by: Chris Conrad, [EMAIL PROTECTED]
Modified:
webservices/xmlrpc/trunk/pom.xml
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
webservices/xmlrpc/trunk/src/changes/changes.xml
Modified: webservices/xmlrpc/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/pom.xml?rev=421821&r1=421820&r2=421821&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/pom.xml (original)
+++ webservices/xmlrpc/trunk/pom.xml Fri Jul 14 00:22:02 2006
@@ -124,6 +124,10 @@
<email>[EMAIL PROTECTED]</email>
</contributor>
<contributor>
+ <name>Chris Conrad</name>
+ <email>[EMAIL PROTECTED]</email>
+ </contributor>
+ <contributor>
<name>Brad Karp</name>
<email>[EMAIL PROTECTED]</email>
</contributor>
Modified:
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java?rev=421821&r1=421820&r2=421821&view=diff
==============================================================================
---
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
(original)
+++
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
Fri Jul 14 00:22:02 2006
@@ -1,161 +1,161 @@
-/*
- * Copyright 1999,2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.xmlrpc.server;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.XmlRpcHandler;
-import org.apache.xmlrpc.XmlRpcRequest;
-import org.apache.xmlrpc.common.TypeConverter;
-import org.apache.xmlrpc.common.TypeConverterFactory;
-import org.apache.xmlrpc.common.XmlRpcNotAuthorizedException;
-import org.apache.xmlrpc.metadata.Util;
-import
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
-import
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.InitializationHandler;
-
-
-/** Default implementation of [EMAIL PROTECTED] XmlRpcHandler}.
- */
-public class ReflectiveXmlRpcHandler implements XmlRpcHandler {
- private static class MethodData {
- final Method method;
- final TypeConverter[] typeConverters;
- MethodData(Method pMethod, TypeConverterFactory pTypeConverterFactory)
{
- method = pMethod;
- Class[] paramClasses = method.getParameterTypes();
- typeConverters = new TypeConverter[paramClasses.length];
- for (int i = 0; i < paramClasses.length; i++) {
- typeConverters[i] =
pTypeConverterFactory.getTypeConverter(paramClasses[i]);
- }
- }
- }
- private final AbstractReflectiveHandlerMapping mapping;
- private final Class clazz;
- private final MethodData[] methods;
- private final Object theInstance;
-
- /** Creates a new instance.
- * @param pMapping The mapping, which creates this handler.
- * @param pClass The class, which has been inspected to create
- * this handler. Typically, this will be the same as
- * <pre>pInstance.getClass()</pre>. It is used for diagnostic
- * messages only.
- * @param pInstanceIsStateless The handler
- * can operate in either of two operation modes:
- * <ol>
- * <li>The object, which is actually performing the requests,
- * is initialized at startup. In other words, there is only
- * one object, which is performing all the requests.
- * Obviously, this is the faster operation mode. On the
- * other hand, it has the disadvantage, that the object
- * must be stateless.</li>
- * <li>A new object is created for any request. This is slower,
- * because the object needs to be initialized. On the other
- * hand, it allows for stateful objects, which may take
- * request specific configuration like the clients IP address,
- * and the like.</li>
- * </ol>
- * @param pMethods The method, which will be invoked for
- * executing the handler.
- */
- public ReflectiveXmlRpcHandler(AbstractReflectiveHandlerMapping
pMapping,
- TypeConverterFactory pTypeConverterFactory,
- Class pClass, boolean pInstanceIsStateless,
Method[] pMethods)
- throws XmlRpcException {
- mapping = pMapping;
- clazz = pClass;
- methods = new MethodData[pMethods.length];
- for (int i = 0; i < methods.length; i++) {
- methods[i] = new MethodData(pMethods[i], pTypeConverterFactory);
- }
- theInstance = pInstanceIsStateless ? newInstance() : null;
- }
-
- private Object getInstance(XmlRpcRequest pRequest) throws XmlRpcException {
- final InitializationHandler ih = mapping.getInitializationHandler();
- if (ih == null) {
- return theInstance == null ? newInstance() : theInstance;
- } else {
- final Object instance = newInstance();
- ih.init(pRequest, instance);
- return instance;
- }
- }
-
- public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
- AuthenticationHandler authHandler =
mapping.getAuthenticationHandler();
- if (authHandler != null && !authHandler.isAuthorized(pRequest)) {
- throw new XmlRpcNotAuthorizedException("Not authorized");
- }
- Object[] args = new Object[pRequest.getParameterCount()];
- for (int j = 0; j < args.length; j++) {
- args[j] = pRequest.getParameter(j);
- }
- Object instance = getInstance(pRequest);
- for (int i = 0; i < methods.length; i++) {
- MethodData methodData = methods[i];
- TypeConverter[] converters = methodData.typeConverters;
- if (args.length == converters.length) {
- boolean matching = true;
- for (int j = 0; j < args.length; j++) {
- if (!converters[j].isConvertable(args[i])) {
- matching = false;
- break;
- }
- }
- if (matching) {
- for (int j = 0; j < args.length; j++) {
- args[i] = converters[i].convert(args[i]);
- }
- return invoke(instance, methodData.method, args);
- }
- }
- }
- throw new XmlRpcException("No method matching arguments: " +
Util.getSignature(args));
- }
-
- private Object invoke(Object pInstance, Method pMethod, Object[] pArgs)
throws XmlRpcException {
- try {
- return pMethod.invoke(pInstance, pArgs);
- } catch (IllegalAccessException e) {
- throw new XmlRpcException("Illegal access to method "
- + pMethod.getName() + " in class "
- + clazz.getName(), e);
- } catch (IllegalArgumentException e) {
- throw new XmlRpcException("Illegal argument for method "
- + pMethod.getName() + " in class "
- + clazz.getName(), e);
- } catch (InvocationTargetException e) {
- Throwable t = e.getTargetException();
- throw new XmlRpcException("Failed to invoke method "
- + pMethod.getName() + " in class "
- + clazz.getName() + ": "
- + t.getMessage(), t);
- }
- }
-
- protected Object newInstance() throws XmlRpcException {
- try {
- return clazz.newInstance();
- } catch (InstantiationException e) {
- throw new XmlRpcException("Failed to instantiate class " +
clazz.getName(), e);
- } catch (IllegalAccessException e) {
- throw new XmlRpcException("Illegal access when instantiating class
" + clazz.getName(), e);
- }
- }
-}
\ No newline at end of file
+/*
+ * Copyright 1999,2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xmlrpc.server;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcHandler;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.common.TypeConverter;
+import org.apache.xmlrpc.common.TypeConverterFactory;
+import org.apache.xmlrpc.common.XmlRpcNotAuthorizedException;
+import org.apache.xmlrpc.metadata.Util;
+import
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
+import
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.InitializationHandler;
+
+
+/** Default implementation of [EMAIL PROTECTED] XmlRpcHandler}.
+ */
+public class ReflectiveXmlRpcHandler implements XmlRpcHandler {
+ private static class MethodData {
+ final Method method;
+ final TypeConverter[] typeConverters;
+ MethodData(Method pMethod, TypeConverterFactory pTypeConverterFactory)
{
+ method = pMethod;
+ Class[] paramClasses = method.getParameterTypes();
+ typeConverters = new TypeConverter[paramClasses.length];
+ for (int i = 0; i < paramClasses.length; i++) {
+ typeConverters[i] =
pTypeConverterFactory.getTypeConverter(paramClasses[i]);
+ }
+ }
+ }
+ private final AbstractReflectiveHandlerMapping mapping;
+ private final Class clazz;
+ private final MethodData[] methods;
+ private final Object theInstance;
+
+ /** Creates a new instance.
+ * @param pMapping The mapping, which creates this handler.
+ * @param pClass The class, which has been inspected to create
+ * this handler. Typically, this will be the same as
+ * <pre>pInstance.getClass()</pre>. It is used for diagnostic
+ * messages only.
+ * @param pInstanceIsStateless The handler
+ * can operate in either of two operation modes:
+ * <ol>
+ * <li>The object, which is actually performing the requests,
+ * is initialized at startup. In other words, there is only
+ * one object, which is performing all the requests.
+ * Obviously, this is the faster operation mode. On the
+ * other hand, it has the disadvantage, that the object
+ * must be stateless.</li>
+ * <li>A new object is created for any request. This is slower,
+ * because the object needs to be initialized. On the other
+ * hand, it allows for stateful objects, which may take
+ * request specific configuration like the clients IP address,
+ * and the like.</li>
+ * </ol>
+ * @param pMethods The method, which will be invoked for
+ * executing the handler.
+ */
+ public ReflectiveXmlRpcHandler(AbstractReflectiveHandlerMapping
pMapping,
+ TypeConverterFactory pTypeConverterFactory,
+ Class pClass, boolean pInstanceIsStateless,
Method[] pMethods)
+ throws XmlRpcException {
+ mapping = pMapping;
+ clazz = pClass;
+ methods = new MethodData[pMethods.length];
+ for (int i = 0; i < methods.length; i++) {
+ methods[i] = new MethodData(pMethods[i], pTypeConverterFactory);
+ }
+ theInstance = pInstanceIsStateless ? newInstance() : null;
+ }
+
+ private Object getInstance(XmlRpcRequest pRequest) throws XmlRpcException {
+ final InitializationHandler ih = mapping.getInitializationHandler();
+ if (ih == null) {
+ return theInstance == null ? newInstance() : theInstance;
+ } else {
+ final Object instance = newInstance();
+ ih.init(pRequest, instance);
+ return instance;
+ }
+ }
+
+ public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
+ AuthenticationHandler authHandler =
mapping.getAuthenticationHandler();
+ if (authHandler != null && !authHandler.isAuthorized(pRequest)) {
+ throw new XmlRpcNotAuthorizedException("Not authorized");
+ }
+ Object[] args = new Object[pRequest.getParameterCount()];
+ for (int j = 0; j < args.length; j++) {
+ args[j] = pRequest.getParameter(j);
+ }
+ Object instance = getInstance(pRequest);
+ for (int i = 0; i < methods.length; i++) {
+ MethodData methodData = methods[i];
+ TypeConverter[] converters = methodData.typeConverters;
+ if (args.length == converters.length) {
+ boolean matching = true;
+ for (int j = 0; j < args.length; j++) {
+ if (!converters[j].isConvertable(args[j])) {
+ matching = false;
+ break;
+ }
+ }
+ if (matching) {
+ for (int j = 0; j < args.length; j++) {
+ args[j] = converters[j].convert(args[j]);
+ }
+ return invoke(instance, methodData.method, args);
+ }
+ }
+ }
+ throw new XmlRpcException("No method matching arguments: " +
Util.getSignature(args));
+ }
+
+ private Object invoke(Object pInstance, Method pMethod, Object[] pArgs)
throws XmlRpcException {
+ try {
+ return pMethod.invoke(pInstance, pArgs);
+ } catch (IllegalAccessException e) {
+ throw new XmlRpcException("Illegal access to method "
+ + pMethod.getName() + " in class "
+ + clazz.getName(), e);
+ } catch (IllegalArgumentException e) {
+ throw new XmlRpcException("Illegal argument for method "
+ + pMethod.getName() + " in class "
+ + clazz.getName(), e);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getTargetException();
+ throw new XmlRpcException("Failed to invoke method "
+ + pMethod.getName() + " in class "
+ + clazz.getName() + ": "
+ + t.getMessage(), t);
+ }
+ }
+
+ protected Object newInstance() throws XmlRpcException {
+ try {
+ return clazz.newInstance();
+ } catch (InstantiationException e) {
+ throw new XmlRpcException("Failed to instantiate class " +
clazz.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new XmlRpcException("Illegal access when instantiating class
" + clazz.getName(), e);
+ }
+ }
+}
Modified: webservices/xmlrpc/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/changes/changes.xml?rev=421821&r1=421820&r2=421821&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/changes/changes.xml (original)
+++ webservices/xmlrpc/trunk/src/changes/changes.xml Fri Jul 14 00:22:02 2006
@@ -8,10 +8,15 @@
due-to-email="[EMAIL PROTECTED]">
Added a missing "synchronized" to the TimingOutCallback.
</action>
+ <action dev="jochen" type="fix" due-to="Chris Conrad"
+ due-to-email="[EMAIL PROTECTED]">
+ Fixed an invalid index, that caused the ReflectiveXmlRpcHandler to fail
+ detecting a method.
+ </action>
</release>
<release version="3.0b1" date="24-Jun-2006">
<action dev="hgomez" type="add">
- add connectionTimeout and replyTimeout in RPC clients.
+ Add connectionTimeout and replyTimeout in RPC clients.
CommonsTransport support connection and reply timeout,
liteHttpTransport only support reply timeout
</action>
<action dev="jochen" type="fix" due-to="Marek Ludha"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]