List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:com.github.glue.mvc.guice.GuiceConfigListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { super.contextInitialized(servletContextEvent); final ServletContext servletContext = servletContextEvent.getServletContext(); servletContext.setAttribute(IOCCONTAINER, new GuiceContainer(createInjector())); }
From source file:org.apache.shindig.common.servlet.GuiceServletContextListener.java
public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); //HNN setting all system.properties specified in the web.xml setSystemProperties(context);// w ww. ja va 2 s .c om String moduleNames = context.getInitParameter(MODULES_ATTRIBUTE); List<Module> modules = Lists.newLinkedList(); if (moduleNames != null) { for (String moduleName : StringUtils.split(moduleNames, ':')) { try { moduleName = moduleName.trim(); if (moduleName.length() > 0) { modules.add((Module) Class.forName(moduleName).newInstance()); } } catch (InstantiationException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } Injector injector = Guice.createInjector(Stage.PRODUCTION, modules); context.setAttribute(INJECTOR_ATTRIBUTE, injector); try { if (!jmxInitialized) { Manager.manage("ShindigGuiceContext", injector); jmxInitialized = true; } } catch (Exception e) { // Ignore errors } }
From source file:org.apache.hupa.server.guice.GuiceServletConfig.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { servletContextRealPath = servletContextEvent.getServletContext().getRealPath("/"); // We get the mock classes using reflection, so as we can package Hupa without mock stuff. try {//from w w w . j a v a 2s . c o m Class<?> mockConstants = Class.forName("org.apache.hupa.server.mock.MockConstants"); demoProperties = (Properties) mockConstants.getField("mockProperties").get(null); demoHostName = demoProperties.getProperty("IMAPServerAddress"); } catch (Exception noDemoAvailable) { } super.contextInitialized(servletContextEvent); }
From source file:org.apache.hupa.server.ioc.GuiceListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { servletContextRealPath = servletContextEvent.getServletContext().getRealPath("/"); // We get the mock classes using reflection, so as we can package Hupa // without mock stuff. try {/*from w ww .j a v a 2s . c o m*/ Class<?> mockConstants = Class.forName("org.apache.hupa.server.mock.MockConstants"); demoProperties = (Properties) mockConstants.getField("mockProperties").get(null); demoHostName = demoProperties.getProperty("IMAPServerAddress"); } catch (Exception noDemoAvailable) { } super.contextInitialized(servletContextEvent); }
From source file:org.jbpm.bpel.integration.server.IntegrationConfigurator.java
public void contextDestroyed(ServletContextEvent event) { IntegrationControl integrationControl = (IntegrationControl) event.getServletContext() .getAttribute(SoapHandler.INTEGRATION_CONTROL_ATTR); // ensure integration control is bound to servlet context, as initialization may have failed if (integrationControl != null) { try {/*from w w w .ja va2 s . co m*/ integrationControl.disableInboundMessageActivities(); log.info("message reception disabled for process: " + integrationControl.getDeploymentDescriptor().getName()); } catch (JMSException e) { log.error("could not stop bpel application", e); } } }
From source file:org.owasp.webgoat.application.WebGoatServletListener.java
/** {@inheritDoc} */ @Override/*from w ww .j av a 2s. c o m*/ public void contextDestroyed(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); context.log("WebGoat is stopping"); // Unregister JDBC drivers in this context's ClassLoader: // Get the webapp's ClassLoader ClassLoader cl = Thread.currentThread().getContextClassLoader(); // Loop through all drivers Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { java.sql.Driver driver = drivers.nextElement(); if (driver.getClass().getClassLoader() == cl) { // This driver was registered by the webapp's ClassLoader, so deregister it: try { context.log("Unregister JDBC driver {}"); DriverManager.deregisterDriver(driver); } catch (SQLException ex) { context.log("Error unregistering JDBC driver {}"); } } else { // driver was not registered by the webapp's ClassLoader and may be in use elsewhere context.log("Not unregistering JDBC driver {} as it does not belong to this webapp's ClassLoader"); } } }
From source file:org.miloss.fgsms.agentcore.servlets.ServetShutdownListener.java
@Override public void contextDestroyed(ServletContextEvent sce) { IMessageProcessor singletonObject = MessageProcessor.getSingletonObject(); System.out.println(sce.getServletContext().getContextPath() + " is shutting down. FGSMS data enqueued is " + singletonObject.outboundQueueSize()); singletonObject.setRunning(false);//from w w w . j av a 2s . c o m while (singletonObject.outboundQueueSize() > 0) { System.out.println(sce.getServletContext().getContextPath() + " is shutting down. Waiting for queue to finish processing: items left: " + singletonObject.outboundQueueSize()); try { Thread.sleep(1000); } catch (InterruptedException ex) { } } singletonObject.terminate(); org.apache.commons.logging.LogFactory.release(Thread.currentThread().getContextClassLoader()); org.apache.commons.logging.LogFactory.release(this.getClass().getClassLoader()); org.apache.log4j.LogManager.shutdown(); }
From source file:com.moreopen.monitor.console.SpringContextLoaderListener.java
@Override public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); BeanLocator.setApplicationContext(/*from ww w .ja v a 2 s. c om*/ WebApplicationContextUtils.getWebApplicationContext(event.getServletContext())); logger.info("Initialize application context, done."); }
From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.ThemeInfoSetup.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); String themeDirPath = ctx.getRealPath("/themes"); if (themeDirPath == null) { throw new IllegalStateException("Application does not have a /themes directory."); }//from ww w.j a va 2 s .c o m File themesBaseDir = new File(themeDirPath); List<String> themeNames = getThemeNames(themesBaseDir); log.debug("themeNames: " + themeNames); if (themeNames.isEmpty()) { ss.fatal(this, "The application contains no themes. '" + themesBaseDir.getAbsolutePath() + "' has no child directories."); } String defaultThemeName = "vitro"; if (!themeNames.contains(defaultThemeName)) { defaultThemeName = themeNames.get(0); } log.debug("defaultThemeName: " + defaultThemeName); String currentThemeName = getCurrentThemeName(ctx); log.debug("currentThemeName: " + currentThemeName); if ((currentThemeName != null) && (!currentThemeName.isEmpty()) && (!themeNames.contains(currentThemeName))) { ss.warning(this, "The current theme selection is '" + currentThemeName + "', but that theme is not available. The '" + defaultThemeName + "' theme will be used instead. " + "Go to the Site Admin page and choose " + "\"Site Information\" to select a theme."); } ApplicationBean.themeInfo = new ThemeInfo(themesBaseDir, defaultThemeName, themeNames); ss.info(this, "current theme: " + currentThemeName + ", default theme: " + defaultThemeName + ", available themes: " + themeNames); }
From source file:org.owasp.webgoat.application.WebGoatServletListener.java
private void loadServlets(ServletContextEvent sce) { final ServletContext servletContext = sce.getServletContext(); ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false);/*www . ja v a 2s .c o m*/ provider.addIncludeFilter(new AnnotationTypeFilter(LessonServletMapping.class)); Set<BeanDefinition> candidateComponents = provider.findCandidateComponents("org.owasp.webgoat"); try { for (BeanDefinition beanDefinition : candidateComponents) { Class controllerClass = Class.forName(beanDefinition.getBeanClassName()); LessonServletMapping pathAnnotation = (LessonServletMapping) controllerClass .getAnnotation(LessonServletMapping.class); final ServletRegistration.Dynamic dynamic = servletContext .addServlet(controllerClass.getSimpleName(), controllerClass); dynamic.addMapping(pathAnnotation.path()); } } catch (Exception e) { logger.error("Error", e); } }