Search in sources :

Example 6 with AsyncWebRequest

use of cn.taketoday.web.context.async.AsyncWebRequest in project today-framework 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.servletRequest, this.servletResponse);
    WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncRequest(webRequest);
    this.servletRequest.setAsyncSupported(true);
}
Also used : StandardServletAsyncWebRequest(cn.taketoday.web.context.async.StandardServletAsyncWebRequest) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) AsyncWebRequest(cn.taketoday.web.context.async.AsyncWebRequest) StandardServletAsyncWebRequest(cn.taketoday.web.context.async.StandardServletAsyncWebRequest) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)

Example 7 with AsyncWebRequest

use of cn.taketoday.web.context.async.AsyncWebRequest 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;
}
Also used : WebAsyncManager(cn.taketoday.web.context.async.WebAsyncManager) RedirectModel(cn.taketoday.web.view.RedirectModel) BindingContext(cn.taketoday.web.BindingContext) AsyncWebRequest(cn.taketoday.web.context.async.AsyncWebRequest) Nullable(cn.taketoday.lang.Nullable)

Aggregations

AsyncWebRequest (cn.taketoday.web.context.async.AsyncWebRequest)7 StandardServletAsyncWebRequest (cn.taketoday.web.context.async.StandardServletAsyncWebRequest)5 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)3 Nullable (cn.taketoday.lang.Nullable)2 BindingContext (cn.taketoday.web.BindingContext)2 WebAsyncManager (cn.taketoday.web.context.async.WebAsyncManager)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 RedirectModel (cn.taketoday.web.view.RedirectModel)2 Test (org.junit.jupiter.api.Test)2 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)1 MappingJackson2HttpMessageConverter (cn.taketoday.http.converter.json.MappingJackson2HttpMessageConverter)1 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)1 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)1 Consumer (java.util.function.Consumer)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1