Search in sources :

Example 56 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat by apache.

the class CombinedRealm method startInternal.

/**
     * Prepare for the beginning of active use of the public methods of this
     * component and implement the requirements of
     * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected void startInternal() throws LifecycleException {
    // Start 'sub-realms' then this one
    Iterator<Realm> iter = realms.iterator();
    while (iter.hasNext()) {
        Realm realm = iter.next();
        if (realm instanceof Lifecycle) {
            try {
                ((Lifecycle) realm).start();
            } catch (LifecycleException e) {
                // If realm doesn't start can't authenticate against it
                iter.remove();
                log.error(sm.getString("combinedRealm.realmStartFail", realm.getClass().getName()), e);
            }
        }
    }
    super.startInternal();
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Realm(org.apache.catalina.Realm)

Example 57 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat by apache.

the class SetParentClassLoaderRule method stop.

/**
     * Stop an existing server instance.
     */
public void stop() {
    try {
        // doesn't get invoked twice
        if (useShutdownHook) {
            Runtime.getRuntime().removeShutdownHook(shutdownHook);
            // If JULI is being used, re-enable JULI's shutdown to ensure
            // log messages are not lost
            LogManager logManager = LogManager.getLogManager();
            if (logManager instanceof ClassLoaderLogManager) {
                ((ClassLoaderLogManager) logManager).setUseShutdownHook(true);
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    // This will fail on JDK 1.2. Ignoring, as Tomcat can run
    // fine without the shutdown hook.
    }
    // Shut down the server
    try {
        Server s = getServer();
        LifecycleState state = s.getState();
        if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0 && LifecycleState.DESTROYED.compareTo(state) >= 0) {
        // Nothing to do. stop() was already called
        } else {
            s.stop();
            s.destroy();
        }
    } catch (LifecycleException e) {
        log.error("Catalina.stop", e);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager) Server(org.apache.catalina.Server) LifecycleState(org.apache.catalina.LifecycleState) LogManager(java.util.logging.LogManager) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager)

Example 58 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat by apache.

the class WebappLoader method startInternal.

/**
     * Start associated {@link ClassLoader} and implement the requirements
     * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected void startInternal() throws LifecycleException {
    if (log.isDebugEnabled())
        log.debug(sm.getString("webappLoader.starting"));
    if (context.getResources() == null) {
        log.info("No resources for " + context);
        setState(LifecycleState.STARTING);
        return;
    }
    // Construct a class loader based on our current repositories list
    try {
        classLoader = createClassLoader();
        classLoader.setResources(context.getResources());
        classLoader.setDelegate(this.delegate);
        // Configure our repositories
        setClassPath();
        setPermissions();
        ((Lifecycle) classLoader).start();
        String contextName = context.getName();
        if (!contextName.startsWith("/")) {
            contextName = "/" + contextName;
        }
        ObjectName cloname = new ObjectName(context.getDomain() + ":type=" + classLoader.getClass().getSimpleName() + ",host=" + context.getParent().getName() + ",context=" + contextName);
        Registry.getRegistry(null, null).registerComponent(classLoader, cloname, null);
    } catch (Throwable t) {
        t = ExceptionUtils.unwrapInvocationTargetException(t);
        ExceptionUtils.handleThrowable(t);
        log.error("LifecycleException ", t);
        throw new LifecycleException("start: ", t);
    }
    setState(LifecycleState.STARTING);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) ObjectName(javax.management.ObjectName)

Example 59 with LifecycleException

use of org.apache.catalina.LifecycleException in project spring-boot by spring-projects.

the class TomcatWebServer method stop.

@Override
public void stop() throws WebServerException {
    synchronized (this.monitor) {
        boolean wasStarted = this.started;
        try {
            this.started = false;
            try {
                stopTomcat();
                this.tomcat.destroy();
            } catch (LifecycleException ex) {
            // swallow and continue
            }
        } catch (Exception ex) {
            throw new WebServerException("Unable to stop embedded Tomcat", ex);
        } finally {
            if (wasStarted) {
                containerCounter.decrementAndGet();
            }
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) WebServerException(org.springframework.boot.web.server.WebServerException) LifecycleException(org.apache.catalina.LifecycleException) WebServerException(org.springframework.boot.web.server.WebServerException) NamingException(javax.naming.NamingException)

Example 60 with LifecycleException

use of org.apache.catalina.LifecycleException in project sonarqube by SonarSource.

the class EmbeddedTomcat method start.

void start() {
    // '%2F' (slash /) and '%5C' (backslash \) are permitted as path delimiters in URLs
    System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
    System.setProperty("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true");
    tomcat = new Tomcat();
    // Initialize directories
    String basedir = tomcatBasedir().getAbsolutePath();
    tomcat.setBaseDir(basedir);
    tomcat.getHost().setAppBase(basedir);
    tomcat.getHost().setAutoDeploy(false);
    tomcat.getHost().setCreateDirs(false);
    tomcat.getHost().setDeployOnStartup(true);
    new TomcatAccessLog().configure(tomcat, props);
    TomcatConnectors.configure(tomcat, props);
    webappContext = new TomcatContexts().configure(tomcat, props);
    try {
        tomcat.start();
        new TomcatStartupLogs(Loggers.get(getClass())).log(tomcat);
    } catch (LifecycleException e) {
        Throwables.propagate(e);
    }
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) LifecycleException(org.apache.catalina.LifecycleException)

Aggregations

LifecycleException (org.apache.catalina.LifecycleException)78 Lifecycle (org.apache.catalina.Lifecycle)23 IOException (java.io.IOException)18 NamingException (javax.naming.NamingException)12 MalformedURLException (java.net.MalformedURLException)11 Container (org.apache.catalina.Container)11 File (java.io.File)10 Realm (org.apache.catalina.Realm)10 ServletException (javax.servlet.ServletException)9 ArrayList (java.util.ArrayList)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Context (org.apache.catalina.Context)5 Loader (org.apache.catalina.Loader)5 StandardManager (org.apache.catalina.session.StandardManager)5 BindException (java.net.BindException)4 Properties (java.util.Properties)4 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 Notification (javax.management.Notification)4