use of org.apache.catalina.core.StandardServer in project tomee by apache.
the class GlobalListenerSupport method lifecycleEvent.
/**
* {@inheritDoc}
*/
public void lifecycleEvent(final LifecycleEvent event) {
final Object source = event.getSource();
if (source instanceof StandardContext) {
final StandardContext standardContext = (StandardContext) source;
if (standardContext instanceof IgnoredStandardContext) {
return;
}
final String type = event.getType();
switch(// better than if cause it prevent duplicates
type) {
case INIT_EVENT:
case Lifecycle.BEFORE_INIT_EVENT:
contextListener.init(standardContext);
break;
case Lifecycle.BEFORE_START_EVENT:
contextListener.beforeStart(standardContext);
break;
case Lifecycle.START_EVENT:
standardContext.addParameter("openejb.start.late", "true");
contextListener.start(standardContext);
break;
case Lifecycle.AFTER_START_EVENT:
contextListener.afterStart(standardContext);
standardContext.removeParameter("openejb.start.late");
break;
case Lifecycle.BEFORE_STOP_EVENT:
contextListener.beforeStop(standardContext);
break;
case Lifecycle.STOP_EVENT:
contextListener.stop(standardContext);
break;
case Lifecycle.AFTER_STOP_EVENT:
contextListener.afterStop(standardContext);
break;
case DESTROY_EVENT:
case Lifecycle.AFTER_DESTROY_EVENT:
contextListener.destroy(standardContext);
break;
case Lifecycle.CONFIGURE_START_EVENT:
contextListener.configureStart(event, standardContext);
break;
default:
}
} else if (StandardHost.class.isInstance(source)) {
final StandardHost standardHost = (StandardHost) source;
final String type = event.getType();
if (Lifecycle.PERIODIC_EVENT.equals(type)) {
contextListener.checkHost(standardHost);
} else if (Lifecycle.AFTER_START_EVENT.equals(type) && REMOTE_SUPPORT) {
final TomEERemoteWebapp child = new TomEERemoteWebapp();
if (!hasChild(standardHost, child.getName())) {
standardHost.addChild(child);
}
// else old tomee webapp surely
}
} else if (StandardServer.class.isInstance(source)) {
final StandardServer standardServer = (StandardServer) source;
final String type = event.getType();
if (Lifecycle.START_EVENT.equals(type)) {
contextListener.start(standardServer);
}
if (Lifecycle.BEFORE_STOP_EVENT.equals(type)) {
TomcatHelper.setStopping(true);
final TomEEClusterListener tomEEClusterListener = SystemInstance.get().getComponent(TomEEClusterListener.class);
if (tomEEClusterListener != null) {
TomEEClusterListener.stop();
}
}
if (Lifecycle.AFTER_STOP_EVENT.equals(type)) {
contextListener.afterStop(standardServer);
}
}
// Notify
// here this way we are sure we get it even in embedded mode. TODO: we miss then few boot events, is it an issue.
SystemInstance.get().fireEvent(event);
}
use of org.apache.catalina.core.StandardServer in project tomee by apache.
the class ServerListener method lifecycleEvent.
public void lifecycleEvent(final LifecycleEvent event) {
if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType()) && StandardServer.class.isInstance(event.getSource())) {
installServerInfo();
}
synchronized (listenerInstalled) {
// only install once
if (listenerInstalled.get() || !Lifecycle.AFTER_INIT_EVENT.equals(event.getType())) {
return;
}
if (!(event.getSource() instanceof StandardServer)) {
return;
}
try {
final StandardServer server = (StandardServer) event.getSource();
TomcatHelper.setServer(server);
final Properties properties = new Properties();
System.getProperties().setProperty("openejb.embedder.source", getClass().getSimpleName());
properties.setProperty("openejb.embedder.source", getClass().getSimpleName());
// if SystemInstance is already initialized, then return
if (SystemInstance.isInitialized()) {
return;
}
// set the openejb.loader property to tomcat-system
properties.setProperty("openejb.loader", "tomcat-system");
// Get the value of catalina.home and set it to openejb.home
final String catalinaHome = System.getProperty("catalina.home");
properties.setProperty("openejb.home", catalinaHome);
//Sets system property for openejb.home
System.setProperty("openejb.home", catalinaHome);
//get the value of catalina.base and set it to openejb.base
final String catalinaBase = System.getProperty("catalina.base");
properties.setProperty("openejb.base", catalinaBase);
//Sets system property for openejb.base
System.setProperty("openejb.base", catalinaBase);
// System.setProperty("tomcat.version", "x.y.z.w");
// System.setProperty("tomcat.built", "mmm dd yyyy hh:mm:ss");
// set the System properties, tomcat.version, tomcat.built
final ClassLoader classLoader = ServerListener.class.getClassLoader();
try {
final Properties tomcatServerInfo = IO.readProperties(classLoader.getResourceAsStream("org/apache/catalina/util/ServerInfo.properties"), new Properties());
String serverNumber = tomcatServerInfo.getProperty("server.number");
if (serverNumber == null) {
// Tomcat5 only has server.info
final String serverInfo = tomcatServerInfo.getProperty("server.info");
if (serverInfo != null) {
final int slash = serverInfo.indexOf('/');
serverNumber = serverInfo.substring(slash + 1);
}
}
if (serverNumber != null) {
System.setProperty("tomcat.version", serverNumber);
}
final String serverBuilt = tomcatServerInfo.getProperty("server.built");
if (serverBuilt != null) {
System.setProperty("tomcat.built", serverBuilt);
}
} catch (final Throwable e) {
// no-op
}
final TomcatLoader loader = new TomcatLoader();
loader.initSystemInstance(properties);
// manage additional libraries
try {
final Collection<URL> files = new ArrayList<>();
for (final File f : ProvisioningUtil.addAdditionalLibraries()) {
files.add(f.toURI().toURL());
}
final ClassLoaderConfigurer configurer = QuickJarsTxtParser.parse(SystemInstance.get().getConf(QuickJarsTxtParser.FILE_NAME));
if (configurer != null) {
files.addAll(asList(configurer.additionalURLs()));
}
if (!files.isEmpty() && URLClassLoader.class.isInstance(classLoader)) {
final URLClassLoader ucl = URLClassLoader.class.cast(classLoader);
try {
final Method addUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
final boolean acc = addUrl.isAccessible();
try {
for (final URL url : files) {
addUrl(ucl, addUrl, url);
}
} finally {
addUrl.setAccessible(acc);
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
loader.initialize(properties);
listenerInstalled.set(true);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "TomEE Listener can't start OpenEJB", e);
// e.printStackTrace(System.err);
}
}
}
use of org.apache.catalina.core.StandardServer 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.core.StandardServer in project tomcat by apache.
the class Tomcat method getServer.
/**
* Get the server object. You can add listeners and few more
* customizations. JNDI is disabled by default.
* @return The Server
*/
public Server getServer() {
if (server != null) {
return server;
}
System.setProperty("catalina.useNaming", "false");
server = new StandardServer();
initBaseDir();
server.setPort(-1);
Service service = new StandardService();
service.setName("Tomcat");
server.addService(service);
return server;
}
use of org.apache.catalina.core.StandardServer in project tomee by apache.
the class ConfTest method run.
@Test
public void run() {
try (final Container container = new Container(new Configuration().conf("ConfTest"))) {
final StandardServer standardServer = TomcatHelper.getServer();
final Realm engineRealm = standardServer.findServices()[0].getContainer().getRealm();
assertTrue(String.valueOf(engineRealm), TomEERealm.class.isInstance(engineRealm));
assertTrue(String.valueOf(engineRealm), JAASRealm.class.isInstance(TomEERealm.class.cast(engineRealm).getNestedRealms()[0]));
final JAASRealm jaas = JAASRealm.class.cast(TomEERealm.class.cast(engineRealm).getNestedRealms()[0]);
assertEquals("PropertiesLoginModule", jaas.getAppName());
assertEquals("org.apache.openejb.core.security.jaas.UserPrincipal", jaas.getUserClassNames());
assertEquals("org.apache.openejb.core.security.jaas.GroupPrincipal", jaas.getRoleClassNames());
assertEquals("test", SystemInstance.get().getProperty("ConfTest.value"));
}
}
Aggregations