Search in sources :

Example 26 with LifecycleException

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

the class LifecycleBase method init.

@Override
public final synchronized void init() throws LifecycleException {
    if (!state.equals(LifecycleState.NEW)) {
        invalidTransition(Lifecycle.BEFORE_INIT_EVENT);
    }
    try {
        setStateInternal(LifecycleState.INITIALIZING, null, false);
        initInternal();
        setStateInternal(LifecycleState.INITIALIZED, null, false);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        setStateInternal(LifecycleState.FAILED, null, false);
        throw new LifecycleException(sm.getString("lifecycleBase.initFail", toString()), t);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException)

Example 27 with LifecycleException

use of org.apache.catalina.LifecycleException in project fess by codelibs.

the class FessWebResourceRoot method processWebInfLib.

@Override
protected void processWebInfLib() throws LifecycleException {
    super.processWebInfLib();
    final WebResource[] possibleJars = listResources("/WEB-INF/plugin", false);
    for (final WebResource possibleJar : possibleJars) {
        if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
            try (final JarFile jarFile = new JarFile(possibleJar.getCanonicalPath())) {
                final Manifest manifest = jarFile.getManifest();
                if (manifest != null && manifest.getEntries() != null) {
                    final Attributes attributes = manifest.getMainAttributes();
                    if (attributes != null && (attributes.get("Fess-WebAppJar") != null || attributes.getValue("Fess-WebAppJar") != null)) {
                        createWebResourceSet(ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", possibleJar.getURL(), "/");
                    }
                }
            } catch (final Exception e) {
                logger.log(Level.WARNING, "Failed to read " + possibleJar, e);
            }
        }
    }
}
Also used : Attributes(java.util.jar.Attributes) WebResource(org.apache.catalina.WebResource) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) LifecycleException(org.apache.catalina.LifecycleException)

Example 28 with LifecycleException

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

the class TomcatWebAppBuilder method addTomEERealm.

private void addTomEERealm(final Engine engine) {
    final Realm realm = engine.getRealm();
    if (realm != null && !(realm instanceof TomEERealm) && (engine.getParent() == null || (!realm.equals(engine.getParent().getRealm())))) {
        final Realm tomeeRealm = tomeeRealm(realm);
        engine.setRealm(tomeeRealm);
        if (LifecycleState.STARTING_PREP.equals(engine.getState())) {
            try {
                Lifecycle.class.cast(tomeeRealm).start();
            } catch (final LifecycleException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) OpenEJBLifecycle(org.apache.openejb.cdi.OpenEJBLifecycle) Lifecycle(org.apache.catalina.Lifecycle) Realm(org.apache.catalina.Realm)

Example 29 with LifecycleException

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

the class LazyValve method instance.

private Valve instance() {
    if (delegate == null) {
        synchronized (this) {
            if (delegate == null) {
                final Object instance;
                ClassLoader cl = loader();
                if (cl == null) {
                    return null;
                }
                final Class<?> clazz;
                try {
                    clazz = cl.loadClass(delegateClassName);
                } catch (final ClassNotFoundException e) {
                    throw new TomEERuntimeException(e);
                }
                try {
                    final ObjectRecipe recipe = new ObjectRecipe(clazz);
                    recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
                    recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
                    recipe.allow(Option.FIELD_INJECTION);
                    recipe.allow(Option.PRIVATE_PROPERTIES);
                    if (properties != null) {
                        final Properties props = new PropertiesAdapter().unmarshal(properties.trim().replaceAll("\\p{Space}*(\\p{Alnum}*)=", "\n$1="));
                        recipe.setAllProperties(props);
                    }
                    instance = recipe.create();
                } catch (final Exception e) {
                    throw new TomEERuntimeException(e);
                }
                delegate = Valve.class.cast(instance);
                delegate.setNext(next);
                if (Contained.class.isInstance(delegate)) {
                    Contained.class.cast(delegate).setContainer(container);
                }
                if (Lifecycle.class.isInstance(delegate)) {
                    if (init) {
                        try {
                            final Lifecycle lifecycle = Lifecycle.class.cast(delegate);
                            for (final LifecycleListener listener : lifecycleListeners) {
                                lifecycle.addLifecycleListener(listener);
                            }
                            lifecycle.init();
                            if (start) {
                                lifecycle.start();
                            }
                        } catch (final LifecycleException e) {
                        // no-op
                        }
                    }
                }
                if (ClusterValve.class.isInstance(delegate)) {
                    ClusterValve.class.cast(delegate).setCluster(cluster);
                }
            }
        }
    }
    return delegate;
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) LifecycleListener(org.apache.catalina.LifecycleListener) Properties(java.util.Properties) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) LifecycleException(org.apache.catalina.LifecycleException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) ClusterValve(org.apache.catalina.ha.ClusterValve) PropertiesAdapter(org.apache.openejb.config.sys.PropertiesAdapter) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) Valve(org.apache.catalina.Valve) ClusterValve(org.apache.catalina.ha.ClusterValve)

Example 30 with LifecycleException

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

the class TomcatWebAppBuilder method destroy.

/**
 * {@inheritDoc}
 */
@Override
public void destroy(final StandardContext standardContext) {
    final Loader standardContextLoader = standardContext.getLoader();
    if (LazyStopLoader.class.isInstance(standardContextLoader)) {
        final Loader delegate = LazyStopLoader.class.cast(standardContextLoader).getDelegateLoader();
        if (TomEEWebappLoader.class.isInstance(delegate)) {
            final TomEEWebappLoader webappLoader = TomEEWebappLoader.class.cast(delegate);
            final ClassLoader loader = webappLoader.internalLoader();
            webappLoader.clearLoader();
            if (TomEEWebappClassLoader.class.isInstance(loader)) {
                TomEEWebappClassLoader.class.cast(loader).internalDestroy();
            }
        }
    }
    final WebResourceRoot root = standardContext.getResources();
    if (LazyStopStandardRoot.class.isInstance(root)) {
        try {
            LazyStopStandardRoot.class.cast(root).internalDestroy();
        } catch (final LifecycleException e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) DeploymentLoader(org.apache.openejb.config.DeploymentLoader) WebResourceRoot(org.apache.catalina.WebResourceRoot)

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