I'm new to XML-RPC.  I thought XML-RPC would be a good fit for my current
project.  I apologize for having to post what is probably a simple problem
but I can find very little documentation as to what old functionality is
gone/broken, what's new, and how to code it.  (Also, any performance tips
would be appreciated.  My basic working XML-RPC test program only achieves
about 22 RPC calls per second on localhost when calling the synchronous
execute() method.)
------------------------------------
My old, now obsolete, O'Reilly book on XML-RPC says on pg. 49 that
registered handler classes that implement XmlRpcHandler cause the normal
server method invocation logic to be bypassed and delegate that task to the
handler class.  This is what I want to do.  Is this feature now gone?  Was
it ever working?  Am I misinterpreting the book?  I can find no
documentation in 3.0 regarding this topic.

Code below is a quick test program - it is the server side only and it dies
when trying to start up with the following stack trace.  I think it's trying
to reflectively analyze the handler class and is finding unsupported method
argument types in the class's methods instead of just delegating RPC to the
handler class.

java.lang.IllegalStateException: Invalid parameter or result type:
org.apache.xmlrpc.XmlRpcRequest
        at
org.apache.xmlrpc.common.TypeConverterFactoryImpl.getTypeConverter(TypeConverterFactoryImpl.java:289)
        at
org.apache.xmlrpc.server.ReflectiveXmlRpcHandler$MethodData.<init>(ReflectiveXmlRpcHandler.java:43)
        at
org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.<init>(ReflectiveXmlRpcHandler.java:69)
        at
org.apache.xmlrpc.metadata.ReflectiveXmlRpcMetaDataHandler.<init>(ReflectiveXmlRpcMetaDataHandler.java:51)
        at
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.newXmlRpcHandler(AbstractReflectiveHandlerMapping.java:169)
        at
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.registerPublicMethods(AbstractReflectiveHandlerMapping.java:150)
        at
org.apache.xmlrpc.server.PropertyHandlerMapping.addHandler(PropertyHandlerMapping.java:97)
        at ServerTest2.main(ServerTest2.java:23)

Here's the code:

------------------------------------------

public class ServerTest2 {

        public ServerTest2() { }
        
        public static void main( String [] args ) {
                try {
                        org.apache.xmlrpc.webserver.WebServer webServer = new
org.apache.xmlrpc.webserver.WebServer( 80 );
                        org.apache.xmlrpc.server.PropertyHandlerMapping phm = 
new
org.apache.xmlrpc.server.PropertyHandlerMapping();
                        phm.addHandler( "Arithmetic", MyXmlRpcHandler.class );
                        org.apache.xmlrpc.server.XmlRpcServer xrs = 
webServer.getXmlRpcServer();
                        xrs.setHandlerMapping( phm );
                        webServer.start();
                }
                catch ( Exception e ) {
                        e.printStackTrace();
                }
        }
}

---------------------------------------

// Want to call methods on instances of this class if can ever get server to
start up without crashing
class SimpleMethods {
        public SimpleMethods() { }
        public  int addTwoInts( int i1, int i2 ) { return i1 + i2; }
        public int stringLength( String s ) { return s.length(); }
}

---------------------------------------

class MyXmlRpcHandler implements org.apache.xmlrpc.XmlRpcHandler {

        // 2 different instances on which to call methods via xmlrpc 
        private SimpleMethods sm1 = new SimpleMethods(); 
        private SimpleMethods sm2 = new SimpleMethods();
        
        public MyXmlRpcHandler() { }
        
        // Hopefully XML-RPC server delegates RPC calls to this method - per old
book at least
        public Object  execute( org.apache.xmlrpc.XmlRpcRequest pRequest ) {
                // Unpack data and set up Vector with method call arguments
                String methodName = pRequest.getMethodName();
                int methodArgCount = pRequest.getParameterCount();
                java.util.Vector< Object > args = new java.util.Vector< Object 
>(
methodArgCount );
                for ( int i = 0; i < methodArgCount; ++i )
                        args.add( pRequest.getParameter( i ) );
                // ... some logic to select target object ...   arbitrarily 
choose sm2 for
test
                // Call static worker method to invoke method on selected object
                return invokeMethod( sm2, methodName, args );
        }
        
        // Reflection-based method invocation worker
        public static Object invokeMethod( java.lang.Object targetObject, String
methodName, java.util.Vector< Object > args ) {
                // Method call return object
                Object retObj = null;
                // Need argument data in arrays, not Vector, to look up and 
invoke a
method via reflection API
                Object [] argArray = new Object [ args.size() ];
                Class [] argTypeArray = new Class [ args.size() ];
                for ( int i = 0; i < args.size(); ++i ) {
                        argArray[ i ] = args.elementAt( i );
                        argTypeArray[ i ] = args.elementAt( i ).getClass();
                }
                // Reflectively lookup method and invoke
                try {
                        java.lang.reflect.Method targetMethod =
targetObject.getClass().getDeclaredMethod( methodName, argTypeArray );
                        retObj = targetMethod.invoke( targetObject, argArray );
                }
                catch ( Exception e ) {
                        e.printStackTrace();
                }
                return retObj;
        }
}
-- 
View this message in context: 
http://www.nabble.com/Need-to-pick-RPC-target-object-tf2320544.html#a6456491
Sent from the Apache Xml-RPC - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to