@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { registerAsyncResultInterceptors(request); super.service(request, response); if (request.getAsyncContext() != null) { MockAsyncContext asyncContext; if (request.getAsyncContext() instanceof MockAsyncContext) { asyncContext = (MockAsyncContext) request.getAsyncContext(); } else { MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class); Assert.notNull(mockRequest, "Expected MockHttpServletRequest"); asyncContext = (MockAsyncContext) mockRequest.getAsyncContext(); Assert.notNull(asyncContext, () -> "Outer request wrapper " + request.getClass().getName() + " has an AsyncContext," + "but it is not a MockAsyncContext, while the nested " + mockRequest.getClass().getName() + " does not have an AsyncContext at all."); } CountDownLatch dispatchLatch = new CountDownLatch(1); asyncContext.addDispatchHandler(dispatchLatch::countDown); getMvcResult(request).setAsyncDispatchLatch(dispatchLatch); } }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { registerAsyncResultInterceptors(request); super.service(request, response); if (request.getAsyncContext() != null) { MockAsyncContext asyncContext; if (request.getAsyncContext() instanceof MockAsyncContext) { asyncContext = (MockAsyncContext) request.getAsyncContext(); } else { MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class); Assert.notNull(mockRequest, "Expected MockHttpServletRequest"); asyncContext = (MockAsyncContext) mockRequest.getAsyncContext(); Assert.notNull(asyncContext, () -> "Outer request wrapper " + request.getClass().getName() + " has an AsyncContext," + "but it is not a MockAsyncContext, while the nested " + mockRequest.getClass().getName() + " does not have an AsyncContext at all."); } CountDownLatch dispatchLatch = new CountDownLatch(1); asyncContext.addDispatchHandler(dispatchLatch::countDown); getMvcResult(request).setAsyncDispatchLatch(dispatchLatch); } }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { registerAsyncResultInterceptors(request); super.service(request, response); if (request.getAsyncContext() != null) { MockAsyncContext asyncContext; if (request.getAsyncContext() instanceof MockAsyncContext) { asyncContext = (MockAsyncContext) request.getAsyncContext(); } else { MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class); Assert.notNull(mockRequest, "Expected MockHttpServletRequest"); asyncContext = (MockAsyncContext) mockRequest.getAsyncContext(); Assert.notNull(asyncContext, "Outer request wrapper " + request.getClass().getName() + " has an AsyncContext,but it is not a MockAsyncContext, while the nested " + mockRequest.getClass().getName() + " does not have an AsyncContext at all."); } final CountDownLatch dispatchLatch = new CountDownLatch(1); asyncContext.addDispatchHandler(new Runnable() { @Override public void run() { dispatchLatch.countDown(); } }); getMvcResult(request).setAsyncDispatchLatch(dispatchLatch); } }