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");
}
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;
}
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");
}
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);
}
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;
}
Aggregations