[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlrpc-user
Subject:    Server-Side XML-RPC and Spring-loaded Handlers
From:       Ryan Shelley <rshelley () csun ! edu>
Date:       2006-10-17 7:10:32
Message-ID: 6C928E60-EDD7-45DE-9654-337A05B58DE1 () csun ! edu
[Download RAW message or body]


Hi everyone...

I'm implementing a stand-alone server and would like to add XML-RPC  
(version 3.0) support for it.  My app is supported by Spring, so I'd  
like to use my existing Spring configurations to wire up my XML-RPC  
configurations.  How Spring actually injects my XmlRpcHandler is not  
entirely the issue, it's more of how to instantiate a new, dynamic,  
object (based on class name) so that XML-RPC can handle requests to it.

So I have some server code (mind you, I've removed my error checking  
and try/catch blocks for brevity)... note that I'm using the XML-RPC  
library version 3.0:
-------------
     private WebServer xmlRpcWebServer = null;
     private XmlRpcServer xmlRpcServer = null;
     private int port;
     private String handlerClass;

     xmlRpcWebServer = new WebServer(port);
     xmlRpcServer = xmlRpcWebServer.getXmlRpcServer();
     PropertyHandlerMapping phm = new PropertyHandlerMapping();

     phm.addHandler(
         "XMLRPCConnectionHandler",
         Class.forName(handlerClass, true, Thread.currentThread 
().getContextClassLoader()).newInstance().getClass()
      );

      xmlRpcServer.setHandlerMapping(phm);

      XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)  
xmlRpcServer.getConfig();
      serverConfig.setEnabledForExtensions(true);
      serverConfig.setContentLengthOptional(false);
      xmlRpcServer.setConfig(serverConfig);

      xmlRpcWebServer.start();
-------------

Suffice to say that "port" and "handlerClass" are populated  
automatically by Spring, so they actually represent "1234" and  
"my.package.Class" (for example).

My log file shows that the handlerClass is instantiated, however, I  
get an error when addHandler executes:

Exception in thread "SM-XMLRPCMgr" 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.newXmlRpcHandl 
er(AbstractReflectiveHandlerMapping.java:169)
         at  
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.registerPublic 
Methods(AbstractReflectiveHandlerMapping.java:150)
         at org.apache.xmlrpc.server.PropertyHandlerMapping.addHandler 
(PropertyHandlerMapping.java:97)
         at edu.csun.groupmgr.XMLRPCConnectionManager.run 
(XMLRPCConnectionManager.java:122)
         at java.lang.Thread.run(Thread.java:613)

For reference, my Handler looks like this:
--------------
package edu.csun.groupmgr;

import org.apache.log4j.Logger;

public class XMLRPCConnectionHandler{

     private Logger log;

     public XMLRPCConnectionHandler() {
         this.log = Logger.getLogger(this.getClass());
         log.debug("XMLRPCConnectionHandler online");
     }

     public boolean isStudentActive(String test, String test2){
         log.debug(test + " | " + test2);
         return true;
     }
}
--------------

I would like to keep the class name variable (hence the  
"Class.forName") because this class might change or be swapped in and  
out for different versions via the Spring configuration, and I want  
to keep it flexible.  What would be the proper method of invoking  
this handler class to pass to the RPC server?  Any help would be  
appreciated.  Thanks!

Ryan Shelley
Lead Developer
ITR Web Development/Middleware
California State University, Northridge

818.677.4258
rshelley@csun.edu





[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic