Package com.alibaba.citrus.turbine

Examples of com.alibaba.citrus.turbine.TurbineRunDataInternal


public class MyControlWithError {
    @Autowired
    private HttpServletRequest request;

    public void execute() throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);

        if (rundata.getCurrentContext().containsKey("with_XSS")) {
            throw new IllegalArgumentException("<script>alert(1)</script>");
        } else {
            throw new IllegalArgumentException();
        }
    }
View Full Code Here


    public static class MyErrorValve implements Valve {
        @Autowired
        private HttpServletRequest request;

        public void invoke(PipelineContext pipelineContext) throws Exception {
            TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);
            saved = rundata;

            rundata.getContext().put("hello", "world");

            throw new IllegalArgumentException();
        }
View Full Code Here

    public static class MyValve implements Valve {
        @Autowired
        private HttpServletRequest request;

        public void invoke(PipelineContext pipelineContext) throws Exception {
            TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);

            assertNotNull(saved);
            assertNotSame(saved, rundata);
            saved = null;

            // 第一个pipeline出错以后,第二个pipeline可以取得上个pipeline的context。
            // 这样,用于错误处理的exception pipleine就可以获得应用的context状态。
            assertEquals("world", rundata.getContext().get("hello"));

            // root context中不包含pull service,因此不存在control tool。
            assertNull(rundata.getContext().get("control"));
        }
View Full Code Here

        public MapDataResolver(DataResolverContext context){
            this.context = context;
        }

        public Object resolve() {
            TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);
            return new ParameterMap(request, rundata.getContext(), rundata);
        }
View Full Code Here

    @Autowired
    private MappingRuleService mappingRuleService;

    public void invoke(PipelineContext pipelineContext) throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        String target = assertNotNull(rundata.getTarget(), "Target was not specified");

        // 检查重定向标志,如果是重定向,则不需要将页面输出。
        if (!rundata.isRedirected()) {
            Context context = rundata.getContext();

            renderTemplate(getScreenTemplate(target), context, rundata);

            // layout可被禁用。
            if (rundata.isLayoutEnabled()) {
                String layoutTemplateOverride = rundata.getLayoutTemplateOverride();

                if (layoutTemplateOverride != null) {
                    target = layoutTemplateOverride;
                }
View Full Code Here

        controlToolName = defaultIfNull(controlToolName, DEFAULT_CONTROL_TOOL_NAME);
        substName = defaultIfNull(substName, DEFAULT_SUBSTITUTION_NAME);
    }

    public void invoke(PipelineContext pipelineContext) throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        Substitution subst = getSubstitution(pipelineContext);

        String template = trimToNull(subst.substitute(templateName));
        String module = trimToNull(subst.substitute(moduleName));

        Context context = rundata.getContext();
        ControlTool controlTool = getControlTool(context, template, module, rundata);

        // render control
        rundata.getResponse().getWriter(); // 必须先预备好buffer
        String content = controlTool.render();

        // 设置context,以便后续模块能够读取
        context.put("controlContent", content); // controlContent为control渲染的结果
        context.put("controlTarget", template != null ? template : module);

        // 重定向至controlExporter target
        rundata.setRedirectTarget(controlExporterTarget);

        pipelineContext.invokeNext();
    }
View Full Code Here

    @Autowired
    private MappingRuleService mappingRuleService;

    public void invoke(PipelineContext pipelineContext) throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        String target = assertNotNull(rundata.getTarget(), "Target was not specified");

        // 检查重定向标志,如果是重定向,则不需要将页面输出。
        if (!rundata.isRedirected()) {
            Context context = rundata.getContext();

            renderTemplate(getScreenTemplate(target), context, rundata);

            // layout可被禁用。
            if (rundata.isLayoutEnabled() && bufferedRequestContext.isBuffering()) {
                String layoutTemplateOverride = rundata.getLayoutTemplateOverride();

                if (layoutTemplateOverride != null) {
                    target = layoutTemplateOverride;
                }
View Full Code Here

            setHomepage("/index");
        }
    }

    public void invoke(PipelineContext pipelineContext) throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
        String target = null;

        // 取得target,并转换成统一的内部后缀名。
        String pathInfo = ServletUtil.getResourcePath(rundata.getRequest()).substring(
                component.getComponentPath().length());

        if ("/".equals(pathInfo)) {
            pathInfo = getHomepage();
        }

        // 注意,必须将pathInfo转换成camelCase。
        int lastSlashIndex = pathInfo.lastIndexOf("/");

        if (lastSlashIndex >= 0) {
            pathInfo = pathInfo.substring(0, lastSlashIndex) + "/"
                       + StringUtil.toCamelCase(pathInfo.substring(lastSlashIndex + 1));
        } else {
            pathInfo = StringUtil.toCamelCase(pathInfo);
        }

        target = mappingRuleService.getMappedName(EXTENSION_INPUT, pathInfo);

        rundata.setTarget(target);

        // 取得action
        String action = StringUtil.toCamelCase(trimToNull(rundata.getParameters().getString(actionParam)));

        action = mappingRuleService.getMappedName(ACTION_MODULE, action);
        rundata.setAction(action);

        // 取得actionEvent
        String actionEvent = ActionEventUtil.getEventName(rundata.getRequest());
        rundata.setActionEvent(actionEvent);

        pipelineContext.invokeNext();
    }
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;
            }

            rundata.setTarget(target);
        }

        // 执行下一个Valve
        pipelineContext.invokeNext();
    }
View Full Code Here

    @Autowired
    private HttpServletRequest request;

    @Override
    public void invoke(PipelineContext pipelineContext) throws Exception {
        TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);

        if (rundata.doRedirectTarget()) {
            pipelineContext.invokeNext(); // continue
        } else {
            super.invoke(pipelineContext); // break
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.turbine.TurbineRunDataInternal

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.