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:org.red5.logging.ContextLoggingListener.java
public void contextInitialized(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); String contextName = servletContext.getContextPath().replaceAll("/", ""); if ("".equals(contextName)) { contextName = "root"; }/*w w w. java 2 s .c o m*/ System.out.printf("Context init: %s%n", contextName); ConfigurableWebApplicationContext appctx = (ConfigurableWebApplicationContext) servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (appctx != null) { System.out.printf( "ConfigurableWebApplicationContext is not null in ContextLoggingListener for: %s, this indicates a misconfiguration or load order problem%n", contextName); } try { // get the selector ContextSelector selector = Red5LoggerFactory.getContextSelector(); // get the logger context for this servlet / app context by name URL url = servletContext.getResource(String.format("/WEB-INF/classes/logback-%s.xml", contextName)); if (url != null && Files.exists(Paths.get(url.toURI()))) { System.out.printf("Context logger config found: %s%n", url.toURI()); } else { url = servletContext.getResource("/WEB-INF/classes/logback.xml"); if (url != null && Files.exists(Paths.get(url.toURI()))) { System.out.printf("Context logger config found: %s%n", url.toURI()); } } // get the logger context for the servlet context LoggerContext loggerContext = url != null ? ((LoggingContextSelector) selector).getLoggerContext(contextName, url) : selector.getLoggerContext(contextName); // set the logger context for use elsewhere in the servlet context servletContext.setAttribute(Red5LoggerFactory.LOGGER_CONTEXT_ATTRIBUTE, loggerContext); // get the root logger for this context Logger logger = Red5LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME, contextName); logger.info("Starting up context: {}", contextName); } catch (Exception e) { System.err.printf("LoggingContextSelector is not the correct type: %s%n", e.getMessage()); e.printStackTrace(); } }
From source file:org.parancoe.web.PopulateInitialDataContextListener.java
@Override public void contextInitialized(ServletContextEvent evt) { ctx = (ApplicationContext) evt.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); Set<Class> fixtureClasses = new LinkedHashSet<Class>(getFixtureClasses()); if (fixtureClasses.isEmpty()) { log.info("Skipping initial data population (no models)"); return;/*from w w w . j a v a2 s .c om*/ } Map<Class, List> fixtures = YamlFixtureHelper.loadFixturesFromResource("initialData/", fixtureClasses); log.info("Populating initial data for models..."); SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory"); Session session = sessionFactory.openSession(); session.beginTransaction(); //Attach transaction to thread TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); TransactionSynchronizationManager.initSynchronization(); try { for (Class clazz : fixtures.keySet()) { List modelFixtures = fixtures.get(clazz); if (modelFixtures.isEmpty()) { log.warn("No data for {}, did you created the fixture file?", YamlFixtureHelper.getModelName(clazz)); continue; } populateTableForModel(clazz, modelFixtures); } fixtures.clear(); log.info("Populating initial data for models done!"); session.getTransaction().commit(); if (session.isOpen()) { session.close(); } } catch (Exception e) { log.error("Error while populating initial data for models {}", e.getMessage(), e); log.debug("Rolling back the populating database transaction"); session.getTransaction().rollback(); } finally { try { if (session.isOpen()) { session.close(); } } catch (Exception e) { /*do nothing*/ } TransactionSynchronizationManager.unbindResource(sessionFactory); TransactionSynchronizationManager.clearSynchronization(); } }
From source file:org.red5.server.undertow.UndertowApplicationContext.java
/** * Stop the application and servlet contexts. *///from w ww. j a v a 2 s. co m public void stop() { log.debug("stop"); try { Deployment deployment = manager.getDeployment(); ServletContextImpl servlet = deployment.getServletContext(); Object o = servlet.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (o != null) { log.debug("Spring context for {} was found", deployment.getDeploymentInfo().getContextPath()); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) o; // close the red5 app if (appCtx.isRunning()) { log.debug("Context was running, attempting to stop"); appCtx.stop(); } if (appCtx.isActive()) { log.debug("Context is active, attempting to close"); appCtx.close(); } } else { log.warn("Spring context for {} was not found", deployment.getDeploymentInfo().getContextPath()); } } catch (Exception e) { log.error("Could not stop spring context", e); } manager.undeploy(); }
From source file:br.com.caelum.vraptor.ioc.spring.DefaultSpringLocator.java
public ConfigurableWebApplicationContext getApplicationContext(ServletContext servletContext) { ConfigurableWebApplicationContext context = (ConfigurableWebApplicationContext) WebApplicationContextUtils .getWebApplicationContext(servletContext); if (context != null) { logger.info("Using a web application context: {}", context); return context; }/*ww w .j av a 2 s . c om*/ if (DefaultSpringLocator.class.getResource("/applicationContext.xml") != null) { logger.info("Using an XmlWebApplicationContext, searching for applicationContext.xml"); XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocation("classpath:applicationContext.xml"); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return ctx; } logger.info("No application context found"); ConfigurableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setId("VRaptor"); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return ctx; }
From source file:com.hp.security.jauth.core.filter.AuthFilter.java
public void init(FilterConfig filterConfig) throws ServletException { //init components this.servletContext = filterConfig.getServletContext(); context = (WebApplicationContext) servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); authService = context.getBean(AuthService.class); exceptionUtil = context.getBean(ExceptionUtil.class); systemInit = context.getBean(SystemInit.class); try {// ww w. j a v a 2 s . co m authHook = context.getBean(AuthHook.class); } catch (NoSuchBeanDefinitionException e) { log.info("no authHook find."); } try { systemInit.userValidationHook = context.getBean(UserValidationHook.class); } catch (NoSuchBeanDefinitionException e) { log.info("no userValidationHook find."); } try { systemInit.soapHook = context.getBean(SoapHook.class); } catch (NoSuchBeanDefinitionException e) { log.info("no SOAP Hook find."); } }
From source file:org.hdiv.web.servlet.tags.AbstractTagTests.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); SimpleWebApplicationContext wac = new SimpleWebApplicationContext(); wac.setServletContext(sc);// w w w . java2s. co m wac.setNamespace("test"); wac.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); if (inDispatcherServlet()) { request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); LocaleResolver lr = new AcceptHeaderLocaleResolver(); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr); ThemeResolver tr = new FixedThemeResolver(); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr); request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac); } else { sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); } return new MockPageContext(sc, request, response); }
From source file:computech.AbstractWebIntegrationTests.java
@Before public void setUp() { context.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);// ww w . j ava 2s . c o m mvc = MockMvcBuilders.webAppContextSetup(context).// addFilters(securityFilterChain).// build(); }
From source file:test.pl.chilldev.web.spring.context.SpringBeansJspPageMetaModelResolverTest.java
@Test(expected = PageMetaModelContextException.class) public void getPageMetaModelWithoutBean() throws PageMetaModelContextException { GenericWebApplicationContext appContext = new GenericWebApplicationContext(); appContext.refresh();// w ww. jav a2s. c o m PageContext jspContext = new MockPageContext(); jspContext.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext); PageMetaModelResolver resolver = new SpringBeansJspPageMetaModelResolver(); resolver.getPageMetaModel(jspContext); }
From source file:org.red5.logging.LoggerContextFilter.java
public void init(FilterConfig config) throws ServletException { ServletContext servletContext = config.getServletContext(); contextName = servletContext.getContextPath().replaceAll("/", ""); if ("".equals(contextName)) { contextName = "root"; }//from w w w. j a v a 2 s . c o m System.out.printf("Filter init: %s%n", contextName); ConfigurableWebApplicationContext appctx = (ConfigurableWebApplicationContext) servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (appctx != null) { System.out.printf( "ConfigurableWebApplicationContext is not null in LoggerContextFilter for: %s, this indicates a misconfiguration or load order problem%n", contextName); } }
From source file:org.openmrs.contrib.metadatarepository.webapp.listener.StartupListenerTest.java
public void testContextInitialized() { listener.contextInitialized(new ServletContextEvent(sc)); assertTrue(sc.getAttribute(Constants.CONFIG) != null); Map config = (Map) sc.getAttribute(Constants.CONFIG); assertEquals(config.get(Constants.CSS_THEME), "simplicity"); assertTrue(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null); assertTrue(sc.getAttribute(Constants.AVAILABLE_ROLES) != null); }