Package javax.servlet

Examples of javax.servlet.AsyncListener


  }

  private boolean startAsync(final String connectionId, HttpServletRequest req, HttpServletResponse response) {
    if (req.isAsyncSupported()) {
      final AsyncContext asyncContext = req.startAsync(req, response);
      asyncContext.addListener(new AsyncListener() {
        @Override
        public void onComplete(AsyncEvent event) throws IOException {
        }

        @Override
View Full Code Here


                boolean error = (event.getType() == EventType.ERROR) ? true : false;
                Iterator<AsyncListenerRegistration> asyncListenerRegistrations =
                    asyncContext.getAsyncListeners().values().iterator();
                while (asyncListenerRegistrations.hasNext()) {
                    AsyncListenerRegistration asyncListenerRegistration = asyncListenerRegistrations.next();
                    AsyncListener asyncListener = asyncListenerRegistration.getListener();
                    try {
                        if (timeout) {
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                            asyncListener.onTimeout(asyncEvent);
                        } else if (error) {
                            Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_ATTR);
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse(), t);
                            asyncListener.onError(asyncEvent);
                        } else {
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                            asyncListener.onComplete(asyncEvent);
                        }
                    } catch (Throwable e) {
                        container.getLogger().error(sm.getString("standardWrapper.async.listenerError",
                                getContainer().getName()), e);
                        exception(request, response, e);
View Full Code Here

                } else if (request.getAsyncContext() != null) {
                    // The AC was closed right away, so call onComplete as no event callback
                    // will occur in that case
                    Request.AsyncContextImpl asyncContext = (Request.AsyncContextImpl) request.getAsyncContext();
                    for (AsyncListenerRegistration asyncListenerRegistration : asyncContext.getAsyncListeners().values()) {
                        AsyncListener asyncListener = asyncListenerRegistration.getListener();
                        AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                        try {
                            asyncListener.onComplete(asyncEvent);
                        } catch (Throwable t) {
                            log.error(sm.getString("coyoteAdapter.complete", asyncListener.getClass()), t);
                        }
                    }
                }

            }
View Full Code Here

            throw new IllegalStateException(sm.getString("coyoteRequest.cannotStartAsync"));
        }
        LinkedHashMap<AsyncListener, AsyncListenerRegistration> localAsyncListeners = asyncListeners;
        asyncListeners = new LinkedHashMap<AsyncListener, AsyncListenerRegistration>();
        for (AsyncListenerRegistration registration : localAsyncListeners.values()) {
            AsyncListener asyncListener = registration.getListener();
            AsyncEvent asyncEvent = new AsyncEvent(asyncContext, registration.getRequest(), registration.getResponse());
            try {
                asyncListener.onStartAsync(asyncEvent);
            } catch (IOException e) {
                throw new IllegalStateException(sm.getString("coyoteRequest.onStartAsyncError",
                        asyncListener.getClass().getName()), e);
            }
        }
        canStartAsync = false;
        if (asyncContext == null) {
            asyncContext = new AsyncContextImpl();
View Full Code Here

    RequestContext requestContext = readRequestContext(req);
    final AsyncContext ctx = req.startAsync(req, resp);

    ctx.setTimeout(_timeout);
    ctx.addListener(new AsyncListener()
    {
      @Override
      public void onTimeout(AsyncEvent event) throws IOException
      {
        AsyncContext ctx = event.getAsyncContext();
View Full Code Here

  public void init() {
    super.onStart();
    req.startAsync(req, res);
    this.ac = req.getAsyncContext();
    // this.ac.setTimeout(1000);
    this.ac.addListener(new AsyncListener() {

      public void onTimeout(AsyncEvent event) throws IOException {
        timeout();

      }
View Full Code Here

  public void init() {
    super.onStart();
    req.startAsync(req, res);
    this.ac = req.getAsyncContext();
    // this.ac.setTimeout(1000);
    this.ac.addListener(new AsyncListener() {

      public void onTimeout(AsyncEvent event) throws IOException {
        timeout();

      }
View Full Code Here

        replay(asyncContext);

        pipeline.newInvocation().invoke();

        AsyncListener listener = listenerCap.getValue(); // addListener被调用

        Callable<?> callable = executor1.getCallable(); // executor.submit(callable)被调用
        assertNotNull(callable);

        // doExecuteTask控制是否执行runnable
        if (doExecuteTask) {
            // 在另一个线程中执行runnable,确保request被绑定到线程中(否则RequestProxyTester会报错)
            runnableCalled = false;
            assertNull(new SimpleAsyncTaskExecutor().submit(callable).get()); // callable总是返回null
            assertTrue(runnableCalled); // runnable或callable被执行
            assertEquals(newResult, GetScreenResult.get()); // doPerformRunnable以后,值被保存到result中

            verify(requestMock, asyncContext);
        }

        // onTimeout
        AsyncEvent event = createMock(AsyncEvent.class);
        reset(asyncContext);

        // 如果runnable已经被执行,那么event.getAsyncContext().complete()将不被执行。
        if (!doExecuteTask) {
            expect(event.getAsyncContext()).andReturn(asyncContext).once();

            asyncContext.complete();
            expectLastCall().andThrow(new IllegalStateException()).once(); // 即使complete抛出异常也没有关系。
        }

        replay(event, asyncContext);

        listener.onTimeout(event); // 当timeout时,asyncContext.complete被调用

        verify(event, asyncContext);
    }
View Full Code Here

            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Async Servlet</h1>");
            AsyncContext ac = request.startAsync();

            ac.addListener(new AsyncListener() {
                @Override
                public void onComplete(AsyncEvent event) throws IOException {
                    System.out.println("onComplete");
                }
View Full Code Here

        }
        // FIXME: if (asyncContext != null && !processing) { throw ISE }
        LinkedHashMap<AsyncListener, AsyncListenerRegistration> localAsyncListeners = asyncListeners;
        asyncListeners = new LinkedHashMap<AsyncListener, AsyncListenerRegistration>();
        for (AsyncListenerRegistration registration : localAsyncListeners.values()) {
            AsyncListener asyncListener = registration.getListener();
            AsyncEvent asyncEvent = new AsyncEvent(asyncContext, registration.getRequest(), registration.getResponse());
            try {
                asyncListener.onStartAsync(asyncEvent);
            } catch (IOException e) {
                // FIXME: error reporting ? throw new IllegalStateException(e);
            }
        }
        if (response.isClosed()) {
View Full Code Here

TOP

Related Classes of javax.servlet.AsyncListener

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.