diff --git a/hsarjcli/src/de/hsadmin/jscli/RpcClient.java b/hsarjcli/src/de/hsadmin/jscli/RpcClient.java index d6c6c71..3eeb63c 100644 --- a/hsarjcli/src/de/hsadmin/jscli/RpcClient.java +++ b/hsarjcli/src/de/hsadmin/jscli/RpcClient.java @@ -3,7 +3,9 @@ package de.hsadmin.jscli; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClient; @@ -17,17 +19,23 @@ public class RpcClient { private static final String XMLRPC_URL = "https://config.hostsharing.net:443/hsar/xmlrpc/hsadmin"; - private final String xmlrpcURL; - private final XmlRpcClient client; + private final List clientList; + private final Map clientMap; public RpcClient(final CASTicketProvider tgt) throws JSCliException { + clientList = new ArrayList(); + clientMap = new HashMap(); try { - xmlrpcURL = Config.getInstance().getProperty("xmlrpcURL", XMLRPC_URL); - XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); - config.setServerURL(new URL(xmlrpcURL)); - config.setEnabledForExtensions(true); - client = new XmlRpcClient(); - client.setConfig(config); + final String xmlrpcURLsString = Config.getInstance().getProperty("xmlrpcURL", XMLRPC_URL); + final String[] xmlrpcURLsArray = xmlrpcURLsString.split(","); + for (final String xmlrpcURL : xmlrpcURLsArray) { + final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); + config.setServerURL(new URL(xmlrpcURL)); + config.setEnabledForExtensions(true); + final XmlRpcClient client = new XmlRpcClient(); + client.setConfig(config); + clientList.add(client); + } } catch (MalformedURLException e) { throw new JSCliException(e); } @@ -35,18 +43,25 @@ public class RpcClient { public List listMethods() throws JSCliException { final List methodList = new ArrayList(); - final List execute = execute("system.listMethods"); - for (final Object obj : execute) { - methodList.add(obj.toString()); + for (final XmlRpcClient client : clientList) { + final List execute = execute(client, "system.listMethods"); + for (final Object obj : execute) { + final String methodString = obj.toString(); + final String[] path = methodString.split("\\."); + if (path.length == 2) { + clientMap.put(path[0], client); + } + methodList.add(methodString); + } } return methodList; } - private List execute(final String method) throws JSCliException { - return execute(method, new ArrayList()); + private List execute(final XmlRpcClient client, final String method) throws JSCliException { + return execute(client, method, new ArrayList()); } - public List execute(final String method, final List params) throws JSCliException { + private List execute(final XmlRpcClient client, final String method, final List params) throws JSCliException { try { final Object execute = client.execute(method, params); final ArrayList list = new ArrayList(); @@ -62,4 +77,13 @@ public class RpcClient { } } + public List execute(final String method, final List params) throws JSCliException { + final String[] path = method.split("\\."); + if (path.length == 2) { + return execute(clientMap.get(path[0]), method, params); + } else { + throw new JSCliException("method not found: " + method); + } + } + } diff --git a/hsarjcli/src/de/hsadmin/jscli/ScriptClient.java b/hsarjcli/src/de/hsadmin/jscli/ScriptClient.java index 4acc603..300e5ef 100644 --- a/hsarjcli/src/de/hsadmin/jscli/ScriptClient.java +++ b/hsarjcli/src/de/hsadmin/jscli/ScriptClient.java @@ -24,11 +24,13 @@ public class ScriptClient { final CASTicketProvider ticketProvider = new CASTicketProvider(console, user, runAs); final RpcClient rpcClient = new RpcClient(ticketProvider); final ScriptEngineManager engineManager = new ScriptEngineManager(); - completionStrings = new HashSet(); engine = engineManager.getEngineByName("js"); engine.put("casgrantingticket", ticketProvider); engine.put("xmlrpcclient", rpcClient); engine.put("xmlrpcLastResult", null); + completionStrings = new HashSet(); + completionStrings.add("set"); + completionStrings.add("where"); try { final InputStream inputResource = getClass().getClassLoader().getResourceAsStream("js/functions.js"); engine.eval(new InputStreamReader(inputResource)); @@ -40,8 +42,11 @@ public class ScriptClient { final String[] parts = method.split("\\."); if (parts.length == 2) { final String module = parts[0]; - completionStrings.add(module); final String function = parts[1]; + if ("system".equals(module) || "getModuleLookup".equals(function) || "createValueObject".equals(function)) { + continue; + } + completionStrings.add(module); final String jsFunctionIdent; if ("delete".equals(function)) { jsFunctionIdent = module + "['remove']";