当前位置: 首页>>代码示例>>Java>>正文


Java DispatcherType.ASYNC属性代码示例

本文整理汇总了Java中javax.servlet.DispatcherType.ASYNC属性的典型用法代码示例。如果您正苦于以下问题:Java DispatcherType.ASYNC属性的具体用法?Java DispatcherType.ASYNC怎么用?Java DispatcherType.ASYNC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.servlet.DispatcherType的用法示例。


在下文中一共展示了DispatcherType.ASYNC属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    if ("y".equals(req.getParameter(DISPATCH_CHECK))) {
        if (req.getDispatcherType() != DispatcherType.ASYNC) {
            track("WrongDispatcherType-");
        }
    }
    track("DispatchingServletGet-");
    final int iter = Integer.parseInt(req.getParameter(ITER_PARAM)) - 1;
    final AsyncContext ctxt = req.startAsync();
    if (addTrackingListener) {
        TrackingListener listener =
            new TrackingListener(completeOnError, true, null);
        ctxt.addListener(listener);
    }
    Runnable run = new Runnable() {
        @Override
        public void run() {
            if (iter > 0) {
                ctxt.dispatch("/stage1?" + ITER_PARAM + "=" + iter +
                        "&" + DISPATCH_CHECK + "=y");
            } else {
                ctxt.dispatch("/stage2");
            }
        }
    };
    if ("y".equals(req.getParameter("useThread"))) {
        new Thread(run).start();
    } else {
        run.run();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:34,代码来源:TestAsyncContextImpl.java

示例2: service

@Override
public void service(ServletRequest req, ServletResponse resp)
        throws ServletException, IOException {
    if (DispatcherType.ASYNC != req.getDispatcherType()) {
        AsyncContext asyncContext;
        if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
            asyncContext = req.startAsync(
                    new ServletRequestWrapper(req),
                    new ServletResponseWrapper(resp));
        } else {
            asyncContext = req.startAsync();
        }
        if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
            asyncContext.dispatch();
        } else {
            asyncContext.dispatch("/target");
        }
        try {
            asyncContext.dispatch("/nonExistingServlet");
            TestAsyncContextImpl.track("FAIL");
        } catch (IllegalStateException e) {
            TestAsyncContextImpl.track("OK");
        }
    } else {
        TestAsyncContextImpl.track("DispatchingGenericServletGet-");
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:TestAsyncContextImpl.java

示例3: dispatchRequest

private void dispatchRequest(final HttpServerExchange exchange, final ServletRequestContext servletRequestContext, final ServletChain servletChain, final DispatcherType dispatcherType) throws Exception {
    servletRequestContext.setDispatcherType(dispatcherType);
    servletRequestContext.setCurrentServlet(servletChain);
    if (dispatcherType == DispatcherType.REQUEST || dispatcherType == DispatcherType.ASYNC) {
        handleFirstRequest(exchange, servletChain, servletRequestContext, servletRequestContext.getServletRequest(), servletRequestContext.getServletResponse());
    } else {
        next.handleRequest(exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ServletInitialHandler.java

示例4: handleFirstRequest

public void handleFirstRequest(final HttpServerExchange exchange, final ServletChain servletChain, final ServletRequestContext servletRequestContext, final ServletRequest request, final ServletResponse response) throws Exception {

        ThreadSetupAction.Handle handle = setupAction.setup(exchange);
        try {
            servletRequestContext.setRunningInsideHandler(true);
            try {
                listeners.requestInitialized(request);
                next.handleRequest(exchange);
                //
                if(servletRequestContext.getErrorCode() > 0) {
                    servletRequestContext.getOriginalResponse().doErrorDispatch(servletRequestContext.getErrorCode(), servletRequestContext.getErrorMessage());
                }
            } catch (Throwable t) {

                //by default this will just log the exception
                boolean handled = exceptionHandler.handleThrowable(exchange, request, response, t);

                if(handled) {
                    exchange.endExchange();
                } else if (request.isAsyncStarted() || request.getDispatcherType() == DispatcherType.ASYNC) {
                    exchange.unDispatch();
                    servletRequestContext.getOriginalRequest().getAsyncContextInternal().handleError(t);
                } else {
                    if (!exchange.isResponseStarted()) {
                        response.reset();                       //reset the response
                        exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
                        exchange.getResponseHeaders().clear();
                        String location = servletContext.getDeployment().getErrorPages().getErrorLocation(t);
                        if (location == null) {
                            location = servletContext.getDeployment().getErrorPages().getErrorLocation(StatusCodes.INTERNAL_SERVER_ERROR);
                        }
                        if (location != null) {
                            RequestDispatcherImpl dispatcher = new RequestDispatcherImpl(location, servletContext);
                            try {
                                dispatcher.error(servletRequestContext, request, response, servletChain.getManagedServlet().getServletInfo().getName(), t);
                            } catch (Exception e) {
                                UndertowLogger.REQUEST_LOGGER.exceptionGeneratingErrorPage(e, location);
                            }
                        } else {
                            if (servletRequestContext.displayStackTraces()) {
                                ServletDebugPageHandler.handleRequest(exchange, servletRequestContext, t);
                            } else {
                                servletRequestContext.getOriginalResponse().doErrorDispatch(StatusCodes.INTERNAL_SERVER_ERROR, StatusCodes.INTERNAL_SERVER_ERROR_STRING);
                            }
                        }
                    }
                }

            } finally {
                servletRequestContext.setRunningInsideHandler(false);
                listeners.requestDestroyed(request);
            }
            //if it is not dispatched and is not a mock request
            if (!exchange.isDispatched() && !(exchange.getConnection() instanceof MockServerConnection)) {
                servletRequestContext.getOriginalResponse().responseDone();
                servletRequestContext.getOriginalRequest().clearAttributes();
            }
            if(!exchange.isDispatched()) {
                AsyncContextImpl ctx = servletRequestContext.getOriginalRequest().getAsyncContextInternal();
                if(ctx != null) {
                    ctx.complete();
                }
            }
        } finally {
            handle.tearDown();
        }
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:67,代码来源:ServletInitialHandler.java


注:本文中的javax.servlet.DispatcherType.ASYNC属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。