use of cn.taketoday.web.context.async.WebAsyncManager in project today-infrastructure by TAKETODAY.
the class ErrorPageFilterTests method setUpAsyncDispatch.
private void setUpAsyncDispatch() throws Exception {
this.request.setAsyncSupported(true);
this.request.setAsyncStarted(true);
DeferredResult<String> result = new DeferredResult<>();
ServletRequestContext context = new ServletRequestContext(null, request, response);
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(context);
asyncManager.setAsyncRequest(new StandardServletAsyncWebRequest(context));
asyncManager.startDeferredResultProcessing(result);
}
use of cn.taketoday.web.context.async.WebAsyncManager 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.WebAsyncManager in project today-framework by TAKETODAY.
the class ErrorPageFilterTests method setUpAsyncDispatch.
private void setUpAsyncDispatch() throws Exception {
this.request.setAsyncSupported(true);
this.request.setAsyncStarted(true);
DeferredResult<String> result = new DeferredResult<>();
ServletRequestContext context = new ServletRequestContext(null, request, response);
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(context);
asyncManager.setAsyncRequest(new StandardServletAsyncWebRequest(request, response));
asyncManager.startDeferredResultProcessing(result);
}
use of cn.taketoday.web.context.async.WebAsyncManager in project today-framework 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);
ServletInvocableHandlerMethod invocableMethod = createInvocableHandlerMethod(request, handlerMethod);
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.WebAsyncManager in project today-framework by TAKETODAY.
the class ResponseBodyEmitterReturnValueHandlerTests method responseBodyFluxWithError.
// gh-21972
@Test
public void responseBodyFluxWithError() throws Exception {
this.request.addHeader("Accept", "text/event-stream");
HandlerMethod type = on(TestController.class).resolveHandlerMethod(Flux.class, String.class);
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();
this.handler.handleReturnValue(webRequest, type, sink.asFlux());
assertThat(this.request.isAsyncStarted()).isTrue();
IllegalStateException ex = new IllegalStateException("wah wah");
sink.tryEmitError(ex);
sink.tryEmitComplete();
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.webRequest);
assertThat(asyncManager.getConcurrentResult()).isSameAs(ex);
assertThat(this.response.getContentType()).isNull();
}
Aggregations