org.apache.catalina.LifecycleEvent Java Examples
The following examples show how to use
org.apache.catalina.LifecycleEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JasperListener.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Primary entry point for startup and shutdown events. * * @param event The event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { try { // Set JSP factory Class.forName("org.apache.jasper.compiler.JspRuntimeContext", true, this.getClass().getClassLoader()); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // Should not occur, obviously log.warn("Couldn't initialize Jasper", t); } // Another possibility is to do directly: // JspFactory.setDefaultFactory(new JspFactoryImpl()); } }
Example #2
Source File: Tomcat.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { try { Context context = (Context) event.getLifecycle(); if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { context.setConfigured(true); } // LoginConfig is required to process @ServletSecurity // annotations if (context.getLoginConfig() == null) { context.setLoginConfig( new LoginConfig("NONE", null, null, null)); context.getPipeline().addValve(new NonLoginAuthenticator()); } } catch (ClassCastException e) { return; } }
Example #3
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
@Override public void configureStart(final LifecycleEvent event, final StandardContext standardContext) { final ContextTransaction contextTransaction = new ContextTransaction(); contextTransaction.setProperty(org.apache.naming.factory.Constants.FACTORY, UserTransactionFactory.class.getName()); standardContext.getNamingResources().setTransaction(contextTransaction); if (event != null) { // ensure NamingContext is available for eager usage (@Observes @Initialized(ApplicationScoped) for instance) standardContext.getNamingContextListener().lifecycleEvent(event); } TomcatHelper.configureJarScanner(standardContext); startInternal(standardContext); // clear a bit log for default case addMyFacesDefaultParameters(standardContext.getLoader().getClassLoader(), standardContext.getServletContext()); // breaks cdi standardContext.setTldValidation(Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.tld.validation", "false"))); // breaks jstl standardContext.setXmlValidation(Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.xml.validation", "false"))); }
Example #4
Source File: IgnoredStandardContext.java From tomee with Apache License 2.0 | 6 votes |
public IgnoredStandardContext() { setJarScanner(new EmptyScanner()); // Tomcat has a stupid rule where a life cycle listener must set // configured true, or it will treat it as a failed deployment addLifecycleListener(new LifecycleListener() { @Override public void lifecycleEvent(final LifecycleEvent event) { final Context context = Context.class.cast(event.getLifecycle()); if (event.getType().equals(Lifecycle.START_EVENT) || event.getType().equals(Lifecycle.BEFORE_START_EVENT) || event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { context.setConfigured(true); } } }); }
Example #5
Source File: Tomcat.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { try { Context context = (Context) event.getLifecycle(); if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { context.setConfigured(true); } // LoginConfig is required to process @ServletSecurity // annotations if (context.getLoginConfig() == null) { context.setLoginConfig( new LoginConfig("NONE", null, null, null)); context.getPipeline().addValve(new NonLoginAuthenticator()); } } catch (ClassCastException e) { return; } }
Example #6
Source File: JMXServerListener.java From tomee with Apache License 2.0 | 6 votes |
@Override public synchronized void lifecycleEvent(final LifecycleEvent event) { try { if (server == null && Lifecycle.START_EVENT.equals(event.getType())) { serviceURL = new JMXServiceURL(protocol, host, port, urlPath); server = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, ManagementFactory.getPlatformMBeanServer()); server.start(); LOGGER.info("Started JMX server: " + serviceURL.toString()); } else if (server != null && Lifecycle.STOP_EVENT.equals(event.getType())) { server.stop(); server = null; LOGGER.info("Stopped JMX server: " + serviceURL.toString()); } } catch (final Exception e) { throw new JMXException(e); } }
Example #7
Source File: HostConfig.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { if (event.getType() == Lifecycle.AFTER_STOP_EVENT) { // The context has stopped. Context context = (Context) event.getLifecycle(); // Remove the old expanded WAR. ExpandWar.delete(toDelete); // Reset the docBase to trigger re-expansion of the WAR. context.setDocBase(newDocBase); // Remove this listener from the Context else it will run every // time the Context is stopped. context.removeLifecycleListener(this); } }
Example #8
Source File: EngineConfig.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Process the START event for an associated Engine. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the engine we are associated with try { engine = (Engine) event.getLifecycle(); } catch (ClassCastException e) { log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
Example #9
Source File: UserConfig.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Process the START event for an associated Host. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the host we are associated with try { host = (Host) event.getLifecycle(); } catch (ClassCastException e) { log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
Example #10
Source File: JniLifecycleListener.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.BEFORE_START_EVENT.equals(event.getType())) { if (!libraryName.isEmpty()) { System.loadLibrary(libraryName); log.info("Loaded native library " + libraryName); } else if (!libraryPath.isEmpty()) { System.load(libraryPath); log.info("Loaded native library from " + libraryPath); } else { throw new IllegalArgumentException("Either libraryName or libraryPath must be set"); } } }
Example #11
Source File: EngineConfig.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Process the START event for an associated Engine. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the engine we are associated with try { engine = (Engine) event.getLifecycle(); } catch (ClassCastException e) { log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
Example #12
Source File: UserConfig.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Process the START event for an associated Host. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the host we are associated with try { host = (Host) event.getLifecycle(); } catch (ClassCastException e) { log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
Example #13
Source File: JGroupsReportingLifeCycleListenerImplTest.java From jwala with Apache License 2.0 | 6 votes |
@Test public void testLifecycleEvent() throws Exception { when(mockLifeCycle.getState()).thenReturn(LifecycleState.STOPPING); lifeCycleListener.lifecycleEvent(new LifecycleEvent(mockLifeCycle, null, null)); sleep(2500); when(mockLifeCycle.getState()).thenReturn(LifecycleState.STOPPED); lifeCycleListener.lifecycleEvent(new LifecycleEvent(mockLifeCycle, null, null)); sleep(2500); verify(mockAppender, atLeastOnce()).doAppend((LoggingEvent) captorLoggingEvent.capture()); final int eventTotal = captorLoggingEvent.getAllValues().size(); final LoggingEvent loggingEvent = (LoggingEvent) captorLoggingEvent.getAllValues().get(eventTotal - 1); assertEquals("Channel closed", loggingEvent.getMessage()); System.out.println(captorLoggingEvent.getAllValues().size()); // make sure that the scheduler has stopped by checking if there are extra events after the listener has processed // a STOPPED life cycle sleep(2500); // pause to let any rogue scheduler do logging if there are any... assertEquals(eventTotal, captorLoggingEvent.getAllValues().size()); }
Example #14
Source File: StoreConfigLifecycleListener.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Register StoreRegistry after Start the complete Server. * * @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent) */ @Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.AFTER_START_EVENT.equals(event.getType())) { if (event.getSource() instanceof Server) { createMBean((Server) event.getSource()); } else { log.warn(sm.getString("storeConfigListener.notServer")); } } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) { if (oname != null) { registry.unregisterComponent(oname); oname = null; } } }
Example #15
Source File: LazyRealm.java From tomee with Apache License 2.0 | 6 votes |
@Override public void setContainer(final Container container) { container.addLifecycleListener(new LifecycleListener() { @Override public void lifecycleEvent(final LifecycleEvent event) { if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType())) { if (creationalContext != null) { creationalContext.release(); } } } }); if (delegate != null) { delegate.setContainer(container); } else { this.container = Context.class.cast(container); } }
Example #16
Source File: UserConfig.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Process the START event for an associated Host. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the host we are associated with try { host = (Host) event.getLifecycle(); } catch (ClassCastException e) { log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
Example #17
Source File: EngineConfig.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Process the START event for an associated Engine. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the engine we are associated with try { engine = (Engine) event.getLifecycle(); } catch (ClassCastException e) { log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
Example #18
Source File: JasperListener.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Primary entry point for startup and shutdown events. * * @param event The event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) { try { // Set JSP factory Class.forName("org.apache.jasper.compiler.JspRuntimeContext", true, this.getClass().getClassLoader()); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // Should not occur, obviously log.warn("Couldn't initialize Jasper", t); } // Another possibility is to do directly: // JspFactory.setDefaultFactory(new JspFactoryImpl()); } }
Example #19
Source File: TomEEUndeployTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void justAContextStop() throws Exception { container.start(); assertEquals(0, webapps().length); final StandardHost standardHost = StandardHost.class.cast(TomcatHelper.getServer().findService("Tomcat").getContainer().findChild("localhost")); final HostConfig listener = new HostConfig(); // not done in embedded but that's the way autodeploy works in normal tomcat standardHost.addLifecycleListener(listener); createWebapp(new File(WORK_DIR, "tomee/webapps/my-webapp")); listener.lifecycleEvent(new LifecycleEvent(standardHost, Lifecycle.START_EVENT, standardHost)); assertEquals(1, webapps().length); webapps()[0].stop(); assertEquals(1, webapps().length); webapps()[0].start(); assertEquals(1, webapps().length); assertEquals("test", IO.slurp(new URL("http://localhost:" + http + "/my-webapp/"))); }
Example #20
Source File: HostConfig.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) { // The context has stopped. Context context = (Context) event.getLifecycle(); // Remove the old expanded WAR. ExpandWar.delete(toDelete); // Reset the docBase to trigger re-expansion of the WAR. context.setDocBase(newDocBase); // Remove this listener from the Context else it will run every // time the Context is stopped. context.removeLifecycleListener(this); } }
Example #21
Source File: TomcatBpmPlatformBootstrap.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void deployBpmPlatform(LifecycleEvent event) { final StandardServer server = (StandardServer) event.getSource(); containerDelegate.getServiceContainer().createDeploymentOperation("deploy BPM platform") .addAttachment(TomcatAttachments.SERVER, server) .addStep(new TomcatParseBpmPlatformXmlStep()) .addStep(new DiscoverBpmPlatformPluginsStep()) .addStep(new StartManagedThreadPoolStep()) .addStep(new StartJobExecutorStep()) .addStep(new PlatformXmlStartProcessEnginesStep()) .execute(); LOG.camundaBpmPlatformSuccessfullyStarted(server.getServerInfo()); }
Example #22
Source File: Tomcat.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { try { Context context = (Context) event.getLifecycle(); if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { context.setConfigured(true); // Process annotations WebAnnotationSet.loadApplicationAnnotations(context); // LoginConfig is required to process @ServletSecurity // annotations if (context.getLoginConfig() == null) { context.setLoginConfig(new LoginConfig("NONE", null, null, null)); context.getPipeline().addValve(new NonLoginAuthenticator()); } } } catch (ClassCastException e) { } }
Example #23
Source File: TestHostConfigAutomaticDeployment.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { String type = event.getType(); if (type.equals(Lifecycle.START_EVENT) || type.equals(Lifecycle.STOP_EVENT) || type.equals(Lifecycle.AFTER_DESTROY_EVENT)) { stateHistory.append(type); } }
Example #24
Source File: TomEEUndeployTest.java From tomee with Apache License 2.0 | 5 votes |
@Test public void tomcatLifecycle() throws Exception { container.start(); assertEquals(0, webapps().length); final StandardHost standardHost = StandardHost.class.cast(TomcatHelper.getServer().findService("Tomcat").getContainer().findChild("localhost")); final HostConfig listener = new HostConfig(); // not done in embedded but that's the way autodeploy works in normal tomcat standardHost.addLifecycleListener(listener); createWebapp(new File(WORK_DIR, "tomee/webapps/my-webapp")); listener.lifecycleEvent(new LifecycleEvent(standardHost, Lifecycle.START_EVENT, standardHost)); assertEquals(1, webapps().length); }
Example #25
Source File: ThreadLocalLeakPreventionListener.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Listens for {@link LifecycleEvent} for the start of the {@link Server} to * initialize itself and then for after_stop events of each {@link Context}. */ @Override public void lifecycleEvent(LifecycleEvent event) { try { Lifecycle lifecycle = event.getLifecycle(); if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) && lifecycle instanceof Server) { // when the server starts, we register ourself as listener for // all context // as well as container event listener so that we know when new // Context are deployed Server server = (Server) lifecycle; registerListenersForServer(server); } if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()) && lifecycle instanceof Server) { // Server is shutting down, so thread pools will be shut down so // there is no need to clean the threads serverStopping = true; } if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) && lifecycle instanceof Context) { stopIdleThreads((Context) lifecycle); } } catch (Exception e) { String msg = sm.getString( "threadLocalLeakPreventionListener.lifecycleEvent.error", event); log.error(msg, e); } }
Example #26
Source File: TestHostConfigAutomaticDeployment.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { String type = event.getType(); if (type.equals(Lifecycle.START_EVENT) || type.equals(Lifecycle.STOP_EVENT) || type.equals(Lifecycle.AFTER_DESTROY_EVENT)) { stateHistory.append(type); } }
Example #27
Source File: TomcatConfigurator.java From tagme with Apache License 2.0 | 5 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.START_EVENT.equals(event.getType())) { TagmeConfig.init(configFilePath, initialize); } }
Example #28
Source File: H2LifecycleListener.java From jwala with Apache License 2.0 | 5 votes |
@Override public synchronized void lifecycleEvent(final LifecycleEvent event) { final LifecycleState lifecycleState = event.getLifecycle().getState(); // h2 tcp server if (h2TcpServerService == null) { h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) { LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) { LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.stopServer(); } // h2 web server try { if (h2WebServerService == null) { h2WebServerService = new H2WebServerServiceImpl(webServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) { LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) { LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.stopServer(); } } catch (final DbServerServiceException e) { LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e); } }
Example #29
Source File: SecurityListener.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void lifecycleEvent(LifecycleEvent event) { // This is the earliest event in Lifecycle if (event.getType().equals(Lifecycle.BEFORE_INIT_EVENT)) { doChecks(); } }
Example #30
Source File: StandardLifecycleSupport.java From session-managers with Apache License 2.0 | 5 votes |
private void notify(LifecycleEvent lifecycleEvent) { for (LifecycleListener lifecycleListener : this.lifecycleListeners) { try { lifecycleListener.lifecycleEvent(lifecycleEvent); } catch (RuntimeException e) { this.logger.warn("Exception encountered while notifying listener of lifecycle event", e); } } }