Search in sources :

Example 11 with LifecycleException

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

the class UserDatabaseRealm method startInternal.

// ------------------------------------------------------ Lifecycle Methods
/**
 * 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 {
    try {
        Context context = getServer().getGlobalNamingContext();
        database = (UserDatabase) context.lookup(resourceName);
    } catch (Throwable e) {
        ExceptionUtils.handleThrowable(e);
        containerLog.error(sm.getString("userDatabaseRealm.lookup", resourceName), e);
        database = null;
    }
    if (database == null) {
        throw new LifecycleException(sm.getString("userDatabaseRealm.noDatabase", resourceName));
    }
    super.startInternal();
}
Also used : Context(javax.naming.Context) LifecycleException(org.apache.catalina.LifecycleException)

Example 12 with LifecycleException

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

the class StandardPipeline method addValve.

/**
 * <p>Add a new Valve to the end of the pipeline associated with this
 * Container.  Prior to adding the Valve, the Valve's
 * <code>setContainer()</code> method 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 added
 *
 * @exception IllegalArgumentException if this Container refused to
 *  accept the specified Valve
 * @exception IllegalArgumentException if the specified Valve refuses to be
 *  associated with this Container
 * @exception IllegalStateException if the specified Valve is already
 *  associated with a different Container
 */
@Override
public void addValve(Valve valve) {
    // Validate that we can add this Valve
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(this.container);
    // Start the new component if necessary
    if (getState().isAvailable()) {
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.addValve: start: ", e);
            }
        }
    }
    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
        first = valve;
        valve.setNext(basic);
    } else {
        Valve current = first;
        while (current != null) {
            if (current.getNext() == basic) {
                current.setNext(valve);
                valve.setNext(basic);
                break;
            }
            current = current.getNext();
        }
    }
    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Example 13 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 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("StandardPipeline.setBasic: 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("StandardPipeline.setBasic: 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 14 with LifecycleException

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

the class ContainerMBean method addChild.

/**
 * Add a new child Container to those associated with this Container,
 * if supported. Won't start the child yet. Has to be started with a call to
 * Start method after necessary configurations are done.
 *
 * @param type ClassName of the child to be added
 * @param name Name of the child to be added
 *
 * @exception MBeanException if the child cannot be added
 */
public void addChild(String type, String name) throws MBeanException {
    Container contained = null;
    try {
        contained = (Container) Class.forName(type).newInstance();
        contained.setName(name);
        if (contained instanceof StandardHost) {
            HostConfig config = new HostConfig();
            contained.addLifecycleListener(config);
        } else if (contained instanceof StandardContext) {
            ContextConfig config = new ContextConfig();
            contained.addLifecycleListener(config);
        }
    } catch (InstantiationException e) {
        throw new MBeanException(e);
    } catch (IllegalAccessException e) {
        throw new MBeanException(e);
    } catch (ClassNotFoundException e) {
        throw new MBeanException(e);
    }
    boolean oldValue = true;
    ContainerBase container = null;
    try {
        container = (ContainerBase) getManagedResource();
        oldValue = container.getStartChildren();
        container.setStartChildren(false);
        container.addChild(contained);
        contained.init();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    } catch (LifecycleException e) {
        throw new MBeanException(e);
    } finally {
        if (container != null) {
            container.setStartChildren(oldValue);
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) LifecycleException(org.apache.catalina.LifecycleException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ContextConfig(org.apache.catalina.startup.ContextConfig) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) HostConfig(org.apache.catalina.startup.HostConfig) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 15 with LifecycleException

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

the class MemoryRealm method startInternal.

// ------------------------------------------------------ Lifecycle Methods
/**
 * 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 {
    String pathName = getPathname();
    InputStream is = null;
    try {
        is = ConfigFileLoader.getInputStream(pathName);
        // Load the contents of the database file
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("memoryRealm.loadPath", pathName));
        }
        Digester digester = getDigester();
        try {
            synchronized (digester) {
                digester.push(this);
                digester.parse(is);
            }
        } catch (Exception e) {
            throw new LifecycleException(sm.getString("memoryRealm.readXml"), e);
        } finally {
            digester.reset();
        }
    } catch (IOException ioe) {
        throw new LifecycleException(sm.getString("memoryRealm.loadExist", pathName), ioe);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
    super.startInternal();
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) InputStream(java.io.InputStream) Digester(org.apache.tomcat.util.digester.Digester) IOException(java.io.IOException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException)

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