Search in sources :

Example 16 with Engine

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

the class ContextConfig method getServer.

private Server getServer() {
    Container c = context;
    while (c != null && !(c instanceof Engine)) {
        c = c.getParent();
    }
    if (c == null) {
        return null;
    }
    Service s = ((Engine) c).getService();
    if (s == null) {
        return null;
    }
    return s.getServer();
}
Also used : Container(org.apache.catalina.Container) ContextService(org.apache.tomcat.util.descriptor.web.ContextService) Service(org.apache.catalina.Service) Engine(org.apache.catalina.Engine)

Example 17 with Engine

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

the class TomcatLoader method processRunningApplications.

/**
     * Process running web applications for ejb deployments.
     *
     * @param tomcatWebAppBuilder tomcat web app builder instance
     * @param standardServer      tomcat server instance
     */
private void processRunningApplications(final TomcatWebAppBuilder tomcatWebAppBuilder, final StandardServer standardServer) {
    for (final org.apache.catalina.Service service : standardServer.findServices()) {
        if (service.getContainer() instanceof Engine) {
            final Engine engine = (Engine) service.getContainer();
            for (final Container engineChild : engine.findChildren()) {
                if (engineChild instanceof Host) {
                    final Host host = (Host) engineChild;
                    for (final Container hostChild : host.findChildren()) {
                        if (hostChild instanceof StandardContext) {
                            final StandardContext standardContext = (StandardContext) hostChild;
                            final int state = TomcatHelper.getContextState(standardContext);
                            if (state == 0) {
                                // context only initialized
                                tomcatWebAppBuilder.init(standardContext);
                            } else if (state == 1) {
                                // context already started
                                standardContext.addParameter("openejb.start.late", "true");
                                final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
                                Thread.currentThread().setContextClassLoader(standardContext.getLoader().getClassLoader());
                                try {
                                    tomcatWebAppBuilder.init(standardContext);
                                    tomcatWebAppBuilder.beforeStart(standardContext);
                                    tomcatWebAppBuilder.start(standardContext);
                                    tomcatWebAppBuilder.afterStart(standardContext);
                                } finally {
                                    Thread.currentThread().setContextClassLoader(oldCL);
                                }
                                standardContext.removeParameter("openejb.start.late");
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardContext(org.apache.catalina.core.StandardContext) Host(org.apache.catalina.Host) Engine(org.apache.catalina.Engine)

Example 18 with Engine

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

the class LiveReloadInstaller method install.

public static void install(String path, final int port, final String folder) {
    final Server server = TomcatHelper.getServer();
    if (server == null) {
        throw new IllegalStateException("tomcat not yet starting");
    }
    // checking which one is localhost could be better but should be fine
    final Service service = server.findServices()[0];
    final Engine engine = Engine.class.cast(service.getContainer());
    final Container host = engine.findChild(engine.getDefaultHost());
    if (LifecycleState.STARTED != host.getState()) {
        throw new IllegalStateException("host not started, call LiveReloadInstaller.install() later.");
    }
    // add connector
    final Connector connector = new Connector();
    connector.setPort(port);
    connector.setAttribute("connectionTimeout", "30000");
    service.addConnector(connector);
    // and the endpoint and start the watcher
    final Closeable watch = Instances.get().getWatcher().watch(folder);
    final LiveReloadWebapp liveReloadWebapp = new LiveReloadWebapp(path);
    liveReloadWebapp.addApplicationLifecycleListener(new ServletContextListener() {

        @Override
        public void contextInitialized(final ServletContextEvent servletContextEvent) {
            servletContextEvent.getServletContext().log("Started livereload server on port " + port);
        }

        @Override
        public void contextDestroyed(final ServletContextEvent servletContextEvent) {
            try {
                watch.close();
            } catch (final IOException e) {
            // no-op: not that important, we shutdown anyway
            }
        }
    });
    host.addChild(liveReloadWebapp);
}
Also used : Connector(org.apache.catalina.connector.Connector) Container(org.apache.catalina.Container) Server(org.apache.catalina.Server) ServletContextListener(javax.servlet.ServletContextListener) Closeable(java.io.Closeable) Service(org.apache.catalina.Service) IOException(java.io.IOException) Engine(org.apache.catalina.Engine) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 19 with Engine

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

the class WebappDeployer method check.

private void check() {
    final StandardServer server = TomcatHelper.getServer();
    for (final Service service : server.findServices()) {
        if (service.getContainer() instanceof Engine) {
            final Engine engine = (Engine) service.getContainer();
            for (final Container engineChild : engine.findChildren()) {
                if (engineChild instanceof StandardHost) {
                    final StandardHost host = (StandardHost) engineChild;
                    webappBuilder.checkHost(host);
                }
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) StandardServer(org.apache.catalina.core.StandardServer) StandardHost(org.apache.catalina.core.StandardHost) Service(org.apache.catalina.Service) Engine(org.apache.catalina.Engine)

Example 20 with Engine

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

the class StandardContextSF method configBase.

/**
     * Return a File object representing the "configuration root" directory for
     * our associated Host.
     * @param context The context instance
     * @return a file to the configuration base path
     */
protected File configBase(Context context) {
    File file = new File(System.getProperty("catalina.base"), "conf");
    Container host = context.getParent();
    if (host instanceof Host) {
        Container engine = host.getParent();
        if (engine instanceof Engine) {
            file = new File(file, engine.getName());
        }
        file = new File(file, host.getName());
        try {
            file = file.getCanonicalFile();
        } catch (IOException e) {
            log.error(e);
        }
    }
    return (file);
}
Also used : Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) IOException(java.io.IOException) File(java.io.File) Engine(org.apache.catalina.Engine)

Aggregations

Engine (org.apache.catalina.Engine)36 Container (org.apache.catalina.Container)18 Host (org.apache.catalina.Host)18 Service (org.apache.catalina.Service)12 Context (org.apache.catalina.Context)9 StandardEngine (org.apache.catalina.core.StandardEngine)8 StandardHost (org.apache.catalina.core.StandardHost)8 StandardService (org.apache.catalina.core.StandardService)7 ObjectName (javax.management.ObjectName)6 Connector (org.apache.catalina.connector.Connector)6 File (java.io.File)5 IOException (java.io.IOException)5 StandardContext (org.apache.catalina.core.StandardContext)4 ServletContext (javax.servlet.ServletContext)2 UnavailableException (javax.servlet.UnavailableException)2 LifecycleException (org.apache.catalina.LifecycleException)2 Server (org.apache.catalina.Server)2 Wrapper (org.apache.catalina.Wrapper)2 ContextName (org.apache.catalina.util.ContextName)2 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1