@Override public Object getAsyncResult(long timeToWait) { if (this.mockRequest.getAsyncContext() != null && timeToWait == -1) { long requestTimeout = this.mockRequest.getAsyncContext().getTimeout(); timeToWait = requestTimeout == -1 ? Long.MAX_VALUE : requestTimeout; } if (!awaitAsyncDispatch(timeToWait)) { throw new IllegalStateException("Async result for handler [" + this.handler + "]" + " was not set during the specified timeToWait=" + timeToWait); } Object result = this.asyncResult.get(); Assert.state(result != RESULT_NONE, () -> "Async result for handler [" + this.handler + "] was not set"); return this.asyncResult.get(); }
@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); } }
AsyncContext asyncContext = request.getAsyncContext(); MockHttpServletResponse mockResponse; HttpServletResponse servletResponse;
@Override public Object getAsyncResult(long timeToWait) { if (this.mockRequest.getAsyncContext() != null) { timeToWait = (timeToWait == -1 ? this.mockRequest.getAsyncContext().getTimeout() : timeToWait); } if (!awaitAsyncDispatch(timeToWait)) { throw new IllegalStateException("Async result for handler [" + this.handler + "]" + " was not set during the specified timeToWait=" + timeToWait); } Object result = this.asyncResult.get(); if (result == RESULT_NONE) { throw new IllegalStateException("Async result for handler [" + this.handler + "] was not set"); } return this.asyncResult.get(); }
@Override public Object getAsyncResult(long timeToWait) { if (this.mockRequest.getAsyncContext() != null && timeToWait == -1) { long requestTimeout = this.mockRequest.getAsyncContext().getTimeout(); timeToWait = requestTimeout == -1 ? Long.MAX_VALUE : requestTimeout; } if (!awaitAsyncDispatch(timeToWait)) { throw new IllegalStateException("Async result for handler [" + this.handler + "]" + " was not set during the specified timeToWait=" + timeToWait); } Object result = this.asyncResult.get(); Assert.state(result != RESULT_NONE, () -> "Async result for handler [" + this.handler + "] was not set"); return this.asyncResult.get(); }
@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); } }
request.getAsyncContext() != null && !request.isAsyncStarted()) { request.getAsyncContext().complete();
AsyncContext asyncContext = request.getAsyncContext(); MockHttpServletResponse mockResponse; HttpServletResponse servletResponse;