Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #273 from wmlynar/kinetic
Browse files Browse the repository at this point in the history
Fix for xmlrpc multicall issue
  • Loading branch information
Juan Ignacio Ubeira committed Mar 29, 2018
2 parents cc8f806 + 6e89306 commit 8f7f2c1
Showing 1 changed file with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
Expand Down Expand Up @@ -197,7 +199,11 @@ public void execute(XmlRpcStreamRequestConfig pConfig,
try {
istream = getInputStream(pConfig, pConnection);
XmlRpcRequest request = getRequest(pConfig, istream);
result = execute(request);
if (request.getMethodName().equals("system.multicall")) {
result = executeMulticall(request);
} else {
result = execute(request);
}
istream.close();
istream = null;
error = null;
Expand Down Expand Up @@ -251,6 +257,53 @@ public void execute(XmlRpcStreamRequestConfig pConfig,
}
log.debug("execute: <-");
}

private Object[] executeMulticall(final XmlRpcRequest pRequest) {
if (pRequest.getParameterCount() != 1)
return null;

Object[] reqs = (Object[]) pRequest.getParameter(0); // call requests
ArrayList<Object> results = new ArrayList<Object>(); // call results
final XmlRpcRequestConfig pConfig = pRequest.getConfig();
// TODO: make concurrent calls?
for (int i = 0; i < reqs.length; i++) {
Object result = null;
try {
@SuppressWarnings("unchecked")
HashMap<String, Object> req = (HashMap<String, Object>) reqs[i];
final String methodName = (String) req.get("methodName");
final Object[] params = (Object[]) req.get("params");
result = execute(new XmlRpcRequest() {
@Override
public XmlRpcRequestConfig getConfig() {
return pConfig;
}

@Override
public String getMethodName() {
return methodName;
}

@Override
public int getParameterCount() {
return params == null ? 0 : params.length;
}

@Override
public Object getParameter(int pIndex) {
return params[pIndex];
}
});
} catch (Throwable t) {
logError(t);
// TODO: should this return an XmlRpc fault?
result = null;
}
results.add(result);
}
Object[] retobj = new Object[] { results };
return retobj;
}

protected void logError(Throwable t) {
final String msg = t.getMessage() == null ? t.getClass().getName() : t.getMessage();
Expand Down

0 comments on commit 8f7f2c1

Please sign in to comment.