tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 50352] New: AsyncListener.onComplete is not called after AsyncContext.complete() is called
Date Sat, 27 Nov 2010 21:31:02 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=50352

           Summary: AsyncListener.onComplete is not called after
                    AsyncContext.complete() is called
           Product: Tomcat 7
           Version: 7.0.4
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: sylvain.laurent@gmail.com


Using servlet 3 async features, when asyncContext.complete(); is called from an
async thread, the AsyncListener onComplete() method is not called though it
should be.

Example Servlet :


package test;

import java.io.IOException;

import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class MyServlet
 */
@WebServlet(value = "/MyServlet", asyncSupported = true)
public class MyServlet extends HttpServlet implements AsyncListener {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException
{
        final AsyncContext asyncContext = request.startAsync(request,
response);
        asyncContext.addListener(this);

        asyncContext.start(new Runnable() {

            @Override
            public void run() {
                try {
                    Thread.sleep(5 * 1000);
                    asyncContext.getResponse().getWriter().write("Hello
world");
                    asyncContext.complete();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    public void onComplete(AsyncEvent arg0) throws IOException {
        System.out.println("onComplete " + arg0);
    }

    @Override
    public void onError(AsyncEvent arg0) throws IOException {
        System.out.println("onError " + arg0);
    }

    @Override
    public void onStartAsync(AsyncEvent arg0) throws IOException {
        System.out.println("onStartAsync " + arg0);
    }

    @Override
    public void onTimeout(AsyncEvent arg0) throws IOException {
        System.out.println("onTimeout " + arg0);
    }
}

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message