ejbServerProps.putAll(properties);
ejbServerProps.setProperty("openejb.ejbd.uri", "http://127.0.0.1:8080/openejb/ejb");
ejbServer.init(ejbServerProps);
// Add our naming context listener to the server which registers all Tomcat resources with OpenEJB
StandardServer standardServer = TomcatHelper.getServer();
OpenEJBNamingContextListener namingContextListener = new OpenEJBNamingContextListener(standardServer);
// Standard server has no state property, so we check global naming context to determine if server is started yet
if (standardServer.getGlobalNamingContext() != null) {
namingContextListener.start();
}
standardServer.addLifecycleListener(namingContextListener);
// Process all applications already started. This deploys EJBs, PersistenceUnits
// and modifies JNDI ENC references to OpenEJB managed objects such as EJBs.
processRunningApplications(tomcatWebAppBuilder, standardServer);
if (Boolean.getBoolean("openejb.servicemanager.enabled")) {
manager = ServiceManager.getManager();
manager.init();
manager.start(false);
} else {
// WS
try {
ServerService cxfService = (ServerService) Class.forName("org.apache.openejb.server.cxf.CxfService").newInstance();
cxfService.start();
services.add(cxfService);
} catch (ClassNotFoundException ignored) {
} catch (Exception e) {
Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, getClass());
logger.error("Webservices failed to start", e);
}
// REST
try {
ServerService restService = (ServerService) Class.forName("org.apache.openejb.server.cxf.rs.CxfRSService").newInstance();
restService.start();
services.add(restService);
} catch (ClassNotFoundException ignored) {
} catch (Exception e) {
logger.error("REST failed to start", e);
}
}
standardServer.addLifecycleListener(new LifecycleListener() {
public void lifecycleEvent(LifecycleEvent event) {
String type = event.getType();
if (Lifecycle.AFTER_STOP_EVENT.equals(type)) {
TomcatLoader.this.destroy();
}