1

I am trying to use an XmlRpcClient to call a method on an XmlRpcServer which reads data from a database according to a list of specified indexes. The length of the list is not fixed, so there could be 5 or 500 values inside. I want to pass this list of indexes along from the client to the server.

I have tried several ways of passing the list of indexes to the server and all have failed, mainly with this error:

org.apache.xmlrpc.XmlRpcException: No method matching arguments: [Ljava.lang.Object;
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
at rpc.RPCClient.read(RPCClient.java:47)
at test.Test.main(Test.java:19)

Right now I am trying to pass the as an Object which I then cast back to an ArrayList (I just let the method return true for now):

Client

// Array containing the indexes
ArrayList<Integer> indexList = new ArrayList<>();

// Client setup
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL(url));
client = new XmlRpcClient();
client.setConfig(config);

// RPC execution
result = (boolean) client.execute("rpc.read", new Object [] {indexList});

Method on server

public boolean read(Object[] o) {
    ArrayList<Integer> indexList= new ArrayList<>();

    for (int i = 0; i < o.length; i++) {
        indexList= (ArrayList<Integer>) o[i];
    }

    return true;
}

This produces the error described above.

Which data type can I pass on to the method on the server? Is it not possible to pass multiple values and do I have to call the method for each index separately instead?

0 Answers0