Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-1246

AsyncContext.dispatch(jsp) does not send content to the wrapped response

XMLWordPrintable

    • 47817144

      I have a simple Async servlet. doGet method simply starts an async and dispatch the request to a JSP in runable task. I create a simple response wrapper to see if getWriter or getOutputStream of the wrapper will be called or not when dispatch JSP called. See the code:

      @WebServlet(asyncSupported = true, urlPatterns =

      { "/testAsync.do" }

      )
      public class TestAsyncServlet extends HttpServlet {

      private static final long serialVersionUID = 1L;

      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

      final AsyncContext ac = req.startAsync(req, new TestAsyncRespWrapper(resp));
      ac.start(new Runnable() {

      @Override
      public void run() {
      try

      { Thread.sleep(3000); }

      catch (InterruptedException ex) {
      }
      ac.dispatch("/WEB-INF/jsp/testAsync.jsp");
      }
      });
      }

      static class TestAsyncRespWrapper extends HttpServletResponseWrapper {

      public TestAsyncRespWrapper(HttpServletResponse resp)

      { super(resp); }

      @Override
      public PrintWriter getWriter() throws IOException

      { System.out.println("TestAsyncRespWrapper - getWriter() called."); return super.getWriter(); }

      @Override
      public ServletOutputStream getOutputStream() throws IOException

      { System.out.println("TestAsyncRespWrapper - getOutputStream() called."); return super.getOutputStream(); }

      }
      }

      testAsync.jsp:

      <%@ page language="java" contentType="text/html; charset=utf-8"%>
      <!DOCTYPE html>
      <html>
      <head>
      <title>Test Async</title>
      </head>
      <body>
      <h2>This is a JSP</h2>

      <% System.out.println("Response class in JSP: " + response.getClass()); %>

      </body>
      </html>

      ----- ISSUE -----
      Deploy the Servlet and run http://localhost:8080/app-test/testAsync.do
      See JSP content generated displays in the browser - OK

      BUT: the response wrapper getWriter() OR getOutputStream never get called.
      System.out in JSP prints: Response class in JSP: class io.undertow.servlet.spec.HttpServletResponseImpl

      ----- NOTE ----
      If I create a Servlet Filter and move the response wrapper into the filter --> I get the same issue.

      ----- EXPECTED -----

      the response wrapper getWriter() OR getOutputStream will be called.
      And
      System.out in JSP prints: Response class in JSP: class TestAsyncRespWrapper

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              haducloc Loc Ha (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: