Search in sources :

Example 36 with LifecycleException

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

the class Connector method initInternal.

@Override
protected void initInternal() throws LifecycleException {
    super.initInternal();
    if (protocolHandler == null) {
        throw new LifecycleException(sm.getString("coyoteConnector.protocolHandlerInstantiationFailed"));
    }
    // Initialize adapter
    adapter = new CoyoteAdapter(this);
    protocolHandler.setAdapter(adapter);
    if (service != null) {
        protocolHandler.setUtilityExecutor(service.getServer().getUtilityExecutor());
    }
    // Make sure parseBodyMethodsSet has a default
    if (null == parseBodyMethodsSet) {
        setParseBodyMethods(getParseBodyMethods());
    }
    if (AprStatus.isAprAvailable() && AprStatus.getUseOpenSSL() && protocolHandler instanceof AbstractHttp11JsseProtocol) {
        AbstractHttp11JsseProtocol<?> jsseProtocolHandler = (AbstractHttp11JsseProtocol<?>) protocolHandler;
        if (jsseProtocolHandler.isSSLEnabled() && jsseProtocolHandler.getSslImplementationName() == null) {
            // OpenSSL is compatible with the JSSE configuration, so use it if APR is available
            jsseProtocolHandler.setSslImplementationName(OpenSSLImplementation.class.getName());
        }
    }
    try {
        protocolHandler.init();
    } catch (Exception e) {
        throw new LifecycleException(sm.getString("coyoteConnector.protocolHandlerInitializationFailed"), e);
    }
}
Also used : AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) LifecycleException(org.apache.catalina.LifecycleException) OpenSSLImplementation(org.apache.tomcat.util.net.openssl.OpenSSLImplementation) LifecycleException(org.apache.catalina.LifecycleException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 37 with LifecycleException

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

the class NamingResourcesImpl method destroyInternal.

@Override
protected void destroyInternal() throws LifecycleException {
    // Set this before we de-register currently known naming resources to
    // avoid timing issues. Duplication de-registration is not an issue.
    resourceRequireExplicitRegistration = false;
    // Destroy in reverse order to create, although it should not matter
    for (ContextResourceLink crl : resourceLinks.values()) {
        try {
            MBeanUtils.destroyMBean(crl);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanDestroyFail", crl.getName()), e);
        }
    }
    for (ContextEnvironment ce : envs.values()) {
        try {
            MBeanUtils.destroyMBean(ce);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanDestroyFail", ce.getName()), e);
        }
    }
    for (ContextResource cr : resources.values()) {
        try {
            MBeanUtils.destroyMBean(cr);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanDestroyFail", cr.getName()), e);
        }
    }
    super.destroyInternal();
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingException(javax.naming.NamingException) LifecycleException(org.apache.catalina.LifecycleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 38 with LifecycleException

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

the class StandardPipeline method setBasic.

/**
 * <p>Set the Valve instance that has been distinguished as the basic
 * Valve for this Pipeline (if any).  Prior to setting the basic Valve,
 * the Valve's <code>setContainer()</code> will be called, if it
 * implements <code>Contained</code>, with the owning Container as an
 * argument.  The method may throw an <code>IllegalArgumentException</code>
 * if this Valve chooses not to be associated with this Container, or
 * <code>IllegalStateException</code> if it is already associated with
 * a different Container.</p>
 *
 * @param valve Valve to be distinguished as the basic Valve
 */
@Override
public void setBasic(Valve valve) {
    // Change components if necessary
    Valve oldBasic = this.basic;
    if (oldBasic == valve) {
        return;
    }
    // Stop the old component if necessary
    if (oldBasic != null) {
        if (getState().isAvailable() && (oldBasic instanceof Lifecycle)) {
            try {
                ((Lifecycle) oldBasic).stop();
            } catch (LifecycleException e) {
                log.error(sm.getString("standardPipeline.basic.stop"), e);
            }
        }
        if (oldBasic instanceof Contained) {
            try {
                ((Contained) oldBasic).setContainer(null);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
            }
        }
    }
    // Start the new component if necessary
    if (valve == null) {
        return;
    }
    if (valve instanceof Contained) {
        ((Contained) valve).setContainer(this.container);
    }
    if (getState().isAvailable() && valve instanceof Lifecycle) {
        try {
            ((Lifecycle) valve).start();
        } catch (LifecycleException e) {
            log.error(sm.getString("standardPipeline.basic.start"), e);
            return;
        }
    }
    // Update the pipeline
    Valve current = first;
    while (current != null) {
        if (current.getNext() == oldBasic) {
            current.setNext(valve);
            break;
        }
        current = current.getNext();
    }
    this.basic = valve;
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Example 39 with LifecycleException

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

the class LifecycleBase method handleSubClassException.

private void handleSubClassException(Throwable t, String key, Object... args) throws LifecycleException {
    setStateInternal(LifecycleState.FAILED, null, false);
    ExceptionUtils.handleThrowable(t);
    String msg = sm.getString(key, args);
    if (getThrowOnFailure()) {
        if (!(t instanceof LifecycleException)) {
            t = new LifecycleException(msg, t);
        }
        throw (LifecycleException) t;
    } else {
        log.error(msg, t);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException)

Example 40 with LifecycleException

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

the class LifecycleBase method destroy.

@Override
public final synchronized void destroy() throws LifecycleException {
    if (LifecycleState.FAILED.equals(state)) {
        try {
            // Triggers clean-up
            stop();
        } catch (LifecycleException e) {
            // Just log. Still want to destroy.
            log.error(sm.getString("lifecycleBase.destroyStopFail", toString()), e);
        }
    }
    if (LifecycleState.DESTROYING.equals(state) || LifecycleState.DESTROYED.equals(state)) {
        if (log.isDebugEnabled()) {
            Exception e = new LifecycleException();
            log.debug(sm.getString("lifecycleBase.alreadyDestroyed", toString()), e);
        } else if (log.isInfoEnabled() && !(this instanceof Lifecycle.SingleUse)) {
            // Rather than have every component that might need to call
            // destroy() check for SingleUse, don't log an info message if
            // multiple calls are made to destroy()
            log.info(sm.getString("lifecycleBase.alreadyDestroyed", toString()));
        }
        return;
    }
    if (!state.equals(LifecycleState.STOPPED) && !state.equals(LifecycleState.FAILED) && !state.equals(LifecycleState.NEW) && !state.equals(LifecycleState.INITIALIZED)) {
        invalidTransition(Lifecycle.BEFORE_DESTROY_EVENT);
    }
    try {
        setStateInternal(LifecycleState.DESTROYING, null, false);
        destroyInternal();
        setStateInternal(LifecycleState.DESTROYED, null, false);
    } catch (Throwable t) {
        handleSubClassException(t, "lifecycleBase.destroyFail", toString());
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException)

Aggregations

LifecycleException (org.apache.catalina.LifecycleException)128 Lifecycle (org.apache.catalina.Lifecycle)36 IOException (java.io.IOException)29 Container (org.apache.catalina.Container)19 NamingException (javax.naming.NamingException)18 File (java.io.File)17 Realm (org.apache.catalina.Realm)16 MalformedURLException (java.net.MalformedURLException)15 ServletException (javax.servlet.ServletException)12 ArrayList (java.util.ArrayList)9 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)9 Manager (org.apache.catalina.Manager)9 Valve (org.apache.catalina.Valve)9 Tomcat (org.apache.catalina.startup.Tomcat)9 Lock (java.util.concurrent.locks.Lock)8 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)8 Cluster (org.apache.catalina.Cluster)8 Loader (org.apache.catalina.Loader)8 Server (org.apache.catalina.Server)8 Contained (org.apache.catalina.Contained)7