I tend to use XML-RPC to implement simple requirements for connecting applications. The reason is that it is a simple, straighforward remote-procedure protocol that has good-enough performance for most of such applications. Also, it is very wide-spread so you can find a stable implementation for whatever platform you need it (for example you can use it to connect Java and PHP applications).
When it comes to Java, I use the Apache XML-RPC library (http://ws.apache.org/xmlrpc/). Reasons: it’s been long time in development, it’s stable and I never had any problems with it.
Now, most of the applications that I write lately are based on the Spring framework, so obviously I needed an adapter (bean factory) for the Apache XML-RPC server. Since I haven’t found one, I had to write it by myself.
Here you can find an archive that contains Spring adapter for the
org.apache.xmlrpc.WebServer class of the Apache XML-RPC library.
Before you look any further, I must say that this is not a general-purpose solution. As you might know, this library can be used with the included minimal web server or through a servlet container. I needed to use the first approach, so here you can find just a wrapper around this web server that lets you use your Spring beans as XML-RPC handlers. If you want to use XML-RPC through the servlet container you can use the
org.springframework.web.servlet.mvc.ServletWrappingController class to wrap it. This second approach is not the topic of this post. If there’s an interest in this, I can document it in another post.
The archive contains the
net.nighttale.spring.xmlrpc.XmlRpcServerBean class that does all the work. It contains a wrapper for properties needed to successfully initialize the web server. It also starts and shutdowns the server when your application does the same.
In the archive you can find an example
applicationContext.xml configuration of this factory.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean name="xmlRpcServer" class="net.nighttale.spring.xmlrpc.XmlRpcServerBean"> <!-- BASIC SETUP --> <property name="address"><value>localhost</value></property> <property name="port"><value>8080</value></property> <!-- CLIENT FILTERING --> <property name="paranoid"><value>true</value></property> <property name="acceptClient"> <list> <value>127.0.0.1</value> <value>192.168.*.*</value> </list> </property> <property name="denyClient"> <list> <value>194.*.*.*</value> </list> </property> <!-- HANDLERS --> <property name="handlers"> <map> <entry> <key><value>test</value></key> <ref bean="testHandler"/> </entry> </map> </property> <!-- SSL configuration --> <property name="secure"><value>true</value></property> <property name="keyStore"><value>keystore</value></property> <property name="keyStorePassword"><value>password</value></property> </bean> <bean name="testHandler" class="net.nighttale.spring.xmlrpc.TestHandler"> </bean> </beans>
As you can see, it can be used to configure all of the aspects of the standalone XML-RPC server. The actual handlers are references to other beans defined in the configuration. In this case, we used a reference to the
testHandler bean defined in the package.
The only thing that is worth explaining is the part regarding the SSL configuration of the server. In case that the
secure property has the value
true, an instance of the
org.apache.xmlrpc.secure.SecureWebServer will be created. In that case you need to provide the location of your keystore and the password for it. More information about this whole SSL stuff and Java could be found in this onJava article. I put just these two basic configuration parameters, because I didn’t need any other (but they can be easily added later on).
In the package you can also find two “client” classes that could be used to test the regular and secure configurations of the XML-RPC server: