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:com.liferay.portal.struts.StrutsUtil.java

public static void forward(String uri, ServletContext ctx, HttpServletRequest req, HttpServletResponse res)
        throws ServletException {

    if (!res.isCommitted()) {
        String path = Constants.TEXT_HTML_DIR + uri;
        if (BrowserSniffer.is_wml(req)) {
            path = Constants.TEXT_WML_DIR + uri;
        }//  w w  w.ja  v  a2  s. c om

        ServletContext portalCtx = ctx.getContext(PropsUtil.get(PropsUtil.PORTAL_CTX));

        if (portalCtx == null) {
            portalCtx = ctx;
        }

        RequestDispatcher rd = portalCtx.getRequestDispatcher(path);

        try {
            rd.forward(req, res);
        } catch (IOException ioe1) {
            Logger.error(StrutsUtil.class, ioe1.getMessage(), ioe1);
        } catch (ServletException se1) {
            req.setAttribute(PageContext.EXCEPTION, se1.getRootCause());

            String errorPath = Constants.TEXT_HTML_DIR + Constants.COMMON_ERROR;
            if (BrowserSniffer.is_wml(req)) {
                path = Constants.TEXT_WML_DIR + Constants.COMMON_ERROR;
            }

            rd = portalCtx.getRequestDispatcher(errorPath);

            try {
                rd.forward(req, res);
            } catch (IOException ioe2) {
                Logger.error(StrutsUtil.class, ioe2.getMessage(), ioe2);
            } catch (ServletException se2) {
                throw se2;
            }
        }
    } else {
        _log.warn(uri + " is already committed");
    }
}

From source file:com.liferay.portlet.admin.action.KillSessionAction.java

public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req,
        ActionResponse res) throws Exception {

    if (!OmniadminUtil.isOmniadmin(PortalUtil.getUser(req).getUserId())) {
        SessionErrors.add(req, PrincipalException.class.getName());

        setForward(req, "portlet.admin.error");
    } else {/*from   w ww .j a  v  a2 s.  c o m*/
        try {
            _killSession(req, res);
        } catch (Exception e) {
            if (e != null && e instanceof PrincipalException) {

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

                setForward(req, "portlet.admin.error");
            } else {
                req.setAttribute(PageContext.EXCEPTION, e);

                setForward(req, Constants.COMMON_ERROR);
            }
        }

        setForward(req, "portlet.admin.list_sessions");
    }
}

From source file:com.liferay.samplestrutsliferay.struts.action.ViewChartAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {/*from w w w  .j a  va2  s.c om*/
        if (_log.isInfoEnabled()) {
            _log.info("execute");
        }

        String attrName = "chart_name";

        // Application scoped session attributes can be fetched from the
        // servlet directly. Portlet scoped session attributes can be
        // fetched from Sun's PortletSessionUtil.

        HttpSession session = request.getSession();

        String chartName = (String) session.getAttribute(attrName);
        //(String)_getAttribute(request, attrName);

        // Chart

        String chartType = request.getParameter("chart_type");

        CategoryDataset dataset = _getDataset();

        String xName = "Soda";
        String yName = "Votes";

        JFreeChart chart = null;

        if (chartType.equals("area")) {
            chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("horizontal_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL,
                    true, false, false);
        } else if (chartType.equals("line")) {
            chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("vertical_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else {
            PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0);

            chart = ChartFactory.createPieChart(chartName, pieData, true, false, false);
        }

        response.setContentType("image/jpeg");

        OutputStream out = response.getOutputStream();

        ChartUtilities.writeChartAsJPEG(out, chart, 400, 400);

        return mapping.findForward("/common/null.jsp");
    } catch (Exception e) {
        request.setAttribute(PageContext.EXCEPTION, e);

        return mapping.findForward("/common/error.jsp");
    }
}

From source file:com.liferay.samplestruts.struts.action.ViewChartAction.java

