Java Code Examples for javax.servlet.DispatcherType#ASYNC

The following examples show how to use javax.servlet.DispatcherType#ASYNC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletInvocationServiceInterceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }

    if (!argumentValidator.validate(args)) {
        return;
    }

    try {
        final HttpServletRequest request = (HttpServletRequest) args[0];
        if (request.getDispatcherType() == DispatcherType.ASYNC) {
            if (isDebug) {
                logger.debug("Skip async servlet Request. isAsyncStarted={}, dispatcherType={}", request.isAsyncStarted(), request.getDispatcherType());
            }
            return;
        }

        this.servletRequestListenerInterceptorHelper.initialized(request, ResinConstants.RESIN_METHOD, this.methodDescriptor);
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
 
Example 2
Source File: AbstractServerHandleInterceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }

    try {
        final HttpServletRequest request = toHttpServletRequest(args);
        final HttpServletResponse response = toHttpServletResponse(args);
        if (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.ERROR) {
            if (isDebug) {
                logger.debug("Skip async servlet request event. isAsyncStarted={}, dispatcherType={}", request.isAsyncStarted(), request.getDispatcherType());
            }
            return;
        }
        final int statusCode = getStatusCode(response);
        this.servletRequestListenerInterceptorHelper.destroyed(request, throwable, statusCode);
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
 
Example 3
Source File: AbstractServerHandleInterceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }

    try {
        final HttpServletRequest request = toHttpServletRequest(args);
        if (request.getDispatcherType() == DispatcherType.ASYNC || request.getDispatcherType() == DispatcherType.ERROR) {
            if (isDebug) {
                logger.debug("Skip async servlet request event. isAsyncStarted={}, dispatcherType={}", request.isAsyncStarted(), request.getDispatcherType());
            }
            return;
        }
        this.servletRequestListenerInterceptorHelper.initialized(request, JettyConstants.JETTY_METHOD, this.methodDescriptor);
    } catch (Throwable t) {
        logger.info("Failed to servlet request event handle.", t);
    }
}
 
Example 4
Source File: TestAsyncContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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-");
    }
}
 
Example 5
Source File: PortletRequestContextImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Make it look like request type while the portlet request body is executing.
 */
@Override
public DispatcherType getDispatcherType() {
   DispatcherType type = getServletRequest().getDispatcherType();
   if (isTrace) {
      StringBuilder txt = new StringBuilder();
      txt.append("Dispatcher type: ").append(type);
      txt.append(", executing request body: ").append(executingRequestBody);
      LOG.trace(txt.toString());
   }
   if (executingRequestBody && (type != DispatcherType.ASYNC)) {
      type = DispatcherType.REQUEST;
   }
   return type;
}
 
Example 6
Source File: ServletInvocationServiceInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }

    if (!argumentValidator.validate(args)) {
        return;
    }

    try {
        final HttpServletRequest request = (HttpServletRequest) args[0];
        final HttpServletResponse response = (HttpServletResponse) args[1];
        if (request.getDispatcherType() == DispatcherType.ASYNC) {
            if (isDebug) {
                logger.debug("Skip async servlet Request. isAsyncStarted={}, dispatcherType={}", request.isAsyncStarted(), request.getDispatcherType());
            }
            return;
        }

        int statusCode = getStatusCode(response);
        this.servletRequestListenerInterceptorHelper.destroyed(request, throwable, statusCode);
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
 
Example 7
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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 (trackingListener != null) {
        ctxt.addListener(trackingListener);
    }
    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();
    }
}
 
Example 8
Source File: TestAsyncContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 9
Source File: ServletInitialHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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) {
        firstRequestHandler.call(exchange, servletRequestContext);
    } else {
        next.handleRequest(exchange);
    }
}
 
Example 10
Source File: TestAsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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-");
    }
}
 
Example 11
Source File: TestAsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 12
Source File: ServletInitialHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
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) {
        firstRequestHandler.call(exchange, servletRequestContext);
    } else {
        next.handleRequest(exchange);
    }
}
 
Example 13
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (DispatcherType.ASYNC == req.getDispatcherType()) {
        if (ENCODED_URI.equals(req.getRequestURI())) {
            resp.getWriter().print("OK");
        } else {
            resp.getWriter().print("FAIL");
        }
    } else {
        AsyncContext ac = req.startAsync();
        ac.dispatch();
    }
}
 
Example 14
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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-");
    }
}
 
Example 15
Source File: Servlet3ApiHelper.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAsyncDispatcherBefore(HttpServletRequest request) {
    return request.isAsyncStarted() || request.getDispatcherType() == DispatcherType.ASYNC;
}
 
Example 16
Source File: Servlet3ApiHelper.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAsyncDispatcherAfter(HttpServletRequest request) {
    return request.getDispatcherType() == DispatcherType.ASYNC;
}
 
Example 17
Source File: AsyncServlet.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

   String testcase = req.getParameter("testcase");
   PrintWriter writer = resp.getWriter();
   TestResult result = null;
   ModuleTestCaseDetails tcd = new ModuleTestCaseDetails();

   /* TestCase: V3ResourceAsyncTests_SPEC_21_Async_getDispatcherType5 */
   /* Details: "The ResourceRequest object getDispatcherType() method returns */
   /* the value DispatcherType.ASYNC within the dispatch target method when the */
   /* PortletAsyncContext object dispatch(String) method is used to dispatch to */
   /* the resource method " */
   if (testcase.equals(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_GETDISPATCHERTYPE5)) {
      result = tcd.getTestResultFailed(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_GETDISPATCHERTYPE5);
      DispatcherType dt = req.getDispatcherType();
      if (dt == DispatcherType.ASYNC) {
         result.setTcSuccess(true);
      } else {
         result.appendTcDetail("Unexpected dispatcher type in dispatch target method: " + dt.name());
      }
      writer.write(result.toString());

      /* TestCase: V3ResourceAsyncTests_SPEC_21_Async_complete6                     */
      /* Details: "The PortletAsyncContext object complete() method throws an       */
      /* IllegalStateException if called after the PortletAsyncContext object       */
      /* dispatch(String) method has been called"                                   */
   } else if (testcase.equals(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_COMPLETE6)) {
      HttpSession session = req.getSession();
      result = (TestResult) session.getAttribute(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_COMPLETE6);
      if (result == null) {
         result = tcd.getTestResultFailed(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_COMPLETE6);
         result.appendTcDetail("No session attribute available, expecting test result under attribute name: " + V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_COMPLETE6);
      }
      session.removeAttribute(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_COMPLETE6);
      writer.write(result.toString());
      
      /* TestCase: V3ResourceAsyncTests_SPEC_21_Async_dispatch6                     */
      /* Details: "The PortletAsyncContext object dispatch(String) method           */
      /* dispatches to the given path if called from within the original resource   */
      /* request"                                                                   */
   } else if (testcase.equals(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_DISPATCH6)) {
      result = tcd.getTestResultSucceeded(testcase);
      writer.write(result.toString());
      
      /* TestCase: V3ResourceAsyncTests_SPEC_21_Async_dispatch7                     */
      /* Details: "The PortletAsyncContext object dispatch(String) method           */
      /* dispatches to the given path if called from within an asynchronous thread" */
   } else if (testcase.equals(V3RESOURCEASYNCTESTS_SPEC_21_ASYNC_DISPATCH7)) {
      result = tcd.getTestResultSucceeded(testcase);
      writer.write(result.toString());
      
   }
}