use of org.apache.ofbiz.webapp.control.RequestHandler 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";
}
use of org.apache.ofbiz.webapp.control.RequestHandler in project ofbiz-framework by apache.
the class WidgetWorker method buildHyperlinkUrl.
public static void buildHyperlinkUrl(Appendable externalWriter, String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
// We may get an encoded request like: /projectmgr/control/EditTaskContents?workEffortId=10003
// Try to reducing a possibly encoded string down to its simplest form: /projectmgr/control/EditTaskContents?workEffortId=10003
// This step make sure the following appending externalLoginKey operation to work correctly
String localRequestName = Parser.unescapeEntities(target, true);
localRequestName = UtilHttp.encodeAmpersands(localRequestName);
Appendable localWriter = new StringWriter();
if ("intra-app".equals(targetType)) {
if (request != null && response != null) {
ServletContext servletContext = request.getSession().getServletContext();
RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_");
externalWriter.append(rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode));
} else if (prefix != null) {
externalWriter.append(prefix);
externalWriter.append(localRequestName);
} else {
externalWriter.append(localRequestName);
}
} else if ("inter-app".equals(targetType)) {
String fullTarget = localRequestName;
localWriter.append(fullTarget);
String externalLoginKey = (String) request.getAttribute("externalLoginKey");
if (UtilValidate.isNotEmpty(externalLoginKey)) {
if (fullTarget.indexOf('?') == -1) {
localWriter.append('?');
} else {
localWriter.append("&");
}
localWriter.append("externalLoginKey=");
localWriter.append(externalLoginKey);
}
} else if ("content".equals(targetType)) {
appendContentUrl(localWriter, localRequestName, request);
} else {
localWriter.append(localRequestName);
}
if (UtilValidate.isNotEmpty(parameterMap)) {
String localUrl = localWriter.toString();
externalWriter.append(localUrl);
boolean needsAmp = true;
if (localUrl.indexOf('?') == -1) {
externalWriter.append('?');
needsAmp = false;
}
for (Map.Entry<String, String> parameter : parameterMap.entrySet()) {
String parameterValue = null;
if (parameter.getValue() instanceof String) {
parameterValue = parameter.getValue();
} else {
Object parameterObject = parameter.getValue();
// skip null values
if (parameterObject == null)
continue;
if (parameterObject instanceof String[]) {
// it's probably a String[], just get the first value
String[] parameterArray = (String[]) parameterObject;
parameterValue = parameterArray[0];
Debug.logInfo("Found String array value for parameter [" + parameter.getKey() + "], using first value: " + parameterValue, module);
} else {
// not a String, and not a String[], just use toString
parameterValue = parameterObject.toString();
}
}
if (needsAmp) {
externalWriter.append("&");
} else {
needsAmp = true;
}
externalWriter.append(parameter.getKey());
externalWriter.append('=');
UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder");
if (simpleEncoder != null && parameterValue != null) {
externalWriter.append(simpleEncoder.encode(URLEncoder.encode(parameterValue, "UTF-8")));
} else {
externalWriter.append(parameterValue);
}
}
} else {
externalWriter.append(localWriter.toString());
}
}
Aggregations