Search in sources :

Example 26 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class RequestProcessor method processActionForm.

/**
     * <p>Retrieve and return the <code>ActionForm</code> associated with this
     * mapping, creating and retaining one if necessary. If there is no
     * <code>ActionForm</code> associated with this mapping, return
     * <code>null</code>.</p>
     *
     * @param request  The servlet request we are processing
     * @param response The servlet response we are creating
     * @param mapping  The mapping we are using
     * @return The <code>ActionForm</code> associated with this mapping.
     */
protected ActionForm processActionForm(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {
    // Create (if necessary) a form bean to use
    ActionForm instance = RequestUtils.createActionForm(request, mapping, moduleConfig, servlet);
    if (instance == null) {
        return (null);
    }
    // Store the new instance in the appropriate scope
    if (log.isDebugEnabled()) {
        log.debug(" Storing ActionForm bean instance in scope '" + mapping.getScope() + "' under attribute key '" + mapping.getAttribute() + "'");
    }
    if ("request".equals(mapping.getScope())) {
        request.setAttribute(mapping.getAttribute(), instance);
    } else {
        HttpSession session = request.getSession();
        session.setAttribute(mapping.getAttribute(), instance);
    }
    return (instance);
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 27 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class RequestProcessor method processLocale.

/**
     * <p>Automatically select a <code>Locale</code> for the current user, if
     * requested. <strong>NOTE</strong> - configuring Locale selection will
     * trigger the creation of a new <code>HttpSession</code> if
     * necessary.</p>
     *
     * @param request  The servlet request we are processing
     * @param response The servlet response we are creating
     */
protected void processLocale(HttpServletRequest request, HttpServletResponse response) {
    // Are we configured to select the Locale automatically?
    if (!moduleConfig.getControllerConfig().getLocale()) {
        return;
    }
    // Has a Locale already been selected?
    HttpSession session = request.getSession();
    if (session.getAttribute(Globals.LOCALE_KEY) != null) {
        return;
    }
    // Use the Locale returned by the servlet container (if any)
    Locale locale = request.getLocale();
    if (locale != null) {
        if (log.isDebugEnabled()) {
            log.debug(" Setting user locale '" + locale + "'");
        }
        session.setAttribute(Globals.LOCALE_KEY, locale);
    }
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession)

Example 28 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class RequestProcessor method processCachedMessages.

/**
     * <p>Removes any <code>ActionMessages</code> object stored in the session
     * under <code>Globals.MESSAGE_KEY</code> and <code>Globals.ERROR_KEY</code>
     * if the messages' <code>isAccessed</code> method returns true.  This
     * allows messages to be stored in the session, display one time, and be
     * released here.</p>
     *
     * @param request  The servlet request we are processing.
     * @param response The servlet response we are creating.
     * @since Struts 1.2
     */
protected void processCachedMessages(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return;
    }
    // Remove messages as needed
    ActionMessages messages = (ActionMessages) session.getAttribute(Globals.MESSAGE_KEY);
    if (messages != null) {
        if (messages.isAccessed()) {
            session.removeAttribute(Globals.MESSAGE_KEY);
        }
    }
    // Remove error messages as needed
    messages = (ActionMessages) session.getAttribute(Globals.ERROR_KEY);
    if (messages != null) {
        if (messages.isAccessed()) {
            session.removeAttribute(Globals.ERROR_KEY);
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 29 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class Action method setLocale.

/**
     * <p>Set the user's currently selected <code>Locale</code> into their
     * <code>HttpSession</code>.</p>
     *
     * @param request The request we are processing
     * @param locale  The user's selected Locale to be set, or null to select
     *                the server's default Locale
     */
protected void setLocale(HttpServletRequest request, Locale locale) {
    HttpSession session = request.getSession();
    if (locale == null) {
        locale = Locale.getDefault();
    }
    session.setAttribute(Globals.LOCALE_KEY, locale);
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 30 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class TagUtils method computeParameters.

/**
     * Compute a set of query parameters that will be dynamically added to a
     * generated URL.  The returned Map is keyed by parameter name, and the
     * values are either null (no value specified), a String (single value
     * specified), or a String[] array (multiple values specified).  Parameter
     * names correspond to the corresponding attributes of the
     * <code>&lt;html:link&gt;</code> tag.  If no query parameters are
     * identified, return <code>null</code>.
     *
     * @param pageContext   PageContext we are operating in
     * @param paramId       Single-value request parameter name (if any)
     * @param paramName     Bean containing single-value parameter value
     * @param paramProperty Property (of bean named by <code>paramName</code>
     *                      containing single-value parameter value
     * @param paramScope    Scope containing bean named by <code>paramName</code>
     * @param name          Bean containing multi-value parameters Map (if
     *                      any)
     * @param property      Property (of bean named by <code>name</code>
     *                      containing multi-value parameters Map
     * @param scope         Scope containing bean named by <code>name</code>
     * @param transaction   Should we add our transaction control token?
     * @return Map of query parameters
     * @throws JspException if we cannot look up the required beans
     * @throws JspException if a class cast exception occurs on a looked-up
     *                      bean or property
     */
public Map computeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction) throws JspException {
    // Short circuit if no parameters are specified
    if ((paramId == null) && (name == null) && !transaction) {
        return (null);
    }
    // Locate the Map containing our multi-value parameters map
    Map map = null;
    try {
        if (name != null) {
            map = (Map) getInstance().lookup(pageContext, name, property, scope);
        }
    // @TODO - remove this - it is never thrown
    //        } catch (ClassCastException e) {
    //            saveException(pageContext, e);
    //            throw new JspException(
    //                    messages.getMessage("parameters.multi", name, property, scope));
    } catch (JspException e) {
        saveException(pageContext, e);
        throw e;
    }
    // Create a Map to contain our results from the multi-value parameters
    Map results = null;
    if (map != null) {
        results = new HashMap(map);
    } else {
        results = new HashMap();
    }
    // Add the single-value parameter (if any)
    if ((paramId != null) && (paramName != null)) {
        Object paramValue = null;
        try {
            paramValue = TagUtils.getInstance().lookup(pageContext, paramName, paramProperty, paramScope);
        } catch (JspException e) {
            saveException(pageContext, e);
            throw e;
        }
        if (paramValue != null) {
            String paramString = null;
            if (paramValue instanceof String) {
                paramString = (String) paramValue;
            } else {
                paramString = paramValue.toString();
            }
            Object mapValue = results.get(paramId);
            if (mapValue == null) {
                results.put(paramId, paramString);
            } else if (mapValue instanceof String[]) {
                String[] oldValues = (String[]) mapValue;
                String[] newValues = new String[oldValues.length + 1];
                System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
                newValues[oldValues.length] = paramString;
                results.put(paramId, newValues);
            } else {
                String[] newValues = new String[2];
                newValues[0] = mapValue.toString();
                newValues[1] = paramString;
                results.put(paramId, newValues);
            }
        }
    }
    // Add our transaction control token (if requested)
    if (transaction) {
        HttpSession session = pageContext.getSession();
        String token = null;
        if (session != null) {
            token = (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
        }
        if (token != null) {
            results.put(Constants.TOKEN_KEY, token);
        }
    }
    // Return the completed Map
    return (results);
}
Also used : JspException(javax.servlet.jsp.JspException) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HttpSession (javax.servlet.http.HttpSession)730 HttpServletRequest (javax.servlet.http.HttpServletRequest)151 Test (org.junit.Test)110 IOException (java.io.IOException)80 HttpServletResponse (javax.servlet.http.HttpServletResponse)80 ServletException (javax.servlet.ServletException)75 ArrayList (java.util.ArrayList)65 RequestDispatcher (javax.servlet.RequestDispatcher)59 HashMap (java.util.HashMap)48 Map (java.util.Map)44 Locale (java.util.Locale)39 Properties (java.util.Properties)39 PrintWriter (java.io.PrintWriter)38 Cookie (javax.servlet.http.Cookie)27 List (java.util.List)24 SQLException (java.sql.SQLException)23 WebUser (org.compiere.util.WebUser)23 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)20 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 ModelAndView (org.springframework.web.servlet.ModelAndView)20