request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg);
return "error";
}
// lookup the service definition to see if this service is externally available, if not require the SERVICE_INVOKE_ANY permission
ModelService modelService = null;
try {
modelService = dispatcher.getDispatchContext().getModelService(serviceName);
} catch (GenericServiceException e) {
Debug.logError(e, "Error looking up ModelService for serviceName [" + serviceName + "]", module);
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.error_modelservice_for_srv_name", locale);
request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + " [" + serviceName + "]: " + e.toString());
return "error";
}
if (modelService == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.service_name_not_find", locale);
request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + " [" + serviceName + "]");
return "error";
}
// make the context valid; using the makeValid method from ModelService
Map<String, Object> serviceContext = FastMap.newInstance();
Iterator<String> ci = modelService.getInParamNames().iterator();
while (ci.hasNext()) {
String name = ci.next();
// don't include userLogin, that's taken care of below
if ("userLogin".equals(name)) continue;
// don't include locale, that is also taken care of below
if ("locale".equals(name)) continue;
Object value = request.getParameter(name);
// if the parameter wasn't passed and no other value found, don't pass on the null
if (value == null) {
value = request.getAttribute(name);
}
if (value == null) {
value = request.getSession().getAttribute(name);
}
if (value == null) {
// still null, give up for this one
continue;
}
if (value instanceof String && ((String) value).length() == 0) {
// interpreting empty fields as null values for each in back end handling...
value = null;
}
// set even if null so that values will get nulled in the db later on
serviceContext.put(name, value);
}
serviceContext = modelService.makeValid(serviceContext, ModelService.IN_PARAM, true, null, timeZone, locale);
if (userLogin != null) {
serviceContext.put("userLogin", userLogin);
}