use of org.springframework.web.servlet.support.SessionFlashMapManager in project motech by motech.
the class FlashMapInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Object flashMapObj = RequestContextUtils.getOutputFlashMap(request);
if (flashMapObj != null && !(flashMapObj instanceof FlashMap)) {
// we need to create a FlashMap using the webapp classLoader
FlashMap flashMapCopy = new FlashMap();
flashMapCopy.putAll((Map<? extends String, ?>) flashMapObj);
// then put it in the request
SessionFlashMapManager sessionFlashMapManager = new SessionFlashMapManager();
sessionFlashMapManager.saveOutputFlashMap(flashMapCopy, request, response);
}
return true;
}
use of org.springframework.web.servlet.support.SessionFlashMapManager in project spring-framework by spring-projects.
the class MockHttpServletRequestBuilderTests method flashAttribute.
@Test
void flashAttribute() {
this.builder.flashAttr("foo", "bar");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null);
assertThat((Object) flashMap).isNotNull();
assertThat(flashMap.get("foo")).isEqualTo("bar");
}
use of org.springframework.web.servlet.support.SessionFlashMapManager in project spring-framework by spring-projects.
the class StandaloneMockMvcBuilder method registerMvcSingletons.
private void registerMvcSingletons(StubWebApplicationContext wac) {
StandaloneConfiguration config = new StandaloneConfiguration();
config.setApplicationContext(wac);
ServletContext sc = wac.getServletContext();
wac.addBeans(this.controllers);
wac.addBeans(this.controllerAdvice);
FormattingConversionService mvcConversionService = config.mvcConversionService();
wac.addBean("mvcConversionService", mvcConversionService);
ResourceUrlProvider resourceUrlProvider = config.mvcResourceUrlProvider();
wac.addBean("mvcResourceUrlProvider", resourceUrlProvider);
ContentNegotiationManager mvcContentNegotiationManager = config.mvcContentNegotiationManager();
wac.addBean("mvcContentNegotiationManager", mvcContentNegotiationManager);
Validator mvcValidator = config.mvcValidator();
wac.addBean("mvcValidator", mvcValidator);
RequestMappingHandlerMapping hm = config.getHandlerMapping(mvcConversionService, resourceUrlProvider);
if (sc != null) {
hm.setServletContext(sc);
}
hm.setApplicationContext(wac);
hm.afterPropertiesSet();
wac.addBean("requestMappingHandlerMapping", hm);
RequestMappingHandlerAdapter ha = config.requestMappingHandlerAdapter(mvcContentNegotiationManager, mvcConversionService, mvcValidator);
if (sc != null) {
ha.setServletContext(sc);
}
ha.setApplicationContext(wac);
ha.afterPropertiesSet();
wac.addBean("requestMappingHandlerAdapter", ha);
wac.addBean("handlerExceptionResolver", config.handlerExceptionResolver(mvcContentNegotiationManager));
wac.addBeans(initViewResolvers(wac));
wac.addBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, this.localeResolver);
wac.addBean(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, new FixedThemeResolver());
wac.addBean(DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, new DefaultRequestToViewNameTranslator());
this.flashMapManager = new SessionFlashMapManager();
wac.addBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, this.flashMapManager);
extendMvcSingletons(sc).forEach(wac::addBean);
}
use of org.springframework.web.servlet.support.SessionFlashMapManager in project spring-framework by spring-projects.
the class RedirectViewTests method setUp.
@BeforeEach
public void setUp() throws Exception {
this.request = new MockHttpServletRequest();
this.request.setContextPath("/context");
this.request.setCharacterEncoding(WebUtils.DEFAULT_CHARACTER_ENCODING);
this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
this.request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager());
this.response = new MockHttpServletResponse();
}
use of org.springframework.web.servlet.support.SessionFlashMapManager in project spring-framework by spring-projects.
the class RedirectViewUriTemplateTests method setUp.
@BeforeEach
public void setUp() {
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
this.request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager());
}
Aggregations