List of usage examples for javax.servlet ServletContextEvent ServletContextEvent
public ServletContextEvent(ServletContext source)
From source file:org.jasig.cas.util.CasLoggerContextInitializer.java
/** * Initialize the logger by decorating the context * with settings for the log file and context. * Calls the initializer of the logging framework * to start the logger./* w w w. ja v a 2s .c om*/ */ private void initialize() { try { if (!INITIALIZED.get() && this.loggerContext != null) { final ServletContextEvent event = new ServletContextEvent(this.context); this.loggerContext.contextInitialized(event); LOGGER.debug("Initialized logging context via [{}]. Logs will be written to [{}]", this.loggerContext.getClass().getSimpleName(), this.logConfigurationFile); INITIALIZED.set(true); } } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderListenerWithDefaultContext() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/applicationContext.xml " + "/org/springframework/web/context/WEB-INF/context-addition.xml"); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);//from w w w. jav a 2 s .co m PortletContextLoader contextLoader = (PortletContextLoader) sc .getAttribute(PortletApplicationContextUtils2.ROOT_PORTLET_APPLICATION_CONTEXT_LOADER_ATTRIBUTE); assertNotNull(contextLoader); //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContext context = PortletApplicationContextUtils2.getPortletApplicationContext(pc); assertTrue("Correct PortletApplicationContext exposed in PortletContext", context instanceof ContribXmlPortletApplicationContext); assertTrue(PortletContextLoader .getCurrentPortletApplicationContext() instanceof ContribXmlPortletApplicationContext); LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle"); assertTrue("Has father", context.containsBean("father")); assertTrue("Has rod", context.containsBean("rod")); assertTrue("Has kerry", context.containsBean("kerry")); assertTrue("Not destroyed", !lb.isDestroyed()); assertFalse(context.containsBean("beans1.bean1")); assertFalse(context.containsBean("beans1.bean2")); listener.contextDestroyed(event); assertTrue("Destroyed", lb.isDestroyed()); assertNull(sc.getAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE)); assertNull(PortletContextLoader.getCurrentPortletApplicationContext()); }
From source file:org.grails.plugin.batch.Launcher.java
public void init(String[] args) { logDebug(true, "init(): begin"); synchronized (initLock) { logDebug(true, "init(): this classLoader ", this.getClass().getClassLoader()); logDebug(true, "init(): thread classLoader ", Thread.currentThread().getContextClassLoader()); logDebug(true, "init(): env ", Environment.getCurrent()); String resourcePath = getSystemProperty("resourcePath", null); if (resourcePath == null) { resourcePath = "war"; }//from w w w. j a va2 s . c o m logDebug(true, "init(): resourcePath ", resourcePath); servletContext = resourcePath != null ? new MockServletContext(resourcePath) : new MockServletContext(); servletContext.setAttribute("args", args); servletContextListeners = new ServletContextListener[] { new Log4jConfigListener(), new GrailsContextLoaderListener() }; this.shutdownHook = new Thread() { public void run() { logDebug(true, "shutdown hook run():"); Launcher.this.destroy(); } }; this.destroyed = false; Runtime.getRuntime().addShutdownHook(this.shutdownHook); logDebug(true, "init(): shutdown hook added"); try { ServletContextEvent event = new ServletContextEvent(servletContext); for (ServletContextListener l : servletContextListeners) { l.contextInitialized(event); } } catch (RuntimeException e) { log.error("init()", e); throw e; } logDebug("init(): thread classLoader ", Thread.currentThread().getContextClassLoader()); GrailsApplication grailsApplication = ApplicationHolder.getApplication(); DefaultGrailsMainClass main = getMainClass(grailsApplication); if (main != null) { final Object instance = main.getReferenceInstance(); WebApplicationContext webContext = (WebApplicationContext) grailsApplication.getMainContext(); webContext.getAutowireCapableBeanFactory().autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); main.callInit(); } logDebug("init(): end"); } }
From source file:org.opennms.netmgt.ncs.rest.AbstractSpringJerseyRestTestCase.java
@Before public void setUp() throws Throwable { beforeServletStart();/*w w w . j a va 2s. c o m*/ setServletContext(new MockServletContext("file:src/main/webapp")); getServletContext().addInitParameter("contextConfigLocation", "file:src/main/resources/META-INF/opennms/component-service.xml"); getServletContext().addInitParameter("parentContextKey", "testDaoContext"); ServletContextEvent e = new ServletContextEvent(getServletContext()); setContextListener(new ContextLoaderListener()); getContextListener().contextInitialized(e); getServletContext().setContextPath(contextPath); setServletConfig(new MockServletConfig(getServletContext(), "dispatcher")); /* getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.netmgt.ncs.rest"); */ try { MockFilterConfig filterConfig = new MockFilterConfig(getServletContext(), "openSessionInViewFilter"); setFilter(new OpenSessionInViewFilter()); getFilter().init(filterConfig); setDispatcher(new SpringServlet()); getDispatcher().init(getServletConfig()); } catch (ServletException se) { throw se.getRootCause(); } setWebAppContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext())); afterServletStart(); System.err.println("------------------------------------------------------------------------------"); }
From source file:org.jasig.cas.util.CasLoggerContextInitializer.java
/** * Destroys all logging hooks and shuts down * the logger.// w w w. j a va2 s . c om */ @PreDestroy public void destroy() { try { if (INITIALIZED.get() && this.loggerContext != null) { final ServletContextEvent event = new ServletContextEvent(this.context); LOGGER.debug("Destroying logging context and shutting it down"); this.loggerContext.contextDestroyed(event); } } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:it.tidalwave.northernwind.frontend.util.NorthernWindContextLoaderListener.java
/******************************************************************************************************************* * * {@inheritDoc}// ww w. j a v a 2 s.c om * ******************************************************************************************************************/ @Override public void contextInitialized(final @Nonnull ServletContextEvent event) { try { log.log("Initializing Spring..."); super.contextInitialized( new ServletContextEvent(new ServletContextDecorator(event.getServletContext()))); } catch (Throwable t) { event.getServletContext().setAttribute(ATTRIBUTE_BOOT_THROWABLE, t); } }
From source file:com.xemantic.tadedon.guice.servlet.mock.FakeServletContainer.java
/** * Starts the container with using given {@code servletContext}. * * @param context the servlet context.//from w w w . j a v a 2 s . co m * @throws ServletException if {@link GuiceFilter} cannot be initialized. * @see #start() */ public void start(ServletContext context) throws ServletException { m_session = new MockHttpSession(); m_context = context; MockFilterConfig config = new MockFilterConfig(m_context); m_filter.init(config); m_listener.contextInitialized(new ServletContextEvent(m_context)); }
From source file:com.xemantic.tadedon.guice.servlet.mock.FakeServletContainer.java
/** * Stops the container. */ public void stop() { m_filter.destroy(); m_listener.contextDestroyed(new ServletContextEvent(m_context)); }
From source file:com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.java
private void notifyStartListeners(ServletContext context) { for (ServletContextListener listener : contextListeners) { listener.contextInitialized(new ServletContextEvent(context)); }/* w ww . j av a 2 s. c om*/ }
From source file:org.opennms.netmgt.ncs.rest.AbstractSpringJerseyRestTestCase.java
@After public void tearDown() throws Exception { System.err.println("------------------------------------------------------------------------------"); beforeServletDestroy();//w w w. j a v a 2 s .c o m getContextListener().contextDestroyed(new ServletContextEvent(getServletContext())); if (getDispatcher() != null) { getDispatcher().destroy(); } afterServletDestroy(); }