radioAe6rt

Running an XML-RPC server as a Java servlet

with 5 comments

Roll your own XML-RPC servlet using Apache XML-RPC v3.0.

The essentials:

The servlet.

The build.xml file.

The web.xml file.

The XmlRpcServlet.properties file, which defines which of your classes handle which remote method calls.

The handler class for this example.

And finally, the Log4J log4j.properties file, which I always deploy early in this sort of project – because I know I will eventually want it. See initLogger() in servlet.init(). The log4j.properties and initLogger() method immediately allow for the creation of rolling appenders for log output to a disk file.

You will also need the ws-commons jar file. This is an unsettling URL, what with the string literal SNAPSHOT in it. If anyone has a better version that bespeaks stability, I would appreciate knowing. It was the only jar of its type I could find to satisfy the VM (argh).

Here is what the war file looks like after ant dist

images/
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/org/
WEB-INF/classes/org/apache/
WEB-INF/classes/org/apache/xmlrpc/
WEB-INF/classes/org/apache/xmlrpc/webserver/
WEB-INF/classes/org/apache/xmlrpc/webserver/XmlRpcServlet.properties
WEB-INF/classes/org/carpediem/
WEB-INF/classes/org/carpediem/phonegnome/
WEB-INF/classes/org/carpediem/phonegnome/crm/
WEB-INF/classes/org/carpediem/phonegnome/crm/Handler.class
WEB-INF/classes/org/carpediem/phonegnome/crm/log4j.properties
WEB-INF/classes/org/carpediem/phonegnome/crm/PGXMLRPCServer.class
WEB-INF/lib/
WEB-INF/lib/log4j-1.2.13.jar
WEB-INF/lib/ws-commons-util-1.0-SNAPSHOT.jar
WEB-INF/lib/xmlrpc-3.0a1.jar
WEB-INF/web.xml

The war file is copied, of course, into /webapps of your servlet container (e.g., Tomcat, jetty), and the container started.

The resulting example servlet can service a remote call of the form crm.inBound(string1,string2).

[tags]xmlrpc,xml-rpc,servlet,tomcat[/tags]

About these ads

Written by radioae6rt

April 23, 2006 at 6:48 am

Posted in Internet

5 Responses

Subscribe to comments with RSS.

  1. Hi,

    I am facing a issue with xml-rpc server. I have a servlet which is the xmlrpc server. I have clients that send request to the server. One of the client resides in the same webserver as that of the server. So when i shutdown the web server i am not able to clean the cache that is available in the client as a socket read exception is thrown. how to clean the cache in the client before the webserver is shutdown. I use xml-rpc 2.0. Please looking forward for your help.

    Vijay

    March 30, 2007 at 2:11 am

  2. Is there anyway you (or anyone) could put some instructions on deploying the example or some step-by-step guide? I would greatly appreciate it.

    Mark

    June 18, 2007 at 4:08 pm

  3. Goodness, it’s been so long since I did this work that I’d have to go back and re-figure it all out. I’m in a time bind, so revisiting this is not something I can get to soon. Sorry.

    ae6rt

    June 18, 2007 at 4:13 pm

  4. When using XML-RPC 3.X you can use the default XML RPC Servlet that comes with it. Easy to set up. See http://ws.apache.org/xmlrpc/server.html

    stefanhendriks

    December 9, 2009 at 5:34 am

  5. Y Pant

    November 23, 2010 at 7:38 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: