xmlrpc instead of SOAP

2 views
Skip to first unread message

Jeff

unread,
Dec 13, 2007, 3:23:34 PM12/13/07
to SWAMP Project Users
Since I threw up my hands in disgust at trying to get python SOAP and
java SOAP to play nicely, I thought I'd try the simpler XMLRPC. I've
spent 3 days trying to get SOAP working and around 30 minutes getting
XMLRPC working. Here's what I did.

swamp_soapinterface.py's new main() method, at least the most relevent
part:
<code>
jm = StandardJobManager(confname)
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",
48080))
server.register_instance(jm)
server.serve_forever()
</code>
Don't forget to import SimpleXMLRPCServer. Note that this exposes ALL
methods of the jm object, even the ones we shouldn't. It's rather
trivial to expose just those we want, but for simplicity this is all
I've done here.

Java example, in full:
<code>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package swampservicecloneclient;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

/**
*
* @author d3n000
*/
public class Main {

private static final Logger logger = Logger.getLogger("");
static {
logger.setLevel(Level.ALL);
//logger.addHandler(new ConsoleHandler());
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws
MalformedURLException, XmlRpcException {
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:48080/RPC2"));
client.setConfig(config);
Object[] params = new Object[]{
new String("")
};
Integer result = (Integer) client.execute("newScriptedFlow",
params);
System.out.println(result);
}
}
</code>

And guess what? It worked! Now I can move on to more difficult
things. No WSDL needed.

I suppose so long as I wrap the swamp functionality in a nice Java
interface, swamp can change underneath without breaking my calling
classes. So much simpler. Why didn't I start here??

Daniel

unread,
Dec 14, 2007, 2:01:46 PM12/14/07
to SWAMP Project Users
This is a perfectly acceptable way to do it. If you set SWAMP's
publishing path to a filesystem path accessible by the client, you
won't really need the static HTTP instance that handles output
download.

Actually, it's probably not a big deal in twisted to expose the API
via XML-RPC in addition to SOAP. I'll put that on my list. I'll kick
it out after writing the server HOWTO.

-Daniel
Reply all
Reply to author
Forward
0 new messages