String serviceName = xmlRpcReq.getMethodName();
ModelService model = null;
try {
model = dctx.getModelService(serviceName);
} catch (GenericServiceException e) {
throw new XmlRpcException(e.getMessage(), e);
}
// check remote invocation security
if (model == null || !model.export) {
throw new XmlRpcException("Unknown method");
}
// prepare the context -- single parameter type struct (map)
Map<String, Object> context = this.getContext(xmlRpcReq, serviceName);
// add in auth parameters
XmlRpcHttpRequestConfig config = (XmlRpcHttpRequestConfig) xmlRpcReq.getConfig();
String username = config.getBasicUserName();
String password = config.getBasicPassword();
if (UtilValidate.isNotEmpty(username)) {
context.put("login.username", username);
context.put("login.password", password);
}
// add the locale to the context
if (context.get("locale") == null) {
context.put("locale", Locale.getDefault());
}
// invoke the service
Map<String, Object> resp;
try {
resp = dispatcher.runSync(serviceName, context);
} catch (GenericServiceException e) {
throw new XmlRpcException(e.getMessage(), e);
}
if (ServiceUtil.isError(resp)) {
Debug.logError(ServiceUtil.getErrorMessage(resp), module);
throw new XmlRpcException(ServiceUtil.getErrorMessage(resp));
}
// return only definied parameters
return model.makeValid(resp, ModelService.OUT_PARAM, false, null);
}