Package com.alibaba.citrus.service.requestcontext

Examples of com.alibaba.citrus.service.requestcontext.RequestContext


        initServlet("webapp/WEB-INF/web.xml");
        initFactory();

        RequestContextChainingService requestContexts = (RequestContextChainingService) factory
                .getBean("requestContexts");
        RequestContext rc = null;

        try {
            // 预备request, response
            rc = requestContexts.getRequestContext(servletContext, request, response);

            // 设置contentType和charset,和jsp中的设置不同,以此为准
            rc.getResponse().setContentType("text/plain; charset=GBK"); // JSP: text/html; charset=UTF-8

            // 预备template context
            TemplateContext context = new MappedTemplateContext();
            context.put("hello", "中国");
View Full Code Here


*
* @author Michael Zhou
*/
public class DummyRequestContextFactoryImpl extends AbstractRequestContextFactory<RequestContext> {
    public RequestContext getRequestContextWrapper(final RequestContext wrappedContext) {
        return new RequestContext() {
            public RequestContext getWrappedRequestContext() {
                return wrappedContext;
            }

            public HttpServletRequest getRequest() {
View Full Code Here

            public void commit() {
                commits.add(index);
            }
        }

        RequestContext wrappedRequestContext = createMock(RequestContext.class);
        HttpServletRequest wrappedRequest = createMock(HttpServletRequest.class);
        HttpServletResponse wrappedResponse = createMock(HttpServletResponse.class);
        ServletContext servletContext = createMock(ServletContext.class);

        expect(wrappedRequestContext.getRequest()).andReturn(wrappedRequest).anyTimes();
        expect(wrappedRequestContext.getResponse()).andReturn(wrappedResponse).anyTimes();
        expect(wrappedRequestContext.getServletContext()).andReturn(servletContext).anyTimes();

        replay(wrappedRequestContext);

        BasicRequestContextImpl requestContext = new BasicRequestContextImpl(wrappedRequestContext, new Object[] {
                new MyInterceptor(1), new MyInterceptor(2), new MyInterceptor(3) });
View Full Code Here

    }

    protected final void initRequestContext(ApplicationContext factory) {
        requestContexts = (RequestContextChainingService) factory.getBean("requestContexts");

        RequestContext topRC = requestContexts.getRequestContext(config.getServletContext(), request, response);

        assertNotNull(topRC);

        rundata = findRequestContext(topRC, RunData.class);

        newRequest = topRC.getRequest();
        newResponse = topRC.getResponse();
    }
View Full Code Here

            public void commit() {
                commits.add(index);
            }
        }

        RequestContext wrappedRequestContext = createMock(RequestContext.class);
        HttpServletRequest wrappedRequest = createMock(HttpServletRequest.class);
        HttpServletResponse wrappedResponse = createMock(HttpServletResponse.class);
        ServletContext servletContext = createMock(ServletContext.class);

        expect(wrappedRequestContext.getRequest()).andReturn(wrappedRequest).anyTimes();
        expect(wrappedRequestContext.getResponse()).andReturn(wrappedResponse).anyTimes();
        expect(wrappedRequestContext.getServletContext()).andReturn(servletContext).anyTimes();

        replay(wrappedRequestContext);

        BasicRequestContextImpl requestContext = new BasicRequestContextImpl(wrappedRequestContext, new Object[] {
                new MyInterceptor(1), new MyInterceptor(2), new MyInterceptor(3) });
View Full Code Here

    }

    protected final void initRequestContext(ApplicationContext factory) {
        requestContexts = (RequestContextChainingService) factory.getBean("requestContexts");

        RequestContext topRC = requestContexts.getRequestContext(config.getServletContext(), request, response);

        assertNotNull(topRC);

        rundata = findRequestContext(topRC, RunData.class);

        newRequest = topRC.getRequest();
        newResponse = topRC.getResponse();

        // 创建turbine rundata
        TurbineUtil.getTurbineRunData(newRequest, true);

        // 设置当前component
View Full Code Here

    /** 取得request context。 */
    protected final void initRequestContext() {
        requestContexts = (RequestContextChainingService) factory.getBean("requestContexts");

        RequestContext topRC = requestContexts.getRequestContext(context, request, response);

        assertNotNull(topRC);

        newRequest = topRC.getRequest();
        newResponse = topRC.getResponse();

        rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(newRequest, true);

        WebxUtil.setCurrentComponent(newRequest, component);

View Full Code Here

        initServlet("webapp/WEB-INF/web.xml");
        initFactory();

        RequestContextChainingService requestContexts = (RequestContextChainingService) factory
                .getBean("requestContexts");
        RequestContext rc = null;

        try {
            // 预备request, response
            rc = requestContexts.getRequestContext(servletContext, request, response);

            // 设置contentType和charset,和jsp中的设置不同,以此为准
            rc.getResponse().setContentType("text/plain; charset=GBK"); // JSP: text/html; charset=UTF-8

            // 预备template context
            TemplateContext context = new MappedTemplateContext();
            context.put("hello", "中国");
View Full Code Here

                                            HttpServletResponse response) {
        assertInitialized();

        // 异步请求(dispatcherType == ASYNC)开始时,如果已经存在request context,则直接取得并返回之。
        boolean asyncDispatcher = request_isDispatcherType(request, DISPATCHER_TYPE_ASYNC);
        RequestContext requestContext = null;

        if (asyncDispatcher) {
            requestContext = RequestContextUtil.getRequestContext(request);
        }

        if (requestContext == null) {
            SimpleRequestContext innerReuestContext = new SimpleRequestContext(servletContext, request, response, this);

            requestContext = innerReuestContext;

            // 将requestContext放入request中,以便今后只需要用request就可以取得requestContext。
            // 及早设置setRequestContext,以便随后的prepareRequestContext就能使用。
            RequestContextUtil.setRequestContext(requestContext);

            for (RequestContextFactory<?> factory : factories) {
                requestContext = factory.getRequestContextWrapper(requestContext);

                // 调用<code>requestContext.prepare()</code>方法
                prepareRequestContext(requestContext);

                // 将requestContext放入request中,以便今后只需要用request就可以取得requestContext。
                RequestContextUtil.setRequestContext(requestContext);
            }

            innerReuestContext.setTopRequestContext(requestContext);

            getLogger().debug("Created a new request context: {}", requestContext);
        }

        // 无论是否是从async恢复,都需要重新设置thread的上下文环境。
        bind(requestContext.getRequest());

        return requestContext;
    }
View Full Code Here

    public void onFinishedProcessContext() {
    }

    public final void service(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws Exception {
        RequestContext requestContext = null;

        try {
            requestContext = assertNotNull(getRequestContext(request, response), "could not get requestContext");

            // 如果请求已经结束,则不执行进一步的处理。例如,当requestContext已经被重定向了,则立即结束请求的处理。
            if (isRequestFinished(requestContext)) {
                return;
            }

            // 请求未结束,则继续处理...
            request = requestContext.getRequest();
            response = requestContext.getResponse();

            // 如果是一个内部请求,则执行内部请求
            if (handleInternalRequest(request, response)) {
                return;
            }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.service.requestcontext.RequestContext

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.