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()); }
@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")); }
@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()); }
@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(); }
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); }
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()); }
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 ex) { } catch (NoSuchBeanDefinitionException ex) { } return (flashMapManager != null) ? flashMapManager : new SessionFlashMapManager(); }
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 ex) { // ignore } catch (NoSuchBeanDefinitionException ex) { // ignore } return (flashMapManager != null ? flashMapManager : new SessionFlashMapManager()); }
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); }
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); }