@Override
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {//from   w  w  w  .ja  va  2s.  c  o  m
        if (_log.isInfoEnabled()) {
            _log.info("execute");
        }

        String attrName = "chart_name";

        // Application scoped session attributes can be fetched from the
        // servlet directly. Portlet scoped session attributes can be
        // fetched from Sun's PortletSessionUtil.

        HttpSession session = request.getSession();

        String chartName = (String) session.getAttribute(attrName);
        //(String)_getAttribute(request, attrName);

        // Chart

        String chartType = request.getParameter("chart_type");

        CategoryDataset dataset = _getDataset();

        String xName = "Soda";
        String yName = "Votes";

        JFreeChart chart = null;

        if (chartType.equals("area")) {
            chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("horizontal_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL,
                    true, false, false);
        } else if (chartType.equals("line")) {
            chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("vertical_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else {
            PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0);

            chart = ChartFactory.createPieChart(chartName, pieData, true, false, false);
        }

        response.setContentType("image/jpeg");

        OutputStream out = response.getOutputStream();

        ChartUtilities.writeChartAsJPEG(out, chart, 400, 400);

        return actionMapping.findForward("/common/null.jsp");
    } catch (Exception e) {
        request.setAttribute(PageContext.EXCEPTION, e);

        return actionMapping.findForward("/common/error.jsp");
    }
}

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

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

    try {//  ww  w .j  a va 2s . c o  m
        HttpSession ses = req.getSession();
        try {
            // Logger.info(this, "User " +
            // PortalUtil.getUser(req).getFullName() + " (" +
            // PortalUtil.getUser(req).getUserId() +
            // ") has logged out from IP: " + req.getRemoteAddr());
            SecurityLogger.logInfo(this.getClass(), "User " + PortalUtil.getUser(req).getFullName() + " ("
                    + PortalUtil.getUser(req).getUserId() + ") has logged out from IP: " + req.getRemoteAddr());
        } catch (Exception e) {
            //Logger.info(this, "User has logged out from IP: " + req.getRemoteAddr());
            SecurityLogger.logInfo(this.getClass(), "User has logged out from IP: " + req.getRemoteAddr());
        }

        EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGOUT_EVENTS_PRE), req, res);

        ArrayList<Cookie> al = new ArrayList<Cookie>();
        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];
                al.add(cookie);
                cookie.setMaxAge(0);
                cookie.setPath("/");
                res.addCookie(cookie);
            }
        }

        Map sessions = PortletSessionPool.remove(ses.getId());

        if (sessions != null) {
            Iterator itr = sessions.entrySet().iterator();

            while (itr.hasNext()) {
                Map.Entry entry = (Map.Entry) itr.next();

                HttpSession portletSession = (HttpSession) entry.getValue();

                portletSession.invalidate();
            }
        }

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

        EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGOUT_EVENTS_POST), req, res);

        // ActionForward af = mapping.findForward("referer");
        // return af;
        return mapping.findForward(Constants.COMMON_REFERER);
    } catch (Exception e) {
        req.setAttribute(PageContext.EXCEPTION, e);
        return mapping.findForward(Constants.COMMON_REFERER);
    }
}

From source file:com.liusoft.dlog4j.velocity.VelocityTool.java

/**
 * ??/*from  ww w  .  ja v  a 2 s  .  co m*/
 * @return
 * @throws IOException
 */
public String exception() throws IOException {
    Throwable t = (Throwable) request.getAttribute(PageContext.EXCEPTION);
    if (t == null) {
        //Tomcat??
        t = (Throwable) request.getAttribute("javax.servlet.error.exception");
    }
    return exception(t);
}

From source file:cn.edu.zjnu.acm.judge.config.SecurityConfiguration.java

@Bean
public AuthenticationEntryPoint authenticationEntryPoint() {
    return (request, response, authException) -> {
        request.setAttribute(PageContext.EXCEPTION, authException);
        request.getRequestDispatcher("/unauthorized").forward(request, response);
    };//  w w w . j a va  2s  . com
}

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

/**
 * testExecute01()//from   w w w.  java2 s . c  o  m
 * <br><br>
 * 
 * ??n
 * <br>
 * _?FA
 * <br><br>
 * l?F(?) ex:Exception<br>
 *         (?) eConfig:ExceptionConfig<br>
 *               ?ypathtB?[h"/errorPath.do"??z<br>
 *         (?) mapping:not null<br>
 *         (?) formInstance:not null<br>
 *         (?) request:not null<br>
 *         (?) response:not null<br>
 *         (?) bundle:null<br>
 *         
 * <br>
 * l?F(l) ActionForward:tH??[h??F"/errorPath.do"<br>
 *         (?) request:NGXg??F<br>
 *                    PageContext.EXCEPTION?Fnull<br>
 *         
 * <br>
 * ?OSystemException?Apath?w?Apath?wpXANVtH??[h??AReLXg?[gtrue??B
 * <br>
 * 
 * @throws Exception ?\bh?O
 */
public void testExecute01() throws Exception {
    // O??

    // VXeOnh
    SystemExceptionHandler handler = new SystemExceptionHandler();

    // VXeOO
    Exception e = new Exception();

    // 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();

    // 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
    assertNull(req.getAttribute(PageContext.EXCEPTION));

}

From source file:com.dotmarketing.portlets.mailinglists.action.ViewMailingListsAction.java

