org.springframework.web.servlet.support.SessionFlashMapManager Java Examples
The following examples show how to use
org.springframework.web.servlet.support.SessionFlashMapManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedirectViewUriTemplateTests.java From spring-analysis-note with MIT License | 5 votes |
@Before 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()); }
Example #2
Source File: RedirectViewTests.java From spring-analysis-note with MIT License | 5 votes |
@Before 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(); }
Example #3
Source File: MockHttpServletRequestBuilder.java From spring-analysis-note with MIT License | 5 votes |
private FlashMapManager getFlashMapManager(MockHttpServletRequest request) { FlashMapManager flashMapManager = null; try { ServletContext servletContext = request.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); flashMapManager = wac.getBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class); } catch (IllegalStateException | NoSuchBeanDefinitionException ex) { // ignore } return (flashMapManager != null ? flashMapManager : new SessionFlashMapManager()); }
Example #4
Source File: MockHttpServletRequestBuilderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void flashAttribute() { this.builder.flashAttr("foo", "bar"); MockHttpServletRequest request = this.builder.buildRequest(this.servletContext); FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null); assertNotNull(flashMap); assertEquals("bar", flashMap.get("foo")); }
Example #5
Source File: RedirectViewUriTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Before 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()); }
Example #6
Source File: RedirectViewTests.java From java-technology-stack with MIT License | 5 votes |
@Before 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(); }
Example #7
Source File: StandaloneMockMvcBuilder.java From java-technology-stack with MIT License | 5 votes |
private void registerMvcSingletons(StubWebApplicationContext wac) { StandaloneConfiguration config = new StandaloneConfiguration(); config.setApplicationContext(wac); ServletContext sc = wac.getServletContext(); wac.addBeans(this.controllers); wac.addBeans(this.controllerAdvice); RequestMappingHandlerMapping hm = config.getHandlerMapping(); if (sc != null) { hm.setServletContext(sc); } hm.setApplicationContext(wac); hm.afterPropertiesSet(); wac.addBean("requestMappingHandlerMapping", hm); RequestMappingHandlerAdapter ha = config.requestMappingHandlerAdapter(); if (sc != null) { ha.setServletContext(sc); } ha.setApplicationContext(wac); ha.afterPropertiesSet(); wac.addBean("requestMappingHandlerAdapter", ha); wac.addBean("handlerExceptionResolver", config.handlerExceptionResolver()); 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); }
Example #8
Source File: MockHttpServletRequestBuilder.java From java-technology-stack with MIT License | 5 votes |
private FlashMapManager getFlashMapManager(MockHttpServletRequest request) { FlashMapManager flashMapManager = null; try { ServletContext servletContext = request.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); flashMapManager = wac.getBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class); } catch (IllegalStateException | NoSuchBeanDefinitionException ex) { // ignore } return (flashMapManager != null ? flashMapManager : new SessionFlashMapManager()); }
Example #9
Source File: MockHttpServletRequestBuilderTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void flashAttribute() { this.builder.flashAttr("foo", "bar"); MockHttpServletRequest request = this.builder.buildRequest(this.servletContext); FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null); assertNotNull(flashMap); assertEquals("bar", flashMap.get("foo")); }
Example #10
Source File: RedirectViewUriTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Before 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()); }
Example #11
Source File: RedirectViewTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void http11() throws Exception { RedirectView rv = new RedirectView(); rv.setUrl("http://url.somewhere.com"); rv.setHttp10Compatible(false); MockHttpServletRequest request = createRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); rv.render(new HashMap<String, Object>(), request, response); assertEquals(303, response.getStatus()); assertEquals("http://url.somewhere.com", response.getHeader("Location")); }
Example #12
Source File: StandaloneMockMvcBuilder.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void registerMvcSingletons(StubWebApplicationContext wac) { StandaloneConfiguration config = new StandaloneConfiguration(); config.setApplicationContext(wac); wac.addBeans(this.controllerAdvice); StaticRequestMappingHandlerMapping hm = config.getHandlerMapping(); hm.setServletContext(wac.getServletContext()); hm.setApplicationContext(wac); hm.afterPropertiesSet(); hm.registerHandlers(this.controllers); wac.addBean("requestMappingHandlerMapping", hm); RequestMappingHandlerAdapter handlerAdapter = config.requestMappingHandlerAdapter(); handlerAdapter.setServletContext(wac.getServletContext()); handlerAdapter.setApplicationContext(wac); handlerAdapter.afterPropertiesSet(); wac.addBean("requestMappingHandlerAdapter", handlerAdapter); wac.addBean("handlerExceptionResolver", config.handlerExceptionResolver()); 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); }
Example #13
Source File: MockHttpServletRequestBuilderTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void flashAttribute() { this.builder.flashAttr("foo", "bar"); MockHttpServletRequest request = this.builder.buildRequest(this.servletContext); FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null); assertNotNull(flashMap); assertEquals("bar", flashMap.get("foo")); }
Example #14
Source File: StandaloneMockMvcBuilder.java From spring-analysis-note with MIT License | 4 votes |
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); }
Example #15
Source File: RedirectViewTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private MockHttpServletRequest createRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap()); request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager()); return request; }
Example #16
Source File: RedirectViewTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private void doTest(final Map<String, ?> map, final String url, final boolean contextRelative, final boolean exposeModelAttributes, String expectedUrlForEncoding) throws Exception { class TestRedirectView extends RedirectView { public boolean queryPropertiesCalled = false; /** * Test whether this callback method is called with correct args */ @Override protected Map<String, Object> queryProperties(Map<String, Object> model) { // They may not be the same model instance, but they're still equal assertTrue("Map and model must be equal.", map.equals(model)); this.queryPropertiesCalled = true; return super.queryProperties(model); } } TestRedirectView rv = new TestRedirectView(); rv.setUrl(url); rv.setContextRelative(contextRelative); rv.setExposeModelAttributes(exposeModelAttributes); HttpServletRequest request = mock(HttpServletRequest.class, "request"); if (exposeModelAttributes) { given(request.getCharacterEncoding()).willReturn(WebUtils.DEFAULT_CHARACTER_ENCODING); } if (contextRelative) { expectedUrlForEncoding = "/context" + expectedUrlForEncoding; given(request.getContextPath()).willReturn("/context"); } given(request.getAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE)).willReturn(new FlashMap()); FlashMapManager flashMapManager = new SessionFlashMapManager(); given(request.getAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE)).willReturn(flashMapManager); HttpServletResponse response = mock(HttpServletResponse.class, "response"); given(response.encodeRedirectURL(expectedUrlForEncoding)).willReturn(expectedUrlForEncoding); response.sendRedirect(expectedUrlForEncoding); rv.render(map, request, response); if (exposeModelAttributes) { assertTrue("queryProperties() should have been called.", rv.queryPropertiesCalled); } }