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();
}
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");
}
}
}
}
}
}
}
}
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);
}
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);
}
}
}
}
}
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);
}
Aggregations