Bug 50352 - AsyncListener.onComplete is not called after AsyncContext.complete() is called
Summary: AsyncListener.onComplete is not called after AsyncContext.complete() is called
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.5
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-27 16:30 UTC by Sylvain Laurent
Modified: 2010-11-29 12:00 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain Laurent 2010-11-27 16:30:59 UTC
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);
	}
}
Comment 1 Mark Thomas 2010-11-29 12:00:30 UTC
Fixed in 7.0.x and will be included in 7.0.6 onwards.