use of cn.taketoday.web.context.async.AsyncWebRequest in project today-infrastructure by TAKETODAY.
the class ReactiveTypeHandlerTests method resetRequest.
private void resetRequest() {
this.servletRequest = new MockHttpServletRequest();
this.servletResponse = new MockHttpServletResponse();
this.webRequest = new ServletRequestContext(null, this.servletRequest, this.servletResponse);
AsyncWebRequest webRequest = new StandardServletAsyncWebRequest(this.webRequest);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncRequest(webRequest);
this.servletRequest.setAsyncSupported(true);
}
use of cn.taketoday.web.context.async.AsyncWebRequest in project today-infrastructure by TAKETODAY.
the class RequestMappingHandlerAdapter method invokeHandlerMethod.
/**
* Invoke the {@link RequestMapping} handler method preparing a {@link ModelAndView}
* if view resolution is required.
*
* @see #createInvocableHandlerMethod(RequestContext, HandlerMethod)
*/
@Nullable
protected Object invokeHandlerMethod(RequestContext request, HandlerMethod handlerMethod) throws Throwable {
BindingContext bindingContext = createBindingContext(handlerMethod);
ModelFactory modelFactory = getModelFactory(handlerMethod, bindingContext);
// ActionMappingAnnotationHandler handler = annotationHandlerMap.get(handlerMethod);
ServletInvocableHandlerMethod invocableMethod = createInvocableHandlerMethod(request, handlerMethod);
invocableMethod.setReturnValueHandlerManager(returnValueHandlerManager);
RedirectModel inputRedirectModel = RequestContextUtils.getInputRedirectModel(request, redirectModelManager);
bindingContext.addAllAttributes(inputRedirectModel);
modelFactory.initModel(request, bindingContext, invocableMethod);
AsyncWebRequest asyncWebRequest = WebAsyncUtils.createAsyncWebRequest(request);
asyncWebRequest.setTimeout(asyncRequestTimeout);
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
asyncManager.setTaskExecutor(taskExecutor);
asyncManager.setAsyncRequest(asyncWebRequest);
asyncManager.registerCallableInterceptors(callableInterceptors);
asyncManager.registerDeferredResultInterceptors(deferredResultInterceptors);
if (asyncManager.hasConcurrentResult()) {
Object result = asyncManager.getConcurrentResult();
bindingContext = asyncManager.getBindingContext();
asyncManager.clearConcurrentResult();
LogFormatUtils.traceDebug(log, traceOn -> {
String formatted = LogFormatUtils.formatValue(result, !traceOn);
return "Resume with async result [" + formatted + "]";
});
invocableMethod = invocableMethod.wrapConcurrentResult(result);
}
Object returnValue = invocableMethod.invokeAndHandle(request, bindingContext);
if (asyncManager.isConcurrentHandlingStarted()) {
return null;
}
// modelFactory.updateModel(request, bindingContext);
return returnValue;
}
use of cn.taketoday.web.context.async.AsyncWebRequest in project today-framework by TAKETODAY.
the class ResponseBodyEmitterReturnValueHandlerTests method responseBodyEmitterWithTimeoutValue.
@Test
public void responseBodyEmitterWithTimeoutValue() throws Exception {
AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncRequest(asyncWebRequest);
ResponseBodyEmitter emitter = new ResponseBodyEmitter(19000L);
emitter.onTimeout(mock(Runnable.class));
emitter.onCompletion(mock(Runnable.class));
HandlerMethod handlerMethod = on(TestController.class).resolveHandlerMethod(ResponseBodyEmitter.class);
this.handler.handleReturnValue(webRequest, handlerMethod, emitter);
verify(asyncWebRequest).setTimeout(19000L);
verify(asyncWebRequest).addTimeoutHandler(any(Runnable.class));
verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
verify(asyncWebRequest).startAsync();
}
use of cn.taketoday.web.context.async.AsyncWebRequest in project today-framework by TAKETODAY.
the class ResponseBodyEmitterReturnValueHandlerTests method responseBodyEmitterWithErrorValue.
@SuppressWarnings("unchecked")
@Test
public void responseBodyEmitterWithErrorValue() throws Exception {
AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncRequest(asyncWebRequest);
ResponseBodyEmitter emitter = new ResponseBodyEmitter(19000L);
emitter.onError(mock(Consumer.class));
emitter.onCompletion(mock(Runnable.class));
HandlerMethod type = on(TestController.class).resolveHandlerMethod(ResponseBodyEmitter.class);
this.handler.handleReturnValue(webRequest, type, emitter);
verify(asyncWebRequest).addErrorHandler(any(Consumer.class));
verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
verify(asyncWebRequest).startAsync();
}
use of cn.taketoday.web.context.async.AsyncWebRequest in project today-framework by TAKETODAY.
the class ResponseBodyEmitterReturnValueHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
List<HttpMessageConverter<?>> converters = Collections.singletonList(new MappingJackson2HttpMessageConverter());
this.handler = new ResponseBodyEmitterReturnValueHandler(converters);
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.webRequest = new ServletRequestContext(null, this.request, this.response);
AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncRequest(asyncWebRequest);
this.request.setAsyncSupported(true);
}
Aggregations