Example usage for javax.servlet.jsp PageContext EXCEPTION

List of usage examples for javax.servlet.jsp PageContext EXCEPTION

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext EXCEPTION.

Prototype

String EXCEPTION

To view the source code for javax.servlet.jsp PageContext EXCEPTION.

Click Source Link

Document

Name used to store uncaught exception in ServletRequest attribute list and PageContext name table.

Usage

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandlerTest.java

/**
 * testExecute02()/*  w ww.j av  a2  s. c  o  m*/
 * <br><br>
 * 
 * ??n
 * <br>
 * _?FA
 * <br><br>
 * l?F(?) ex:Exception<br>
 *         (?) eConfig:not null<br>
 *         (?) mapping:not null<br>
 *               ?yinputtB?[h"/errorInput.do"??z
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:null<br>
 *         
 * <br>
 * l?F(l) ActionForward:tH??[h??F"/errorInput.do"<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION?A<br>
 *                    Oo^?B<br>
 *         
 * <br>
 * ?OSystemException?AANV}bsOinput?w?Ainput?wpXANVtH??[h?ReLXg?[gtrue??B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testExecute02() throws Exception {
    // O??
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeOO
    Exception e = new Exception();

    // O??
    ExceptionConfig eConfig = new ExceptionConfig();
    eConfig.setKey("action.message.key");

    // ANV}bsOInput??
    ActionMapping mapping = new ActionMapping();
    mapping.setInput("/errorInput.do");

    DynaActionForm form = new DynaActionForm();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    MockServletContext context = new MockServletContext();

    // T?[ubgReLXgNGXgQ??B
    session.setServletContext(context);
    req.setSession(session);

    // eXg{
    ActionForward forward = handler.execute(e, eConfig, mapping, form, req, res);

    // 

    // lmF
    assertEquals("/errorInput.do", forward.getPath());

    // NGXg??mF
    assertNull(req.getAttribute(PageContext.EXCEPTION));
}

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandler.java

/**
 * SystemExceptionOnhGg|Cg?B/*from  w w  w  .j a va2  s. c  o  m*/
 *
 * @param ex O
 * @param eConfig ORtBO
 * @param mapping ANV}bsO
 * @param formInstance ANVtH?[
 * @param request HTTPNGXg
 * @param response HTTPX|X
 *
 * @return J?
 *
 * @throws ServletException T?[ubgO
 *
 * @see jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler#execute(
 *  java.lang.Exception,
 *  org.apache.struts.config.ExceptionConfig,
 *  org.apache.struts.action.ActionMapping,
 *  org.apache.struts.action.ActionForm,
 *  javax.servlet.http.HttpServletRequest,
 *  javax.servlet.http.HttpServletResponse
 *  )
 */
@Override
public ActionForward execute(Exception ex, ExceptionConfig eConfig, ActionMapping mapping,
        ActionForm formInstance, HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    // ?ytH??[h???z
    // pathtH??[h?w???A
    // ANV}bsOinput?ftHg?B
    String path = null;
    if (eConfig.getPath() != null) {
        path = eConfig.getPath();
    } else {
        path = mapping.getInput();
    }
    ActionForward forward = new ActionForward(path);
    String logLevel = null;

    // ?yJ???z
    if (eConfig instanceof ExceptionConfigEx) {
        //J?W?[??AW?[?
        forward.setModule(((ExceptionConfigEx) eConfig).getModule());
        // ?Ox
        logLevel = ((ExceptionConfigEx) eConfig).getLogLevel();
    }

    // ?ySystemException???AG?[L?[G?[?bZ?[Wu?s?z
    if (ex instanceof SystemException) {
        SystemException se = (SystemException) ex;

        // ?yNGXg?bZ?[W\?[X?B?z
        MessageResources resources = null;

        // XR?[v?bZ?[W\?[X?ohL?[?B
        String bundle = eConfig.getBundle();
        if (bundle == null) {
            // struts-config.xmlmessage-resources
            // bundle?w???A
            // ftHgohL?[?
            bundle = Globals.MESSAGES_KEY;
        }

        // NGXg??B
        resources = (MessageResources) request.getAttribute(bundle);
        if (resources == null) {
            // NGXg?AvP?[V??B
            resources = (MessageResources) RequestUtil.getServletContext(request).getAttribute(bundle);
        }

        // ?yG?[L?[G?[?bZ?[Wu?s?z
        // SystemExceptionG?[L?[G?[?bZ?[Wu?B
        String message = null;
        if (resources == null) {
            // \?[X??G?[L?[?bZ?[W
            message = se.getErrorCode();
        } else {
            message = getErrorMessage(request, se, resources);
        }
        se.setMessage(message);

        // ?y\pActionMessage??z
        String key = eConfig.getKey();
        ActionMessage error = null;
        if (resources != null) {
            // G?[?bZ?[Wu
            String[] options = se.getOptions();

            if (options != null && options.length > 0) {
                error = new ActionMessage(key, options);
            } else {
                error = new ActionMessage(key);
            }
        } else {
            // ?bZ?[W\?[X??G?[L?[?bZ?[W
            error = new ActionMessage(key, false);
        }
        super.storeException(request, key, error, forward, eConfig.getScope());

        // O?bZ?[W?AX^bNg?[X
        // ZbVnbVl?O?o
        String sessionHash = RequestUtil.getSessionHash(request);
        logException(logLevel, "sessionHash = " + sessionHash);
        logException(logLevel, ExceptionUtil.getStackTrace(se));

        // ?yu?SystemException??z
        // VXeOJSPG?[y?[W exception 
        //  request ?
        request.setAttribute(PageContext.EXCEPTION, se);
    }

    // VXeG?[?AANV}bsO?J?B
    return forward;
}

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandlerTest.java

/**
 * testExecute03()//from   w ww  . j  a  v  a 2s. com
 * <br><br>
 * 
 * ?n
 * <br>
 * _?FA
 * <br><br>
 * l?F(?) ex:SystemException optionString=null<br>
 *         (?) eConfig:ExceptionConfig<br>
 *               ?ypathtB?[h"/errorPath.do"??z<br>
 *         (?) mapping:not null<br>
 *               ?yinputtB?[h"/errorInput.do"??z
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:null<br>
 *         (?) resources:?yNGXg??z<br>
 *                Globals.MESSAGES_KEYMessageResourceMessageResources<br>
 *                MessageResources?o<br>
 *                 SystemExceptionHandlerTest.error.message="O?bZ?[W"<br>
 *                }<br>
 *         
 * <br>
 * l?F(l) ActionForward:tH??[h??F"/errorPath.do"<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION?FSystemException<br>
 *         (?) se:G?[?bZ?[W?F"O?bZ?[W"<br>
 *         (?) ActionMessages?F"action.message.key"o^
 *                                    valuesnull
 *         (?) ?O:?yG?[?O?z<br>
 *                    ??bZ?[W?<br>
 *                    "sessionHash = " + sessionHash<br>
 *                    ExceptionUtil.getStackTrace(se)<br>
 *         
 * <br>
 * O??path??AANV}bsOinput?w?Apath?D??B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
@SuppressWarnings("static-access")
public void testExecute03() throws Exception {
    // O??

    // VXeOnh
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeO
    SystemException e = new SystemException(new Exception(), "SystemExceptionHandlerTest.error.message");

    // O??
    ExceptionConfig eConfig = new ExceptionConfig();
    eConfig.setPath("/errorPath.do");
    eConfig.setKey("action.message.key");

    // ANV}bsOInput??
    ActionMapping mapping = new ActionMapping();
    mapping.setInput("/errorInput.do");

    DynaActionForm form = new DynaActionForm();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    MockServletContext context = new MockServletContext();

    // MessageResources?
    MessageResourcesFactory factory = PropertyMessageResourcesFactory.createFactory();
    PropertyMessageResources requestResources = new PropertyMessageResources(factory,
            SystemExceptionHandler.class.getPackage().getName().replace('.', '/')
                    + "/SystemExceptionHandler_MessageResources01");

    // NGXgMessageResourceso^
    req.setAttribute(Globals.MESSAGES_KEY, requestResources);

    // T?[ubgReLXgNGXgQ??B
    session.setServletContext(context);
    req.setSession(session);

    // eXg{
    ActionForward forward = handler.execute(e, eConfig, mapping, form, req, res);

    // 

    // lmF
    assertEquals("/errorPath.do", forward.getPath());

    // NGXg?mF
    assertSame(e, req.getAttribute(PageContext.EXCEPTION));

    // O?mF
    assertEquals("O?bZ?[W", UTUtil.getPrivateField(e, "message"));

    // ActionMessages?mF
    ActionMessages messages = (ActionMessages) req.getAttribute(Globals.ERROR_KEY);
    assertEquals(1, messages.size());
    Iterator it = messages.get();
    while (it.hasNext()) {
        ActionMessage actionMessage = (ActionMessage) it.next();
        assertEquals("action.message.key", actionMessage.getKey());
        assertNull(actionMessage.getValues());
    }

    // ?O?omF
    String sessionHash = RequestUtil.getSessionHash(req);
    assertTrue(LogUTUtil.checkError("sessionHash = " + sessionHash));
    assertTrue(LogUTUtil.checkError(ExceptionUtil.getStackTrace(e)));
}

From source file:com.liferay.portal.action.LoginAction.java

public static void login(HttpServletRequest req, HttpServletResponse res, String login, String password,
        boolean rememberMe) throws Exception {

    CookieKeys.validateSupportCookie(req);

    HttpSession ses = req.getSession();// w  w w  . j a v  a 2s .  co  m

    long userId = GetterUtil.getLong(login);

    int authResult = Authenticator.FAILURE;

    Company company = PortalUtil.getCompany(req);

    //
    boolean ldaplogin = false;
    if (PrefsPropsUtil.getString(company.getCompanyId(), PropsUtil.LDAP_AUTH_ENABLED).equals("true")) {
        LdapContext ctx = PortalLDAPUtil.getContext(company.getCompanyId());
        String accountname = "";
        try {
            User user1 = UserLocalServiceUtil.getUserByScreenName(company.getCompanyId(), login);
            Properties env = new Properties();

            String baseProviderURL = PrefsPropsUtil.getString(company.getCompanyId(),
                    PropsUtil.LDAP_BASE_PROVIDER_URL);
            String userDN = PrefsPropsUtil.getString(company.getCompanyId(), PropsUtil.LDAP_USERS_DN);
            String baseDN = PrefsPropsUtil.getString(company.getCompanyId(), PropsUtil.LDAP_BASE_DN);
            String filter = PrefsPropsUtil.getString(company.getCompanyId(), PropsUtil.LDAP_AUTH_SEARCH_FILTER);
            filter = StringUtil.replace(filter,
                    new String[] { "@company_id@", "@email_address@", "@screen_name@", "@user_id@" },
                    new String[] { String.valueOf(company.getCompanyId()), "", login, login });
            try {
                SearchControls cons = new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 0, null, false,
                        false);

                NamingEnumeration enu = ctx.search(userDN, filter, cons);
                if (enu.hasMoreElements()) {
                    SearchResult result = (SearchResult) enu.nextElement();
                    accountname = result.getName();
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            }

            env.put(Context.INITIAL_CONTEXT_FACTORY, PrefsPropsUtil.getString(PropsUtil.LDAP_FACTORY_INITIAL));
            env.put(Context.PROVIDER_URL, LDAPUtil.getFullProviderURL(baseProviderURL, baseDN));
            env.put(Context.SECURITY_PRINCIPAL, accountname + "," + userDN);
            env.put(Context.SECURITY_CREDENTIALS, password);

            new InitialLdapContext(env, null);
            ldaplogin = true;
            System.out.println("LDAP Login");
        } catch (Exception e) {
            SessionErrors.add(req, "ldapAuthentication");
            e.printStackTrace();
            System.out.println("LDAP error login");
            return;
        }
    }

    //

    Map headerMap = new HashMap();

    Enumeration enu1 = req.getHeaderNames();

    while (enu1.hasMoreElements()) {
        String name = (String) enu1.nextElement();

        Enumeration enu2 = req.getHeaders(name);

        List headers = new ArrayList();

        while (enu2.hasMoreElements()) {
            String value = (String) enu2.nextElement();

            headers.add(value);
        }

        headerMap.put(name, (String[]) headers.toArray(new String[0]));
    }

    Map parameterMap = req.getParameterMap();

    if (company.getAuthType().equals(CompanyImpl.AUTH_TYPE_EA)) {
        authResult = UserLocalServiceUtil.authenticateByEmailAddress(company.getCompanyId(), login, password,
                headerMap, parameterMap);

        userId = UserLocalServiceUtil.getUserIdByEmailAddress(company.getCompanyId(), login);
    } else if (company.getAuthType().equals(CompanyImpl.AUTH_TYPE_SN)) {
        authResult = UserLocalServiceUtil.authenticateByScreenName(company.getCompanyId(), login, password,
                headerMap, parameterMap);

        userId = UserLocalServiceUtil.getUserIdByScreenName(company.getCompanyId(), login);
    } else if (company.getAuthType().equals(CompanyImpl.AUTH_TYPE_ID)) {
        authResult = UserLocalServiceUtil.authenticateByUserId(company.getCompanyId(), userId, password,
                headerMap, parameterMap);
    }

    boolean OTPAuth = false;

    if (GetterUtil.getBoolean(PropsUtil.get("use.yubicoauthentication"), false) == true) {
        String otppasswd = ParamUtil.getString(req, "otp");
        String userslist = GetterUtil.getString(PropsUtil.get("yubico.users.not.require.otp"), "root");
        if (userslist.contains(login)) {
            authResult = Authenticator.SUCCESS;
        } else {
            OTPAuth = SecurityUtils.verifyOTP(otppasswd, login);
            if (authResult == Authenticator.SUCCESS && OTPAuth) {
                authResult = Authenticator.SUCCESS;
            } else {
                authResult = Authenticator.FAILURE;
            }
        }
    }

    if (PrefsPropsUtil.getString(company.getCompanyId(), PropsUtil.LDAP_AUTH_ENABLED).equals("true")) {
        if (!login.equals("root")) {
            if (ldaplogin) {
                authResult = Authenticator.SUCCESS;
            }
        }
    }

    if (authResult == Authenticator.SUCCESS) {

        boolean loginViaPortal = true;

        setLoginCookies(req, res, ses, userId, rememberMe);
        // login to epsos
        String language = GeneralUtils.getLocale(req);
        SpiritEhrWsClientInterface webService = EpsosHelperService.getInstance().getWebService(req);

        InitUserObj initUserObj = EpsosHelperImpl.createEpsosUserInformation(req, res, language, webService,
                userId, company.getCompanyId(), login, loginViaPortal);
        SpiritUserClientDto usr = initUserObj.getUsr();
        Assertion assertion = initUserObj.getAssertion();

        if (Validator.isNotNull(usr)) {
            req.getSession().setAttribute(EpsosHelperService.EPSOS_LOGIN_INFORMATION_ASSERTIONID,
                    assertion.getID());
            req.getSession().setAttribute(EpsosHelperService.EPSOS_LOGIN_INFORMATION_ASSERTION, assertion);
            req.getSession().setAttribute(EPSOS_LOGIN_INFORMATION_ATTRIBUTE, usr);
        } else {
            SessionErrors.add(req, "User doesn't belong to epSOS role so you can't login");
        }

        if (Validator.isNull(usr) && (!(login.equals("root")))) {
            try {
                Cookie cookie = new Cookie(CookieKeys.ID, StringPool.BLANK);
                cookie.setMaxAge(0);
                cookie.setPath("/");

                CookieKeys.addCookie(res, cookie);

                cookie = new Cookie(CookieKeys.PASSWORD, StringPool.BLANK);
                cookie.setMaxAge(0);
                cookie.setPath("/");

                CookieKeys.addCookie(res, cookie);

                try {
                    ses.invalidate();
                } catch (Exception e) {
                }

            } catch (Exception e) {
                req.setAttribute(PageContext.EXCEPTION, e);

            }
            throw new AuthException();

        }

    } else {
        throw new AuthException();
    }
}

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandlerTest.java

/**
 * testExecute04()//from  www. j  ava 2s . c  o  m
 * <br><br>
 * 
 * ?n
 * <br>
 * _?FC
 * <br><br>
 * l?F(?) ex:SystemException optionString=null<br>
 *         (?) eConfig:not null<br>
 *         (?) mapping:not null<br>
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:null<br>
 *         (?) resources:?yNGXg??z<br>
 *                Globals.MESSAGES_KEYMessageResourceMessageResources<br>
 *                MessageResources?o<br>
 *                 SystemExceptionHandlerTest.error.message="O?bZ?[W"<br>
 *                ?p<br>
 *         
 * <br>
 * l?F(l) ActionForward:tH??[h??Fnull<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION?A<br>
 *                    SystemExceptiono^?B<br>
 *         (?) se:G?[?bZ?[W?F"O?bZ?[W"<br>
 *         (?) ActionMessages?F"action.message.key"o^
 *                                    valuesnull
 *         (?) ?O:?yG?[?O?z<br>
 *                    ??bZ?[W?<br>
 *                    "sessionHash = " + sessionHash<br>
 *                    ExceptionUtil.getStackTrace(se)<br>
 *         
 * <br>
 * O??path??AANV}bsOinput?null?AANVtH??[hJ?null?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
@SuppressWarnings("static-access")
public void testExecute04() throws Exception {
    // O??

    // VXeOnh
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeO
    SystemException e = new SystemException(new Exception(), "SystemExceptionHandlerTest.error.message");

    ExceptionConfig eConfig = new ExceptionConfig();
    eConfig.setKey("action.message.key");

    ActionMapping mapping = new ActionMapping();
    DynaActionForm form = new DynaActionForm();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    MockServletContext context = new MockServletContext();

    // MessageResources
    MessageResourcesFactory factory = PropertyMessageResourcesFactory.createFactory();
    PropertyMessageResources requestResources = new PropertyMessageResources(factory,
            SystemExceptionHandler.class.getPackage().getName().replace('.', '/')
                    + "/SystemExceptionHandler_MessageResources01");

    // NGXgMessageResources?
    req.setAttribute(Globals.MESSAGES_KEY, requestResources);

    // T?[ubgReLXgNGXgQ??B
    session.setServletContext(context);
    req.setSession(session);

    // eXg{
    ActionForward forward = handler.execute(e, eConfig, mapping, form, req, res);

    // 

    // lmF
    assertNull(forward.getPath());

    // NGXg??mF
    assertSame(e, req.getAttribute(PageContext.EXCEPTION));

    // VXeO?mF?B
    assertEquals("O?bZ?[W", UTUtil.getPrivateField(e, "message"));

    // ActionMessages?mF
    ActionMessages messages = (ActionMessages) req.getAttribute(Globals.ERROR_KEY);
    assertEquals(1, messages.size());
    Iterator it = messages.get();
    while (it.hasNext()) {
        ActionMessage actionMessage = (ActionMessage) it.next();
        assertEquals("action.message.key", actionMessage.getKey());
        assertNull(actionMessage.getValues());
    }

    // ?O?omF
    String sessionHash = RequestUtil.getSessionHash(req);
    assertTrue(LogUTUtil.checkError("sessionHash = " + sessionHash));
    assertTrue(LogUTUtil.checkError(ExceptionUtil.getStackTrace(e)));
}

From source file:com.liferay.portal.servlet.MainServlet.java

public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

    if (!PortalInstances.matches()) {
        String html = ContentUtil.get("messages/en_US/init.html");

        res.getOutputStream().print(html);

        return;//from www .  jav  a2s  . com
    }

    if (ShutdownUtil.isShutdown()) {
        String html = ContentUtil.get("messages/en_US/shutdown.html");

        res.getOutputStream().print(html);

        return;
    }
    req.setAttribute("dotcache", "no");
    // Shared session

    HttpSession ses = req.getSession();

    if (!GetterUtil.getBoolean(PropsUtil.get(PropsUtil.TCK_URL))) {
        String sharedSessionId = CookieUtil.get(req.getCookies(), CookieKeys.SHARED_SESSION_ID);

        _log.debug("Shared session id is " + sharedSessionId);

        if (sharedSessionId == null) {
            sharedSessionId = PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12);

            Cookie sharedSessionIdCookie = new Cookie(CookieKeys.SHARED_SESSION_ID, sharedSessionId);
            sharedSessionIdCookie.setPath("/");
            sharedSessionIdCookie.setMaxAge(86400);

            res.addCookie(sharedSessionIdCookie);

            _log.debug("Shared session id is " + sharedSessionId);
        }

        // if (ses.getAttribute(WebKeys.SHARED_SESSION_ID) == null) {
        ses.setAttribute(WebKeys.SHARED_SESSION_ID, sharedSessionId);
        // }

        HttpSession portalSes = (HttpSession) SharedSessionPool.get(sharedSessionId);

        if ((portalSes == null) || (ses != portalSes)) {
            if (portalSes == null) {
                _log.debug("No session exists in pool");
            } else {
                _log.debug("Session " + portalSes.getId() + " in pool is old");
            }

            _log.debug("Inserting current session " + ses.getId() + " in pool");

            SharedSessionPool.put(sharedSessionId, ses);
        }
    }

    // Test CAS auto login

    /*
     * ses.setAttribute(
     * com.liferay.portal.auth.CASAutoLogin.CAS_FILTER_USER,
     * "liferay.com.1");
     */

    // CTX

    ServletContext ctx = getServletContext();
    ServletContext portalCtx = ctx.getContext(PropsUtil.get(PropsUtil.PORTAL_CTX));
    if (portalCtx == null) {
        portalCtx = ctx;
    }

    req.setAttribute(WebKeys.CTX, portalCtx);

    // CTX_PATH variable

    String ctxPath = (String) ctx.getAttribute(WebKeys.CTX_PATH);

    if (portalCtx.getAttribute(WebKeys.CTX_PATH) == null) {
        portalCtx.setAttribute(WebKeys.CTX_PATH, ctxPath);
    }

    if (ses.getAttribute(WebKeys.CTX_PATH) == null) {
        ses.setAttribute(WebKeys.CTX_PATH, ctxPath);
    }

    req.setAttribute(WebKeys.CTX_PATH, ctxPath);

    // CAPTCHA_PATH variable

    String captchaPath = (String) ctx.getAttribute(WebKeys.CAPTCHA_PATH);

    if (portalCtx.getAttribute(WebKeys.CAPTCHA_PATH) == null) {
        portalCtx.setAttribute(WebKeys.CAPTCHA_PATH, captchaPath);
    }

    if (ses.getAttribute(WebKeys.CAPTCHA_PATH) == null) {
        ses.setAttribute(WebKeys.CAPTCHA_PATH, captchaPath);
    }

    req.setAttribute(WebKeys.CAPTCHA_PATH, captchaPath);

    // IMAGE_PATH variable

    String imagePath = (String) ctx.getAttribute(WebKeys.IMAGE_PATH);

    if (portalCtx.getAttribute(WebKeys.IMAGE_PATH) == null) {
        portalCtx.setAttribute(WebKeys.IMAGE_PATH, imagePath);
    }

    if (ses.getAttribute(WebKeys.IMAGE_PATH) == null) {
        ses.setAttribute(WebKeys.IMAGE_PATH, imagePath);
    }

    req.setAttribute(WebKeys.IMAGE_PATH, imagePath);

    // WebKeys.COMPANY_ID variable

    String companyId = (String) ctx.getAttribute(WebKeys.COMPANY_ID);

    if (portalCtx.getAttribute(WebKeys.COMPANY_ID) == null) {
        portalCtx.setAttribute(WebKeys.COMPANY_ID, companyId);
    }

    if (ses.getAttribute(WebKeys.COMPANY_ID) == null) {
        ses.setAttribute(WebKeys.COMPANY_ID, companyId);
    }

    req.setAttribute(WebKeys.COMPANY_ID, companyId);

    // Portlet Request Processor

    PortletRequestProcessor portletReqProcessor = (PortletRequestProcessor) portalCtx
            .getAttribute(WebKeys.PORTLET_STRUTS_PROCESSOR);

    if (portletReqProcessor == null) {
        portletReqProcessor = new PortletRequestProcessor(this, getModuleConfig(req));

        portalCtx.setAttribute(WebKeys.PORTLET_STRUTS_PROCESSOR, portletReqProcessor);
    }

    // Tiles definitions factory

    if (portalCtx.getAttribute(TilesUtilImpl.DEFINITIONS_FACTORY) == null) {
        portalCtx.setAttribute(TilesUtilImpl.DEFINITIONS_FACTORY,
                ctx.getAttribute(TilesUtilImpl.DEFINITIONS_FACTORY));
    }

    // Set character encoding

    String strutsCharEncoding = PropsUtil.get(PropsUtil.STRUTS_CHAR_ENCODING);

    req.setCharacterEncoding(strutsCharEncoding);

    /*
     * if (!BrowserSniffer.is_wml(req)) { res.setContentType(
     * Constants.TEXT_HTML + "; charset=" + strutsCharEncoding); }
     */

    // Determine content type

    String contentType = req.getHeader("Content-Type");

    if ((contentType != null) && (contentType.startsWith("multipart/form-data"))) {

        req = new UploadServletRequest(req);
    } else if (ParamUtil.get(req, WebKeys.ENCRYPT, false)) {
        try {
            Company company = CompanyLocalManagerUtil.getCompany(companyId);

            req = new EncryptedServletRequest(req, company.getKeyObj());
        } catch (Exception e) {
        }
    }

    // Current URL

    String completeURL = Http.getCompleteURL(req);
    if (completeURL.indexOf("j_security_check") != -1) {
        completeURL = ctxPath;
    } else {
        completeURL = completeURL.substring(completeURL.indexOf("://") + 3, completeURL.length());

        completeURL = completeURL.substring(completeURL.indexOf("/"), completeURL.length());
    }

    req.setAttribute(WebKeys.CURRENT_URL, completeURL);

    // Chat server

    // Login

    String userId = PortalUtil.getUserId(req);

    if ((userId != null)) {
        PrincipalThreadLocal.setName(userId);
    }

    if (userId == null) {
        try {
            User user = UserManagerUtil.getDefaultUser(companyId);
            if (ses.getAttribute(Globals.LOCALE_KEY) == null)
                ses.setAttribute(Globals.LOCALE_KEY, user.getLocale());

        } catch (Exception e) {
            Logger.error(this, e.getMessage(), e);
        }
    }

    // Process pre service events

    try {
        EventsProcessor.process(PropsUtil.getArray(PropsUtil.SERVLET_SERVICE_EVENTS_PRE), req, res);
    } catch (Exception e) {
        Logger.error(this, e.getMessage(), e);

        req.setAttribute(PageContext.EXCEPTION, e);

        StrutsUtil.forward(PropsUtil.get(PropsUtil.SERVLET_SERVICE_EVENTS_PRE_ERROR_PAGE), portalCtx, req, res);
    }

    // Struts service

    callParentService(req, res);

    // Process post service events

    try {
        EventsProcessor.process(PropsUtil.getArray(PropsUtil.SERVLET_SERVICE_EVENTS_POST), req, res);
    } catch (Exception e) {
        Logger.error(this, e.getMessage(), e);
    }

    // Clear the principal associated with this thread

    PrincipalThreadLocal.setName(null);
}

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandlerTest.java

/**
 * testExecute05()/*w ww. j av  a 2 s  .  c  om*/
 * <br><br>
 * 
 * ??n
 * <br>
 * _?FC
 * <br><br>
 * l?F(?) ex:SystemException optionString=null<br>
 *         (?) eConfig:ExceptionConfig<br>
 *               ?ypathtB?[h"/errorPath.do"??z<br>
 *         (?) mapping:MockActionMapping<br>
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:Globals.MESSAGE_KEY<br>
 *         (?) resources:?yNGXg??z<br>
 *                Globals.MESSAGES_KEYMessageResourceMessageResources<br>
 *                MessageResources?o<br>
 *                 SystemExceptionHandlerTest.error.message ="O?bZ?[W"<br>
 *                ?p<br>
 *         
 * <br>
 * l?F(l) ActionForward:tH??[h??F"/errorPath.do"<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION?A<br>
 *                    SystemExceptiono^?B<br>
 *         (?) se:G?[?bZ?[W?F"O?bZ?[W"<br>
 *                    ??B<br>
 *         (?) ActionMessages?F"action.message.key"o^
 *                                    valuesnull
 *         (?) ?O:?yG?[?O?z<br>
 *                    ??bZ?[W?<br>
 *                    "sessionHash = " + sessionHash<br>
 *                    ExceptionUtil.getStackTrace(se)<br>
 *         
 * <br>
 * O??bundle?Globals.MESSAGE_KEY?AL?[Globals.MESSAGE_KEYMessageResourcesp?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
@SuppressWarnings("static-access")
public void testExecute05() throws Exception {
    // O??

    // VXeOnh
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeO
    SystemException e = new SystemException(new Exception(), "SystemExceptionHandlerTest.error.message");

    // O??
    ExceptionConfig eConfig = new ExceptionConfig();
    eConfig.setPath("/errorPath.do");
    // ANV?bZ?[WL?[w
    eConfig.setKey("action.message.key");
    // ?bZ?[W\?[XohL?[w
    eConfig.setBundle(Globals.MESSAGES_KEY);

    ActionMapping mapping = new ActionMapping();
    DynaActionForm form = new DynaActionForm();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    MockServletContext context = new MockServletContext();

    // MessageResources
    MessageResourcesFactory factory = PropertyMessageResourcesFactory.createFactory();
    PropertyMessageResources requestResources = new PropertyMessageResources(factory,
            SystemExceptionHandler.class.getPackage().getName().replace('.', '/')
                    + "/SystemExceptionHandler_MessageResources01");

    // NGXgMessageResourceso^
    req.setAttribute(Globals.MESSAGES_KEY, requestResources);

    // T?[ubgReLXgNGXgQ??B
    session.setServletContext(context);
    req.setSession(session);

    // eXg{
    ActionForward forward = handler.execute(e, eConfig, mapping, form, req, res);

    // 

    // lmF
    assertEquals("/errorPath.do", forward.getPath());

    // NGXg??mF
    assertSame(e, req.getAttribute(PageContext.EXCEPTION));

    // VXeO?mF
    assertEquals("O?bZ?[W", UTUtil.getPrivateField(e, "message"));

    // ActionMessages?mF
    ActionMessages messages = (ActionMessages) req.getAttribute(Globals.ERROR_KEY);
    assertEquals(1, messages.size());
    Iterator it = messages.get();
    while (it.hasNext()) {
        ActionMessage actionMessage = (ActionMessage) it.next();
        assertEquals("action.message.key", actionMessage.getKey());
        assertNull(actionMessage.getValues());
    }

    // ?O?omF
    String sessionHash = RequestUtil.getSessionHash(req);
    assertTrue(LogUTUtil.checkError("sessionHash = " + sessionHash));
    assertTrue(LogUTUtil.checkError(ExceptionUtil.getStackTrace(e)));
}

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandlerTest.java

/**
 * testExecute06()/*from  w w w .  j  a v  a2s. c o m*/
 * <br><br>
 * 
 * ??n
 * <br>
 * _?FA
 * <br><br>
 * l?F(?) ex:SystemException optionString=null<br>
 *         (?) eConfig:ExceptionConfig<br>
 *               ?ypathtB?[h"/errorPath.do"??z<br>
 *         (?) mapping:MockActionMapping<br>
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:anotherKey<br>
 *         (?) resources:?yNGXg??z<br>
 *               Globals.MESSAGES_KEYMessageResourceMessageResources<br>
 *               MessageResources?o<br>
 *                SystemExceptionHandlerTest.error.message ="O?bZ?[W"<br>
 *               ?p<br>
 *               anotherKeynull<br>
 *               ?yT?[ubgReLXg??z<br>
 *               anotherKeyMessageResourceMessageResources<br>
 *               MessageResources?o<br>
 *                SystemExceptionHandlerTest.error.message ="T?[ubgO?bZ?[W"<br>
 *               ?p<br>
 * <br>
 * l?F(l) ActionForward:tH??[h??F"/errorPath.do"<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION:<br>
 *                    SystemExceptiono^?B<br>
 *         (?) se:G?[?bZ?[W?F"T?[ubgO?bZ?[W"<br>
 *         (?) ActionMessages?F"action.message.key"o^
 *                                    valuesnull
 *         (?) ?O:?yG?[?O?z<br>
 *                    ??bZ?[W?<br>
 *                    "sessionHash = " + sessionHash<br>
 *                    ExceptionUtil.getStackTrace(se)<br>
 *         
 * <br>
 * O??bundle??AT?[ubgReLXgL?[?AT?[ubgReLXgi[?bZ?[W\?[X<br>
 * p?B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
@SuppressWarnings("static-access")
public void testExecute06() throws Exception {
    // O??

    // VXeOnh
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeO
    SystemException e = new SystemException(new Exception(), "SystemExceptionHandlerTest.error.message");

    // O??
    ExceptionConfig eConfig = new ExceptionConfig();
    eConfig.setPath("/errorPath.do");
    // ?bZ?[W\?[XohL?[w
    eConfig.setBundle("anotherKey");
    // ANV?bZ?[WL?[
    eConfig.setKey("action.message.key");

    ActionMapping mapping = new ActionMapping();
    DynaActionForm form = new DynaActionForm();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    MockServletContext context = new MockServletContext();

    // MessageResources
    MessageResourcesFactory factory = PropertyMessageResourcesFactory.createFactory();
    PropertyMessageResources requestResources = new PropertyMessageResources(factory,
            SystemExceptionHandler.class.getPackage().getName().replace('.', '/')
                    + "/SystemExceptionHandler_MessageResources01");
    PropertyMessageResources servletResources = new PropertyMessageResources(factory,
            SystemExceptionHandler.class.getPackage().getName().replace('.', '/')
                    + "/SystemExceptionHandler_MessageResources02");

    // T?[ubgReLXgMessageResourceso^
    context.setAttribute("anotherKey", servletResources);

    // NGXg?bZ?[W\?[Xo^
    req.setAttribute(Globals.MESSAGES_KEY, requestResources);

    // T?[ubgReLXgNGXgQ??B
    session.setServletContext(context);
    req.setSession(session);

    // eXg{
    ActionForward forward = handler.execute(e, eConfig, mapping, form, req, res);

    // 

    // lmF
    assertEquals("/errorPath.do", forward.getPath());

    // NGXg??mF
    assertSame(e, req.getAttribute(PageContext.EXCEPTION));

    // ActionMessages?mF
    ActionMessages messages = (ActionMessages) req.getAttribute(Globals.ERROR_KEY);
    assertEquals(1, messages.size());
    Iterator it = messages.get();
    while (it.hasNext()) {
        ActionMessage actionMessage = (ActionMessage) it.next();
        assertEquals("action.message.key", actionMessage.getKey());
        assertNull(actionMessage.getValues());
    }

    // VXeO?mF
    assertEquals("T?[ubgO?bZ?[W", UTUtil.getPrivateField(e, "message"));

    // ?O?omF
    String sessionHash = RequestUtil.getSessionHash(req);
    assertTrue(LogUTUtil.checkError("sessionHash = " + sessionHash));
    assertTrue(LogUTUtil.checkError(ExceptionUtil.getStackTrace(e)));

}

From source file:jp.terasoluna.fw.web.struts.action.SystemExceptionHandlerTest.java

/**
 * testExecute07()//from  ww  w.  j  a v a 2s  . c  om
 * <br><br>
 * 
 * ??n
 * <br>
 * _?FC
 * <br><br>
 * l?F(?) ex:SystemException optionString=null<br>
 *         (?) eConfig:ExceptionConfig<br>
 *               ?ypathtB?[h"/errorPath.do"??z<br>
 *         (?) mapping:MockActionMapping<br>
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:null<br>
 *         (?) resources:?yNGXg??z<br>
 *               Globals.MESSAGES_KEYnull<br>
 *               ?yT?[ubgReLXg??z<br>
 *               Globals.MESSAGES_KEYnull<br>
 * <br>
 * l?F(l) ActionForward:tH??[h??F"/errorPath.do"<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION?A<br>
 *                    SystemExceptiono^?B<br>
 *         (?) se:G?[?bZ?[W?F"SystemExceptionHandlerTest.error.message"<br>
 *         (?) ActionMessages?F"action.message.key"o^
 *                                    resourcetB?[hfalse
 *                                    valuesnull
 *         (?) ?O:?yG?[?O?z<br>
 *                    ??bZ?[W?<br>
 *                    "sessionHash = " + sessionHash<br>
 *                    ExceptionUtil.getStackTrace(se)<br>
 *         
 * <br>
 * ?bZ?[W\?[X?AG?[R?[h?bZ?[W??B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testExecute07() throws Exception {
    // O??

    // VXeOnh
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeO
    SystemException e = new SystemException(new Exception(), "SystemExceptionHandlerTest.error.message");

    // O??
    ExceptionConfig eConfig = new ExceptionConfig();
    eConfig.setPath("/errorPath.do");
    eConfig.setKey("action.message.key");

    ActionMapping mapping = new ActionMapping();
    DynaActionForm form = new DynaActionForm();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    MockServletContext context = new MockServletContext();

    // ?bZ?[W\?[X?

    // T?[ubgReLXgNGXgQ??B
    session.setServletContext(context);
    req.setSession(session);

    // eXg{
    ActionForward forward = handler.execute(e, eConfig, mapping, form, req, res);

    // 

    // lmF
    assertEquals("/errorPath.do", forward.getPath());

    // NGXg??mF
    assertSame(e, req.getAttribute(PageContext.EXCEPTION));

    // VXeO?mF
    assertEquals("SystemExceptionHandlerTest.error.message", UTUtil.getPrivateField(e, "message"));

    // ActionMessages?mF
    ActionMessages messages = (ActionMessages) req.getAttribute(Globals.ERROR_KEY);
    assertEquals(1, messages.size());
    Iterator it = messages.get();
    while (it.hasNext()) {
        ActionMessage actionMessage = (ActionMessage) it.next();
        assertEquals("action.message.key", actionMessage.getKey());
        assertFalse(actionMessage.isResource());
        assertNull(actionMessage.getValues());
    }

    // ?O?omF
    String sessionHash = RequestUtil.getSessionHash(req);
    assertTrue(LogUTUtil.checkError("sessionHash = " + sessionHash));
    assertTrue(LogUTUtil.checkError(ExceptionUtil.getStackTrace(e)));
}

From source file:com.liferay.portal.action.LoginAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req,
        HttpServletResponse res) throws Exception {

    HttpSession ses = req.getSession();//ww  w.ja v a2s .co  m

    ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);

    if (ses.getAttribute("j_username") != null && ses.getAttribute("j_password") != null) {

        if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.PORTAL_JAAS_ENABLE))) {

            return mapping.findForward("/portal/touch_protected.jsp");
        } else {
            res.sendRedirect(themeDisplay.getPathMain());

            return null;
        }
    }

    String cmd = ParamUtil.getString(req, Constants.CMD);

    if (cmd.equals("already-registered")) {
        try {
            login(req, res);

            if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.PORTAL_JAAS_ENABLE))) {

                return mapping.findForward("/portal/touch_protected.jsp");
            } else {
                String redirect = ParamUtil.getString(req, "redirect");

                if (Validator.isNotNull(redirect)) {
                    res.sendRedirect(redirect);
                } else {
                    res.sendRedirect(themeDisplay.getPathMain());
                }

                return null;
            }
        } catch (Exception e) {
            if (e instanceof AuthException) {
                Throwable cause = e.getCause();

                if (cause instanceof PasswordExpiredException || cause instanceof UserLockoutException) {

                    SessionErrors.add(req, cause.getClass().getName());
                } else {
                    SessionErrors.add(req, e.getClass().getName());
                }

                return mapping.findForward("portal.login");
            } else if (e instanceof CookieNotSupportedException || e instanceof NoSuchUserException
                    || e instanceof PasswordExpiredException || e instanceof UserEmailAddressException
                    || e instanceof UserIdException || e instanceof UserLockoutException
                    || e instanceof UserPasswordException || e instanceof UserScreenNameException) {

                SessionErrors.add(req, e.getClass().getName());

                return mapping.findForward("portal.login");
            } else {
                req.setAttribute(PageContext.EXCEPTION, e);

                return mapping.findForward(ActionConstants.COMMON_ERROR);
            }
        }
    } else if (cmd.equals("forgot-password")) {
        try {
            sendPassword(req);

            return mapping.findForward("portal.login");
        } catch (Exception e) {
            if (e instanceof NoSuchUserException || e instanceof SendPasswordException
                    || e instanceof UserEmailAddressException) {

                SessionErrors.add(req, e.getClass().getName());

                return mapping.findForward("portal.login");
            } else {
                req.setAttribute(PageContext.EXCEPTION, e);

                return mapping.findForward(ActionConstants.COMMON_ERROR);
            }
        }
    } else {
        return mapping.findForward("portal.login");
    }
}