List of usage examples for javax.servlet ServletContextEvent getServletContext
public ServletContext getServletContext()
From source file:nl.tjonahen.javaee7.cdi.springbridge.servletsupport.ApplicationContextFinder.java
@Override public void contextInitialized(ServletContextEvent sce) { WebApplicationContext requiredWebApplicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(sce.getServletContext()); ApplicationContextLocatorImpl.putContext(requiredWebApplicationContext); ApplicationContextManager.getInstance(); // trigger Application context locator }
From source file:org.excalibur.service.deployment.server.context.handler.AbstractApplicationInitializedHandler.java
@Override public final void handlerApplicationInitialized(ServletContextEvent sce) { ApplicationContext context = (ApplicationContext) sce.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); String hostName = System.getProperty("org.excalibur.instance.hostname"); checkState(!isNullOrEmpty(hostName)); String regionName = System.getProperty("org.excalibur.provider.region.name"); checkState(!isNullOrEmpty(regionName)); String zoneName = System.getProperty("org.excalibur.provider.region.zone.name"); checkState(!isNullOrEmpty(zoneName)); String username = System.getProperty("org.excalibur.user.name"); checkState(!isNullOrEmpty(username)); String keyname = System.getProperty("org.excalibur.user.keyname"); checkState(!isNullOrEmpty(keyname)); Configuration configuration = new Configuration() .setProvider((ProviderSupport) context.getBean(Provider.class)) .setRegion(context.getBean(RegionRepository.class).findByName(regionName)) .setZone(context.getBean(RegionRepository.class).findZoneByName(zoneName)) .setUser(context.getBean(UserRepository.class).findUserByUsername(username)).setHostName(hostName); UserProviderCredentials credentials = context.getBean(UserRepository.class) .findLoginCredentialsOfUserForProvider(configuration.getUser().getId(), configuration.getProvider().getName()); checkNotNull(credentials).setRegion(configuration.getRegion()); credentials//from w w w. j av a 2 s . c o m .setLoginCredentials(credentials.getLoginCredentials().toBuilder().credentialName(keyname).build()); configuration.setCredentials(credentials); handlerApplicationInitializedEvent(configuration, context, sce); if (this.next_ != null) { this.next_.handlerApplicationInitialized(sce); } }
From source file:org.sonar.server.platform.PlatformServletContextListener.java
/** * Configure Logback from classpath, with configuration from sonar.properties *//* w w w . ja v a 2 s . co m*/ private void configureLogback(ServletContextEvent event) { String configProfilingLevel = defaultIfEmpty( event.getServletContext().getInitParameter(Profiling.CONFIG_PROFILING_LEVEL), System.getProperty(Profiling.CONFIG_PROFILING_LEVEL)); Profiling.Level profilingLevel = Profiling.Level.fromConfigString(configProfilingLevel); String consoleEnabled = defaultIfEmpty( defaultIfEmpty(event.getServletContext().getInitParameter(CONFIG_LOG_CONSOLE), System.getProperty(CONFIG_LOG_CONSOLE)), // Line below used in last resort "false"); Map<String, String> variables = ImmutableMap.of("RAILS_LOGGER_LEVEL", profilingLevel == Profiling.Level.FULL ? "DEBUG" : "WARN", "LOGFILE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT, "CONSOLE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? CONSOLE_FULL_LOGGING_FORMAT : CONSOLE_STANDARD_LOGGING_FORMAT, "CONSOLE_ENABLED", consoleEnabled); Logback.configure("/org/sonar/server/platform/logback.xml", variables); }
From source file:MyServlet.java
/** * Record the fact that this web application has been initialized. * * @param event The servlet context event *//*from w w w . ja v a 2 s. co m*/ public void contextInitialized(ServletContextEvent event) { this.context = event.getServletContext(); log("contextInitialized()"); }
From source file:com.headissue.pigeon.PigeonBootstrapListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { LogUtils.debug(log, "Pigeon listener is starting"); context = servletContextEvent.getServletContext(); super.contextInitialized(servletContextEvent); }
From source file:com.moreopen.websocket.demo.server.SpringContextLoaderListener.java
@Override public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); WebApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(event.getServletContext()); com.moreopen.websocket.demo.BeanLocator.setApplicationContext(applicationContext); logger.info("============ Initialize application context, done. " + applicationContext); }
From source file:com.telefonica.euro_iaas.paasmanager.bootstrap.PropertiesMBeanRegisterBootstrap.java
/** * Stores every system properties in BD and show them by JMX *//* w w w . j a v a 2s .c o m*/ public void contextInitialized(ServletContextEvent event) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); PropertiesProvider propertiesUtil = new PropertiesProviderFactoryImpl() .createPropertiesProvider((EntityManagerFactory) ctx.getBean("entityManagerFactory")); try { for (String namespace : propertiesUtil.getNamespaces()) { PropertiesProviderMBean mbean = new PropertiesProviderMBean(namespace, propertiesUtil); log.info("Registering mbean " + namespace); MBeanUtils.register(mbean, event.getServletContext().getContextPath() + ":service=SystemConfiguration-" + namespace); } } catch (Exception e) { throw new PaasManagerServerRuntimeException(e); } }
From source file:com.telefonica.euro_iaas.sdc.bootstrap.PropertiesMBeanRegisterBootstrap.java
/** * Unregister the mbean./*from w w w. j av a 2 s. c o m*/ */ public void contextDestroyed(ServletContextEvent event) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); PropertiesProvider propertiesUtil = new PropertiesProviderFactoryImpl() .createPropertiesProvider((EntityManagerFactory) ctx.getBean("entityManagerFactory")); try { for (String namespace : propertiesUtil.getNamespaces()) { log.info("Unregistering mbean " + namespace); MBeanUtils.unregister( event.getServletContext().getContextPath() + ":service=SystemConfiguration-" + namespace); } } catch (Exception e) { throw new SdcRuntimeException(e); } }
From source file:com.github.glue.mvc.general.DefaultConfigListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { super.contextInitialized(servletContextEvent); final ServletContext servletContext = servletContextEvent.getServletContext(); container = new DefaultContainer(); MvcConfig mvcConfig = createViewConfig(); RequestDefinitionScanner scanner = new RequestDefinitionScanner(mvcConfig.getActionPackages()); container.bind(RequestDefinitionScanner.class.getName(), scanner); for (ViewResolver resolver : mvcConfig.getViewResolvers()) { container.bind(resolver.getClass().getName() + ":" + resolver.getViewName(), resolver); }// www . j a v a 2 s. c om container.bind(ViewConfig.class.getName(), new DefaultViewConfig(container)); servletContext.setAttribute(CONTAINER, container); }
From source file:it.openutils.mgnlaws.magnolia.AmazonMgnlServletContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); String appVersion = context.getInitParameter(PARAM_APP_VERSION_KEY); if (!appVersion.equals("${project.version}") || StringUtils.endsWith(appVersion, "SNAPSHOT")) { String amazonAwsAccessKey = context.getInitParameter(PARAM_AWS_ACCESS_KEY); String amazonAwsSecretKey = context.getInitParameter(PARAM_AWS_SECRET_KEY); String amazonAwsRegion = context.getInitParameter(PARAM_AWS_REGION); System.setProperty("aws.credentials.accessKey", amazonAwsAccessKey); System.setProperty("aws.credentials.secretKey", amazonAwsSecretKey); System.setProperty("aws.region", amazonAwsRegion); if (StringUtils.isNotEmpty(amazonAwsAccessKey) && StringUtils.isNotEmpty(amazonAwsSecretKey)) { try { String ec2endpoint = "http://ec2." + amazonAwsRegion + ".amazonaws.com"; initEc2(amazonAwsAccessKey, amazonAwsSecretKey, ec2endpoint); } catch (IOException e) { log.warn("Error getting instance id", e); } catch (AmazonEc2InstanceNotFound e) { log.warn("Error getting instance details", e); }//from w ww .java2 s . com } else { log.warn("No Amazon credentials found"); } } super.contextInitialized(sce); }