Search in sources :

Example 46 with HttpSession

use of javax.servlet.http.HttpSession in project javaee7-samples by javaee-samples.

the class PublicServletPublicEJBLogout method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String webName = null;
    if (request.getUserPrincipal() != null) {
        webName = request.getUserPrincipal().getName();
    }
    String ejbName = "";
    try {
        ejbName = publicEJB.getUserName();
    } catch (Exception e) {
        logger.log(SEVERE, "", e);
    }
    request.logout();
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.invalidate();
    }
    String webNameAfterLogout = null;
    if (request.getUserPrincipal() != null) {
        webNameAfterLogout = request.getUserPrincipal().getName();
    }
    String ejbNameAfterLogout = "";
    try {
        ejbNameAfterLogout = publicEJB.getUserName();
    } catch (Exception e) {
        logger.log(SEVERE, "", e);
    }
    response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
    response.getWriter().write("web username after logout: " + webNameAfterLogout + "\n" + "EJB username after logout: " + ejbNameAfterLogout + "\n");
}
Also used : HttpSession(javax.servlet.http.HttpSession) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 47 with HttpSession

use of javax.servlet.http.HttpSession in project jfinal by jfinal.

the class JFinalSession method intercept.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void intercept(Invocation inv) {
    inv.invoke();
    Controller c = inv.getController();
    if (c.getRender() instanceof com.jfinal.render.JsonRender) {
        return;
    }
    HttpSession hs = c.getSession(createSession);
    if (hs != null) {
        Map session = new JFinalSession(hs);
        for (Enumeration<String> names = hs.getAttributeNames(); names.hasMoreElements(); ) {
            String name = names.nextElement();
            session.put(name, hs.getAttribute(name));
        }
        c.setAttr("session", session);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Controller(com.jfinal.core.Controller) Map(java.util.Map) HashMap(java.util.HashMap)

Example 48 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class RepayLoanActionForm method getUserLocale.

protected Locale getUserLocale(HttpServletRequest request) {
    Locale locale = null;
    HttpSession session = request.getSession();
    if (session != null) {
        UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (null != userContext) {
            locale = userContext.getCurrentLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Example 49 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class ApplyAdjustmentActionForm method getUserLocale.

protected Locale getUserLocale(HttpServletRequest request) {
    Locale locale = null;
    HttpSession session = request.getSession();
    if (session != null) {
        UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (null != userContext) {
            locale = userContext.getCurrentLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Example 50 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class MifosRequestProcessor method processActionPerform.

/**
     * This method is overridden because in case of exception we need to
     * populate the request with the old values so that when the user goes back
     * to the previous page it has all the values in the request.For this we
     * create an object which will store the values of previous request in case
     * the request is successful and if there is an exception it reads values
     * from that object and context and dups all in the request.
     */
@Override
protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
    ActivityContext activityContext = null;
    ActionForward forward = null;
    HttpSession session = request.getSession();
    // gets the object where we will store values from request.
    PreviousRequestValues previousRequestValues = (PreviousRequestValues) session.getAttribute(Constants.PREVIOUS_REQUEST);
    if (null == previousRequestValues) {
        previousRequestValues = new PreviousRequestValues();
        session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues);
    }
    // getting the activity context from the session
    activityContext = (ActivityContext) session.getAttribute("ActivityContext");
    try {
        String currentFlowKey = request.getParameter(Constants.CURRENTFLOWKEY);
        if (currentFlowKey != null) {
            previousRequestValues.getPreviousRequestValueMap().put(Constants.CURRENTFLOWKEY, currentFlowKey);
        }
        forward = (action.execute(mapping, form, request, response));
        String method = request.getParameter("method");
        if (method.equals(ClientConstants.METHOD_RETRIEVE_PICTURE)) {
            forward = mapping.findForward("get_success");
        }
        // set the last forward in the activity context
        if (activityContext != null) {
            activityContext.setLastForward(forward);
        }
        // read the request and add the values to the PreviousRequestValues
        // object. this will set every thing in the request apart from
        // context and value object.
        Enumeration requestAttributes = request.getAttributeNames();
        while (requestAttributes.hasMoreElements()) {
            String nextName = (String) requestAttributes.nextElement();
            if (nextName.startsWith(Constants.STORE_ATTRIBUTE) || nextName.equalsIgnoreCase(Constants.CURRENTFLOWKEY)) {
                logger.debug(nextName + "=" + request.getAttribute(nextName));
                previousRequestValues.getPreviousRequestValueMap().put(nextName, request.getAttribute(nextName));
            }
        }
    } catch (Exception e) {
        // processException logs an error (see MifosExceptionHandler)
        forward = (processException(request, response, e, form, mapping));
        // set the last forward in the activity context
        if (activityContext != null) {
            activityContext.setLastForward(forward);
        }
        populateTheRequestFromPreviousValues(request, previousRequestValues);
    } finally {
        try {
            session.removeAttribute(SecurityConstants.SECURITY_PARAM);
        } catch (Exception e) {
        // FIXME: yikes, what is being swallowed here?
        }
    }
    if (null != forward) {
        logger.info("forward.path=" + forward.getPath());
    }
    return forward;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Enumeration(java.util.Enumeration) PreviousRequestValues(org.mifos.framework.util.helpers.PreviousRequestValues) HttpSession(javax.servlet.http.HttpSession) ActionForward(org.apache.struts.action.ActionForward) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

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