private Map<String, Object> serviceInvoker(ModelService modelService, Map<String, Object> context) throws GenericServiceException {
if (modelService.location == null || modelService.invoke == null)
throw new GenericServiceException("Cannot locate service to invoke");
XmlRpcClientConfigImpl config = null;
XmlRpcClient client = null;
String serviceName = modelService.invoke;
String engine = modelService.engineName;
String url = null;
String login = null;
String password = null;
String keyStoreComponent = null;
String keyStoreName = null;
String keyAlias = null;
try {
url = ServiceConfigUtil.getEngineParameter(engine, "url");
login = ServiceConfigUtil.getEngineParameter(engine, "login");
password = ServiceConfigUtil.getEngineParameter(engine, "password");
keyStoreComponent = ServiceConfigUtil.getEngineParameter(engine, "keyStoreComponent");
keyStoreName = ServiceConfigUtil.getEngineParameter(engine, "keyStoreName");
keyAlias = ServiceConfigUtil.getEngineParameter(engine, "keyAlias");
config = new XmlRpcClientConfigImpl();
config.setBasicUserName(login);
config.setBasicPassword(password);
config.setServerURL(new URL(url));
}catch (MalformedURLException e) {
throw new GenericServiceException("Cannot invoke service : engine parameters are not correct");
}
catch (GenericConfigException e) {
throw new GenericServiceException("Cannot invoke service : engine parameters are not correct");
}
if(UtilValidate.isNotEmpty(keyStoreComponent) && UtilValidate.isNotEmpty(keyStoreName) && UtilValidate.isNotEmpty(keyAlias)){
client = new XmlRpcClient(config, keyStoreComponent, keyStoreName, keyAlias);
}
else{
client = new XmlRpcClient(config);
}
List<ModelParam> inModelParamList = modelService.getInModelParamList();
if (Debug.verboseOn()) {
Debug.logVerbose("[XMLRPCClientEngine.invoke] : Parameter length - " + inModelParamList.size(), module);
for (ModelParam p: inModelParamList) {
Debug.logVerbose("[XMLRPCClientEngine.invoke} : Parameter: " + p.name + " (" + p.mode + ")", module);
}
}
Map<String, Object> result = null;
Map<String, Object> params = FastMap.newInstance();
for (ModelParam modelParam: modelService.getModelParamList()) {
// don't include OUT parameters in this list, only IN and INOUT
if ("OUT".equals(modelParam.mode) || modelParam.internal) continue;
Object paramValue = context.get(modelParam.name);
if (paramValue != null) {
params.put(modelParam.name, paramValue);
}
}
List<Map<String,Object>> listParams = UtilMisc.toList(params);
try{
result = UtilGenerics.cast(client.execute(serviceName, listParams.toArray()));
}catch (XmlRpcException e) {
result = ServiceUtil.returnError(e.getLocalizedMessage());
}
return result;
}