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.laur...@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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to