use of org.apache.ofbiz.webapp.control.ConfigXMLReader.Event in project ofbiz-framework by apache.
the class CoreEvents method runService.
/**
* Run a service.
* Request Parameters which are used for this event:
* SERVICE_NAME - Name of the service to invoke
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return Response code string
*/
public static String runService(HttpServletRequest request, HttpServletResponse response) {
// get the mode and service name
String serviceName = request.getParameter("serviceName");
String mode = request.getParameter("mode");
Locale locale = UtilHttp.getLocale(request);
if (UtilValidate.isEmpty(serviceName)) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.must_specify_service_name", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
if (UtilValidate.isEmpty(mode)) {
mode = "sync";
}
// now do a security check
Security security = (Security) request.getAttribute("security");
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
// 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_", 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_", errMsg + "[" + serviceName + "]");
return "error";
}
if (!modelService.export && !security.hasPermission("SERVICE_INVOKE_ANY", request.getSession())) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.not_authorized_to_call", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg + ".");
return "error";
}
Debug.logInfo("Running service named [" + serviceName + "] from event with mode [" + mode + "]", module);
// call the service via the ServiceEventHandler which
// adapts an event to a service.
Event event = new Event("service", mode, serviceName, false);
try {
return seh.invoke(event, null, request, response);
} catch (EventHandlerException e) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.service_eventhandler_exception", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg + ": " + e.getMessage());
return "error";
}
}
use of org.apache.ofbiz.webapp.control.ConfigXMLReader.Event in project ofbiz-framework by apache.
the class TaskEvents method delegateAndAcceptAssignment.
/**
* Delegate and accept assignment event
*/
public static String delegateAndAcceptAssignment(HttpServletRequest request, HttpServletResponse response) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
Locale locale = UtilHttp.getLocale(request);
if (addToOrderRole(request)) {
try {
EventHandler eh = rh.getEventFactory().getEventHandler("service");
eh.invoke(new Event("service", "", "wfAcceptRoleAssignment", true), null, request, response);
} catch (EventHandlerException e) {
Debug.logError(e, "Invocation error", module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderFailedToInvokeTheWfDelegateAndAcceptAssignmentService", locale));
return "error";
}
return "success";
}
return "error";
}
use of org.apache.ofbiz.webapp.control.ConfigXMLReader.Event in project ofbiz-framework by apache.
the class TaskEvents method acceptRoleAssignment.
/**
* Accept role assignment event
*/
public static String acceptRoleAssignment(HttpServletRequest request, HttpServletResponse response) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
Locale locale = UtilHttp.getLocale(request);
if (addToOrderRole(request)) {
try {
EventHandler eh = rh.getEventFactory().getEventHandler("service");
eh.invoke(new Event("service", "", "wfAcceptRoleAssignment", true), null, request, response);
} catch (EventHandlerException e) {
Debug.logError(e, "Invocation error", module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderFailedToInvokeTheWfAcceptRoleAssignmentService", locale));
return "error";
}
return "success";
}
return "error";
}
Aggregations