public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req,
        RenderResponse res) throws Exception {

    Logger.debug(this, "Running ViewMailingListsAction");

    try {//  w  ww .j  ava  2 s  . c o m
        //get the user, order, direction
        User user = com.liferay.portal.util.PortalUtil.getUser(req);
        String orderBy = req.getParameter("orderby");
        String direction = req.getParameter("direction");
        String condition = req.getParameter("query");

        //get their lists
        List list = null;
        List roles = com.dotmarketing.business.APILocator.getRoleAPI().loadRolesForUser(user.getUserId());
        boolean isMarketingAdmin = false;

        Iterator rolesIt = roles.iterator();
        while (rolesIt.hasNext()) {
            Role role = (Role) rolesIt.next();
            if (UtilMethods.isSet(role.getRoleKey())
                    && role.getRoleKey().equals(Config.getStringProperty("MAILINGLISTS_ADMIN_ROLE"))) {
                isMarketingAdmin = true;
                break;
            }
        }

        if (isMarketingAdmin) {
            if (UtilMethods.isSet(orderBy) && UtilMethods.isSet(direction)) {
                //list = MailingListFactory.getAllMailingLists(orderBy, direction);
                list = MailingListFactory.getAllMailingLists();
                list.addAll(UserFilterFactory.getAllUserFilter());

                if (orderBy.equals("title")) {
                    if (direction.equals(" asc"))
                        Collections.sort(list, new ComparatorTitleAsc());
                    else
                        Collections.sort(list, new ComparatorTitleDesc());
                }
            } else if (UtilMethods.isSet(condition)) {
                list = MailingListFactory.getAllMailingListsCondition(condition);
                list.addAll(UserFilterFactory.getUserFilterByTitle(condition));
                Collections.sort(list, new ComparatorTitleAsc());
            } else {
                list = MailingListFactory.getAllMailingLists();
                list.addAll(UserFilterFactory.getAllUserFilter());
                Collections.sort(list, new ComparatorTitleAsc());
            }
        } else {
            if (UtilMethods.isSet(orderBy) && UtilMethods.isSet(direction)) {
                //list = MailingListFactory.getMailingListsByUser(user, orderBy, direction);
                list = MailingListFactory.getMailingListsByUser(user);
                list.add(MailingListFactory.getUnsubscribersMailingList());
                list.addAll(UserFilterFactory.getAllUserFilterByUser(user));

                if (orderBy.equals("title")) {
                    if (direction.equals(" asc"))
                        Collections.sort(list, new ComparatorTitleAsc());
                    else
                        Collections.sort(list, new ComparatorTitleDesc());
                }
            } else if (UtilMethods.isSet(condition)) {
                list = MailingListFactory.getMailingListsByUserCondition(user, condition);
                list.add(MailingListFactory.getUnsubscribersMailingList());
                list.addAll(UserFilterFactory.getUserFilterByTitleAndUser(condition, user));
                Collections.sort(list, new ComparatorTitleAsc());
            } else {
                list = MailingListFactory.getMailingListsByUser(user);
                list.add(MailingListFactory.getUnsubscribersMailingList());
                list.addAll(UserFilterFactory.getAllUserFilterByUser(user));
                Collections.sort(list, new ComparatorTitleAsc());
            }
        }

        if (req.getWindowState().equals(WindowState.NORMAL)) {
            //            if (list != null)
            //               list = orderMailingListByDescDate(list);
            req.setAttribute(WebKeys.MAILING_LIST_VIEW_PORTLET, list);
            return mapping.findForward("portlet.ext.mailinglists.view");
        } else {
            req.setAttribute(WebKeys.MAILING_LIST_VIEW, list);
            return mapping.findForward("portlet.ext.mailinglists.view_mailinglists");
        }
    } catch (Exception e) {
        req.setAttribute(PageContext.EXCEPTION, e);
        return mapping.findForward(Constants.COMMON_ERROR);
    }
}

From source file:com.dotmarketing.portlets.cmsmaintenance.action.ViewCMSMaintenanceAction.java

public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req,
        RenderResponse res) throws Exception {
    Logger.debug(this, "Running ViewCMSMaintenanceAction!!!! = " + req.getWindowState());

    // Set the asset paths
    try {//from  www  .ja  va2 s  . c om
        assetRealPath = Config.getStringProperty("ASSET_REAL_PATH");
    } catch (Exception e) {
    }
    try {
        assetPath = Config.getStringProperty("ASSET_PATH");
    } catch (Exception e) {
    }

    try {
        //gets the user
        _initCacheValues(req);

        if (req.getWindowState().equals(WindowState.MAXIMIZED)) {
            Logger.debug(this, "Showing view action cms maintenance maximized");
            _initStructures(form, req, res);
            return mapping.findForward("portlet.ext.cmsmaintenance.view_cms_maintenance");
        } else {
            Logger.debug(this, "Showing view action cms maintenance minimized");
            return mapping.findForward("portlet.ext.cmsmaintenance.view");
        }
    } catch (Exception e) {
        req.setAttribute(PageContext.EXCEPTION, e);
        return mapping.findForward(com.liferay.portal.util.Constants.COMMON_ERROR);
    }
}