Search in sources :

Example 26 with RequestHandler

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";
}
Also used : Locale(java.util.Locale) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) EventHandlerException(org.apache.ofbiz.webapp.event.EventHandlerException) ServletContext(javax.servlet.ServletContext) EventHandler(org.apache.ofbiz.webapp.event.EventHandler) Event(org.apache.ofbiz.webapp.control.ConfigXMLReader.Event)

Example 27 with RequestHandler

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: &#47;projectmgr&#47;control&#47;EditTaskContents&#63;workEffortId&#61;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("&amp;");
            }
            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("&amp;");
            } 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());
    }
}
Also used : UtilCodec(org.apache.ofbiz.base.util.UtilCodec) StringWriter(java.io.StringWriter) RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) ServletContext(javax.servlet.ServletContext) Map(java.util.Map)

Aggregations

RequestHandler (org.apache.ofbiz.webapp.control.RequestHandler)27 ServletContext (javax.servlet.ServletContext)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 HashMap (java.util.HashMap)10 IOException (java.io.IOException)9 Writer (java.io.Writer)7 Environment (freemarker.core.Environment)6 Locale (java.util.Locale)6 WeakHashMap (java.util.WeakHashMap)6 GeneralException (org.apache.ofbiz.base.util.GeneralException)6 GenericValue (org.apache.ofbiz.entity.GenericValue)6 HttpSession (javax.servlet.http.HttpSession)5 Delegator (org.apache.ofbiz.entity.Delegator)5 Map (java.util.Map)4 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)4 TemplateModelException (freemarker.template.TemplateModelException)3 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)3 EventHandlerException (org.apache.ofbiz.webapp.event.EventHandlerException)3 BeanModel (freemarker.ext.beans.BeanModel)2