Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-4352

Servlet 3 - async-mode - onComplete not tirggered when JSP is dispatched

    Details

      Description

      When a JSP is dispatched in a Async-Servlet, the AsyncListener#onComplete is never triggered.

      AsyncServlet.java
      @WebServlet(urlPatterns = { "/AsyncServlet" }, asyncSupported = true)
      public class AsyncServlet extends HttpServlet {
      	public AsyncServlet() {
      		super();
      	}
      
      	@Override
      	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      		res.setContentType("text/html");
      		final AsyncContext ac;
      		if (req.isAsyncStarted()) {
      			ac = req.getAsyncContext();
      		} else {
      			ac = req.startAsync();
      		}
      		ac.setTimeout(5000);
      		ac.addListener(new AsyncListener() {
      			@Override
      			public void onTimeout(AsyncEvent event) throws IOException {
      				System.out.println("onTimeout");
      			}
      			@Override
      			public void onStartAsync(AsyncEvent event) throws IOException {
      				System.out.println("onStartAsync");
      			}
      			@Override
      			public void onError(AsyncEvent event) throws IOException {
      				System.out.println("onError");
      			}
      			@Override
      			public void onComplete(AsyncEvent event) throws IOException {
      				System.out.println("onComplete");
      			}
      		});
      
      		System.out.println("Calling JSP...");
      		ac.dispatch("/result.jsp");
      		System.out.println("After JSP call");
      	}
      }
      
      result.jsp
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>AsyncServletTest</title>
      </head>
      <body>
      	<p>JSP Content</p>
      	<%
      	System.out.println("Start JSP");
      	Thread.sleep(1000); // sleep 1 seconds
      	String resp = (String)request.getAttribute("result");
      	resp = resp + "<p>on JSP</p>";
      	Thread.sleep(1000); // sleep 1 seconds
      	System.out.println("End JSP");
      	%>
      	<p><%=resp%></p>
      </body>
      </html>
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                swd847 Stuart Douglas
                Reporter:
                cwat-gugrill Günther Grill
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: