Search in sources :

Example 91 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 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.getInfo()), e);
            }
        }
    }
    super.startInternal();
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Realm(org.apache.catalina.Realm)

Example 92 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 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 93 with LifecycleException

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

the class SetParentClassLoaderRule method stopServer.

public void stopServer(String[] arguments) {
    if (arguments != null) {
        arguments(arguments);
    }
    Server s = getServer();
    if (s == null) {
        // Create and execute our Digester
        Digester digester = createStopDigester();
        File file = configFile();
        FileInputStream fis = null;
        try {
            InputSource is = new InputSource(file.toURI().toURL().toString());
            fis = new FileInputStream(file);
            is.setByteStream(fis);
            digester.push(this);
            digester.parse(is);
        } catch (Exception e) {
            log.error("Catalina.stop: ", e);
            System.exit(1);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                // Ignore
                }
            }
        }
    } else {
        // Server object already present. Must be running as a service
        try {
            s.stop();
        } catch (LifecycleException e) {
            log.error("Catalina.stop: ", e);
        }
        return;
    }
    // Stop the existing server
    s = getServer();
    if (s.getPort() > 0) {
        Socket socket = null;
        OutputStream stream = null;
        try {
            socket = new Socket(s.getAddress(), s.getPort());
            stream = socket.getOutputStream();
            String shutdown = s.getShutdown();
            for (int i = 0; i < shutdown.length(); i++) {
                stream.write(shutdown.charAt(i));
            }
            stream.flush();
        } catch (ConnectException ce) {
            log.error(sm.getString("catalina.stopServer.connectException", s.getAddress(), String.valueOf(s.getPort())));
            log.error("Catalina.stop: ", ce);
            System.exit(1);
        } catch (IOException e) {
            log.error("Catalina.stop: ", e);
            System.exit(1);
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e) {
                // Ignore
                }
            }
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                // Ignore
                }
            }
        }
    } else {
        log.error(sm.getString("catalina.stopServer"));
        System.exit(1);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LifecycleException(org.apache.catalina.LifecycleException) Server(org.apache.catalina.Server) OutputStream(java.io.OutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ConnectException(java.net.ConnectException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) Digester(org.apache.tomcat.util.digester.Digester) File(java.io.File) Socket(java.net.Socket) ConnectException(java.net.ConnectException)

Example 94 with LifecycleException

use of org.apache.catalina.LifecycleException in project camunda-bpm-platform by camunda.

the class TomcatServerBootstrap method start.

public void start() {
    Properties serverProperties = readProperties();
    int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));
    tomcat = new Tomcat();
    tomcat.setPort(port);
    tomcat.setBaseDir(getWorkingDir());
    tomcat.getHost().setAppBase(getWorkingDir());
    tomcat.getHost().setAutoDeploy(true);
    tomcat.getHost().setDeployOnStartup(true);
    String contextPath = "/" + getContextPath();
    PomEquippedResolveStage resolver = Maven.configureResolver().useLegacyLocalRepo(true).workOffline().loadPomFromFile("pom.xml");
    WebArchive wa = ShrinkWrap.create(WebArchive.class, "rest-test.war").setWebXML(webXmlPath).addAsLibraries(resolver.resolve("org.codehaus.jackson:jackson-jaxrs:1.6.5").withTransitivity().asFile()).addAsLibraries(resolver.addDependencies(MavenDependencies.createDependency("org.mockito:mockito-core", ScopeType.TEST, false, MavenDependencies.createExclusion("org.hamcrest:hamcrest-core"))).resolve().withTransitivity().asFile()).addAsServiceProvider(ProcessEngineProvider.class, MockedProcessEngineProvider.class).add(new ClassLoaderAsset("runtime/tomcat/context.xml"), "META-INF/context.xml").addPackages(true, "org.camunda.bpm.engine.rest");
    addRuntimeSpecificLibraries(wa, resolver);
    wa.setWebXML(webXmlPath);
    String webAppPath = getWorkingDir() + "/" + getContextPath() + ".war";
    wa.as(ZipExporter.class).exportTo(new File(webAppPath), true);
    tomcat.addWebapp(tomcat.getHost(), contextPath, webAppPath);
    try {
        tomcat.start();
    } catch (LifecycleException e) {
        throw new RuntimeException(e);
    }
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) LifecycleException(org.apache.catalina.LifecycleException) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Properties(java.util.Properties) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) PomEquippedResolveStage(org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage) File(java.io.File)

Example 95 with LifecycleException

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

the class LazyRealm method instance.

private Realm instance() {
    if (delegate == null) {
        synchronized (this) {
            if (delegate == null) {
                final Object instance;
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                if (container != null && container.getLoader() != null && container.getLoader().getClassLoader() != null) {
                    cl = container.getLoader().getClassLoader();
                }
                final Class<?> clazz;
                try {
                    clazz = cl.loadClass(realmClass);
                } catch (final ClassNotFoundException e) {
                    throw new TomEERuntimeException(e);
                }
                if (!cdi) {
                    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);
                    }
                } else {
                    final WebBeansContext webBeansContext;
                    try {
                        webBeansContext = WebBeansContext.currentInstance();
                        if (webBeansContext == null) {
                            return null;
                        }
                    } catch (final IllegalStateException ise) {
                        // too early to have a cdi bean, skip these methods - mainly init() but @PostConstruct works then
                        return null;
                    }
                    final BeanManager bm = webBeansContext.getBeanManagerImpl();
                    final Set<Bean<?>> beans = bm.getBeans(clazz);
                    final Bean<?> bean = bm.resolve(beans);
                    if (bean == null) {
                        return null;
                    }
                    creationalContext = bm.createCreationalContext(null);
                    instance = bm.getReference(bean, clazz, creationalContext);
                }
                if (instance == null) {
                    throw new TomEERuntimeException("realm can't be retrieved from cdi");
                }
                if (instance instanceof Realm) {
                    delegate = (Realm) instance;
                    delegate.setContainer(container);
                    delegate.setCredentialHandler(credentialHandler);
                    if (Lifecycle.class.isInstance(delegate)) {
                        if (init) {
                            try {
                                final Lifecycle lifecycle = Lifecycle.class.cast(delegate);
                                lifecycle.init();
                                if (start) {
                                    lifecycle.start();
                                }
                            } catch (final LifecycleException e) {
                            // no-op
                            }
                        }
                    }
                } else {
                    delegate = new LowTypedRealm(instance);
                    delegate.setContainer(container);
                    delegate.setCredentialHandler(credentialHandler);
                }
                for (final PropertyChangeListener listener : support.getPropertyChangeListeners()) {
                    delegate.addPropertyChangeListener(listener);
                }
            }
        }
    }
    return delegate;
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) PropertyChangeListener(java.beans.PropertyChangeListener) Lifecycle(org.apache.catalina.Lifecycle) Properties(java.util.Properties) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) Bean(javax.enterprise.inject.spi.Bean) PropertiesAdapter(org.apache.openejb.config.sys.PropertiesAdapter) WebBeansContext(org.apache.webbeans.config.WebBeansContext) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) BeanManager(javax.enterprise.inject.spi.BeanManager) Realm(org.apache.catalina.Realm)

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