Search in sources :

Example 1 with RedirectModel

use of cn.taketoday.web.view.RedirectModel in project today-infrastructure by TAKETODAY.

the class ParameterizableViewControllerTests method handleRequestWithFlashAttributes.

@Test
public void handleRequestWithFlashAttributes() throws Exception {
    this.request.setAttribute(RedirectModel.INPUT_ATTRIBUTE, new RedirectModel("name", "value"));
    ModelAndView mav = this.controller.handleRequest(this.context);
    assertThat(mav.getModel().size()).isEqualTo(1);
    assertThat(mav.getModel().get("name")).isEqualTo("value");
}
Also used : RedirectModel(cn.taketoday.web.view.RedirectModel) ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 2 with RedirectModel

use of cn.taketoday.web.view.RedirectModel 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;
}
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)

Example 3 with RedirectModel

use of cn.taketoday.web.view.RedirectModel in project today-framework by TAKETODAY.

the class ParameterizableViewControllerTests method handleRequestWithFlashAttributes.

@Test
public void handleRequestWithFlashAttributes() throws Exception {
    this.request.setAttribute(RedirectModel.INPUT_ATTRIBUTE, new RedirectModel("name", "value"));
    ModelAndView mav = this.controller.handleRequest(this.context);
    assertThat(mav.getModel().size()).isEqualTo(1);
    assertThat(mav.getModel().get("name")).isEqualTo("value");
}
Also used : RedirectModel(cn.taketoday.web.view.RedirectModel) ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 4 with RedirectModel

use of cn.taketoday.web.view.RedirectModel in project today-framework by TAKETODAY.

the class ModelFactoryTests method updateModelWhenRedirecting.

// SPR-12542
@Test
public void updateModelWhenRedirecting() throws Throwable {
    String attributeName = "sessionAttr";
    String attribute = "value";
    RequestContextDataBinder dataBinder = new RequestContextDataBinder(attribute, attributeName);
    BindingContext container = new BindingContext0(dataBinder);
    container.addAttribute(attributeName, attribute);
    String queryParam = "123";
    String queryParamName = "q";
    container.setRedirectModel(new RedirectModel(queryParamName, queryParam));
    ModelFactory modelFactory = new ModelFactory(null, container, this.attributeHandler);
    modelFactory.updateModel(this.webRequest, container);
    assertThat(container.getRedirectModel().get(queryParamName)).isEqualTo(queryParam);
    assertThat(container.getRedirectModel().size()).isEqualTo(1);
    assertThat(this.attributeStore.retrieveAttribute(this.webRequest, attributeName)).isEqualTo(attribute);
}
Also used : RedirectModel(cn.taketoday.web.view.RedirectModel) RequestContextDataBinder(cn.taketoday.web.bind.RequestContextDataBinder) BindingContext(cn.taketoday.web.BindingContext) Test(org.junit.jupiter.api.Test)

Example 5 with RedirectModel

use of cn.taketoday.web.view.RedirectModel 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

RedirectModel (cn.taketoday.web.view.RedirectModel)13 ModelAndView (cn.taketoday.web.view.ModelAndView)6 BindingContext (cn.taketoday.web.BindingContext)4 Test (org.junit.jupiter.api.Test)4 Nullable (cn.taketoday.lang.Nullable)2 RequestContext (cn.taketoday.web.RequestContext)2 AsyncWebRequest (cn.taketoday.web.context.async.AsyncWebRequest)2 WebAsyncManager (cn.taketoday.web.context.async.WebAsyncManager)2 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)2 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)2 RequestContextDataBinder (cn.taketoday.web.bind.RequestContextDataBinder)1 HandlerMethod (cn.taketoday.web.handler.method.HandlerMethod)1 ModelMap (cn.taketoday.web.view.ModelMap)1 RedirectModelManager (cn.taketoday.web.view.RedirectModelManager)1 Method (java.lang.reflect.Method)1