XML-RPC Sample
Contents [hide]
Prerequisite
This sample uses the Jala extension to Helma, so you have to use Helma 1.6.x or get Jala from http://dev.orf.at/jala. You can add the Jala module by calling: app.addRepository('modules/jala/code/XmlRpcRequest.js').
You must create two Helma applications: xmlrpcserver and xmlrcpclient. No special configuration of Helma is necessary.
Server
helma/apps/xmlrcpserver/actions.js: function main_action_xmlrpc(methodName, param) {
switch(methodName) {
case "addDoc":
return this[methodName](param);
break;
default:
return "method '" + methodName + "' not supported!";
break;
}
return ;
}
The first argument of the XML/RPC action is the method name. Arguments 1..n are the supplied arguments by the client. Note that you don't generate a response by writing to the res object, but by simply returning a XML-RPCable return value from the action.
helma/apps/xmlrpcserver/functions.js function addDoc(param) {
return "added '" + param.name + "' to the search index.";
}
This is just how you could layout your XML/RPC actions.
Client
helma/apps/xmlrpcclient/actions.js function main_action() {
var xmlReq = new jala.XmlRpcRequest("http://localhost:8080/xmlrpcserver/", "addDoc");
var xmlRes = xmlReq.execute({name: "ist einfach gut"});
res.debug(xmlRes.result);
}
In this example i am supplying a JSON-Object to be sent to the xmlrpcserver. You can send as many argument as you like. I would not send to complex datatypes. But integers, strings and JSON Objects are good.
Configuration
You can change the XML/RPC Port in the Helma start script.
This can be start.bat or start.sh in your Helma home directory or if you use /etc/init.d/helma to start and stop your Helma instance you can change the configuration in /etc/helma.conf.