Package com.alibaba.citrus.webx.util

Examples of com.alibaba.citrus.webx.util.ErrorHandlerHelper$ExceptionCodeMapping


    /** 简化的error page handler。 */
    public static class TestErrorHandler implements RequestHandler {
        public void handleRequest(RequestHandlerContext ctx) throws Exception {
            HttpServletResponse response = ctx.getResponse();
            ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(ctx.getRequest());
            Throwable exception = helper.getException();

            response.setContentType("text/html; charset=UTF-8");

            PrintWriter out = response.getWriter();

View Full Code Here


        Exception e = new Exception();

        ErrorHandlerHelper.getInstance(newRequest).init("app1", e, null);
        pipeline.newInvocation().invoke();

        ErrorHandlerHelper helper = (ErrorHandlerHelper) rundata.getContext().get("error");

        assertEquals(e, helper.getException());
    }
View Full Code Here

        Exception e = new Exception();

        ErrorHandlerHelper.getInstance(newRequest).init("app1", e, null);
        pipeline.newInvocation().invoke();

        ErrorHandlerHelper helper = (ErrorHandlerHelper) rundata.getContext().get("error1");

        assertEquals(e, helper.getException());
    }
View Full Code Here

        ErrorHandlerHelper.getInstance(newRequest).init("app1", new Exception(), null);
        pipeline.newInvocation().invoke();

        assertEquals(501, RequestContextUtil.findRequestContext(newRequest, LazyCommitRequestContext.class).getStatus());

        ErrorHandlerHelper helper = (ErrorHandlerHelper) rundata.getContext().get("error");

        assertEquals(501, helper.getStatusCode());
        assertEquals("NOT_IMPLEMENTED", helper.getMessage());
    }
View Full Code Here

    @Test
    public void statusCode_default() {
        ErrorHandlerHelper.getInstance(newRequest).init("app1", new IllegalArgumentException(), null);
        pipeline.newInvocation().invoke();

        ErrorHandlerHelper helper = (ErrorHandlerHelper) rundata.getContext().get("error");

        assertEquals(500, helper.getStatusCode());
        assertEquals("INTERNAL_SERVER_ERROR", helper.getMessage());
    }
View Full Code Here

    /** 简化的error page handler。 */
    public static class TestErrorHandler implements RequestHandler {
        public void handleRequest(RequestHandlerContext ctx) throws Exception {
            HttpServletResponse response = ctx.getResponse();
            ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(ctx.getRequest());
            Throwable exception = helper.getException();

            response.setContentType("text/html; charset=UTF-8");

            PrintWriter out = response.getWriter();

View Full Code Here

        }

        public RequestHandlerContext getRequestHandlerContextForError(HttpServletRequest request, HttpServletResponse response,
                                                                      Throwable exception) {
            // servletName == ""
            ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(request);

            helper.init(EMPTY_STRING, exception, exceptionCodeMapping);
            response.setStatus(helper.getStatusCode());

            String internalBaseURL = getBaseURL(request) + internalPathPrefix;

            return new InternalRequestHandlerContext(request, response, internalBaseURL, internalBaseURL + "/"
                                                                                         + ERROR_PREFIX, "", errorHandler);
View Full Code Here

        sorted.add(handler);
    }

    public void invoke(PipelineContext pipelineContext) throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(request);
        Throwable exception = helper.getException();

        // 模板中可用的helper
        rundata.getContext().put(helperName, helper);

        if (exception != null) {
            int statusCode = -1;
            String target = null;
            LoggingDetail loggingDetail = defaultLoggingDetail;
            Logger logger = defaultLogger;

            // 从最根本的exception cause开始反向追溯,例如:t1 caused by t2 caused by t3,
            // 那么,检查顺序为t3, t2, t1。
            CAUSES:
            for (Throwable cause : getCauses(exception, true)) {
                // 对于每个异常,查找匹配的exception handlers。
                // 所有handlers已经排序,较特殊的异常在前,假设T1 extends T2,那么T1在T2之前。
                for (ExceptionHandler exceptionHandler : exceptionHandlers) {
                    if (exceptionHandler.getExceptionType().isInstance(cause)) {
                        statusCode = exceptionHandler.getStatusCode();
                        target = exceptionHandler.getPage();
                        loggingDetail = exceptionHandler.getLoggingDetail();
                        logger = exceptionHandler.getLogger();
                        break CAUSES;
                    }
                }
            }

            if (statusCode > 0) {
                rundata.getResponse().setStatus(statusCode);
                helper.setStatusCode(statusCode); // 更新request attributes
            }

            // 打印日志
            helper.logError(logger, loggingDetail);

            // 设定错误页面target
            if (target == null) {
                target = defaultPage;
            }
View Full Code Here

*/
public class SendErrorHandler implements RequestHandler {
    private final static Logger log = LoggerFactory.getLogger(SendErrorHandler.class);

    public void handleRequest(RequestHandlerContext context) throws Exception {
        ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(context.getRequest());

        helper.setServletErrorAttributes();
        helper.logError(log);

        context.getResponse().sendError(helper.getStatusCode());
    }
View Full Code Here

    private final        EnvironmentVariablesComponent environmentVariablesComponent = new EnvironmentVariablesComponent(this, "env", keyValuesComponent);
    private final        SystemInfoComponent           systemInfoComponent           = new SystemInfoComponent(this, "sysinfo", keyValuesComponent);

    @Override
    protected Object getBodyVisitor(RequestHandlerContext context) {
        ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(context.getRequest());

        helper.logError(log);

        return new DetailedErrorPageVisitor(context, helper);
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.webx.util.ErrorHandlerHelper$ExceptionCodeMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.