List of usage examples for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
To view the source code for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.
Click Source Link
From source file:com.cimait.invoicec.portal.util.servlet.SBServletInitializer.java
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { ApplicationContext parent = null;/*w ww .j a va 2 s. c o m*/ Object object = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (object instanceof ApplicationContext) { this.logger.info("Root context already created (using as parent)."); parent = (ApplicationContext) object; servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null); } SpringApplicationBuilder application = new SpringApplicationBuilder(); if (parent != null) { application.initializers(new ParentContextApplicationContextInitializer(parent)); } application.initializers(new ServletContextApplicationContextInitializer(servletContext)); application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); application = configure(application); // Ensure error pages are registered //application.sources(ErrorPageFilter.class); return (WebApplicationContext) application.run(); }
From source file:org.efs.openreports.util.displaytag.MockDisplayTablePageContext.java
public MockDisplayTablePageContext(String exportType, ApplicationContext applicationContext) { request.setupAddParameter(// w w w . jav a 2 s . c o m new ParamEncoder(null).encodeParameterName(TableTagParameters.PARAMETER_EXPORTTYPE), exportType); HashMap<String, String> map = new HashMap<String, String>(); map.put(TableTagParameters.BEAN_BUFFER, "placeholder"); request.setAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY, map); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
From source file:org.parancoe.web.test.junit4.WebXmlContextLoader.java
/** * Loads a Spring ApplicationContext from the supplied * <code>locations</code>. and creates a standard {@link GenericWebApplicationContext} instance. * * @return a new application context//from w ww.j a v a 2 s .c o m * @see org.springframework.test.context.ContextLoader#loadContext * @see GenericWebApplicationContext * @see #createBeanDefinitionReader(GenericApplicationContext) * @see BeanDefinitionReader */ @Override public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Loading ApplicationContext for locations [{}].", StringUtils.arrayToCommaDelimitedString(locations)); } GenericWebApplicationContext context = new GenericWebApplicationContext(); createBeanDefinitionReader(context).loadBeanDefinitions(locations); MockServletContext servletContext = new MockServletContext(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:test.pl.chilldev.facelets.taglib.spring.social.NotConnectedTagTest.java
@Test public void applyNotConnected() throws IOException, FacesException { String provider = "facebook"; Map<String, Object> config = new HashMap<>(); config.put(NotConnectedTag.ATTRIBUTE_PROVIDER, provider); NotConnectedTag tag = new NotConnectedTag(MockTagConfig.factory(config, this.nextHandler)); // set up context FaceletContext context = new MockFaceletContext(); context.getFacesContext().getExternalContext().getApplicationMap() .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); List<Connection<?>> connections = new ArrayList<>(); when(this.applicationContext.getBean(ConnectionRepository.class)).thenReturn(this.connectionRepository); when(this.connectionRepository.findConnections(provider)).thenReturn(connections); // run the tag tag.apply(context, this.parent); verify(this.nextHandler).apply(context, this.parent); }
From source file:test.pl.chilldev.facelets.taglib.spring.social.ConnectedTagTest.java
@Test public void applyNotConnected() throws IOException, FacesException { String provider = "facebook"; Map<String, Object> config = new HashMap<>(); config.put(ConnectedTag.ATTRIBUTE_PROVIDER, provider); ConnectedTag tag = new ConnectedTag(MockTagConfig.factory(config, this.nextHandler)); // set up context FaceletContext context = new MockFaceletContext(); context.getFacesContext().getExternalContext().getApplicationMap() .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); List<Connection<?>> connections = new ArrayList<>(); when(this.applicationContext.getBean(ConnectionRepository.class)).thenReturn(this.connectionRepository); when(this.connectionRepository.findConnections(provider)).thenReturn(connections); // run the tag tag.apply(context, this.parent); verifyZeroInteractions(this.nextHandler); }
From source file:org.motechproject.mobile.web.IncomingMessageServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request//from w w w .java 2 s .c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { ApplicationContext appContext = (ApplicationContext) request.getSession().getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); WebManager webManager = (WebManager) appContext.getBean("webManagerBean"); IncomingMessageRequestWorker imrWorker = webManager.createIMRWorker(); String responseString = imrWorker.doRequest(request.getParameterMap()); out.print(responseString.replaceAll("\n", "<br />")); } finally { out.close(); } }
From source file:org.terasoluna.gfw.web.pagination.PaginationTagTest.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); WebApplicationContext wac = mock(WebApplicationContext.class); when(wac.getServletContext()).thenReturn(sc); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }
From source file:config.JettyConfiguration.java
@Bean public ServletContextHandler servletContext() throws IOException { ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS); AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); webApplicationContext.setParent(applicationContext); webApplicationContext.refresh();/*w ww. ja v a 2 s. co m*/ handler.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext); handler.setContextPath("/"); handler.setResourceBase(new ClassPathResource("webapp").getURI().toString()); handler.addServlet(AdminServlet.class, "/metrics/*"); handler.addServlet(dispatcherServlet(), "/"); handler.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", null); return handler; }
From source file:base.StripesTestFixture.java
@Before public void injectSpringContextInServletContext() { CTX.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }