I am trying to call the Ejabberd command create_room_with_opts via XMLRPC (Java) using the apache XMLRPC api. The following is the code I am using.
public static void main(){
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL(<EJABBERD_HOST_URL>));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
// Command string
String command = "create_room_with_opts";
Map<String, Object> struct1 = new HashMap<String, Object>();
struct1.put("user", <ADMIN_USERNAME>);
struct1.put("server", <HOST>);
struct1.put("password", <ADMIN_PASSWORD>);
struct1.put("admin", Boolean.TRUE);
Map<String, Object> struct = new HashMap<String, Object>();
struct.put("name", "testroom");
struct.put("service", <NAME_OF_SERVICE>);
struct.put("host", <HOST>);
struct.put("options", getOpts());
HashMap result = (HashMap) client.execute(command, params);
}
static Object[] getOpts() {
Object opt[] = new Object[1];
HashMap<String, Object> option = new HashMap<String, Object>();
HashMap<String, Object> optionTuple = new HashMap<String, Object>();
option.put("name", "public");
option.put("value", Boolean.TRUE);
optionTuple.put("option", option);
return opt;
}
However, when I run this code I get the following exception.
org.apache.xmlrpc.XmlRpcException: Error -122
Parameter '{struct,[{name,<<"public">>},{value,<<"true">>}]}' can't be coerced to type '{tuple,[{name,binary},{value,binary}]}'
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:181)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:149)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:95)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:39)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
I am unable to identify the problem in this code.
I have tried the example given in the ejabberd documentation at the following link (https://docs.ejabberd.im/developer/ejabberd-api/admin-api/), but it seems that there is a syntax error in that example.
I am able to call the other commands(for example create_room, register, etc) for the same Ejabberd server successfully, so I know that the configuration is correct.
I am using JDK1.7 and apache XMLRPC api 3.1.3
Is there any other example(for create_room_with_opts command) which I can check?