use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project tomee by apache.
the class TomEEWebappContainer method start.
@Override
public void start() throws LifecycleException {
// see if TomEE is already running by checking the http port
final int httpPort = configuration.getHttpPort();
if (Setup.isRunning(configuration.getHost(), httpPort)) {
logger.info(String.format("Tomcat found running on port %s", httpPort));
return;
}
shutdown = true;
final String s = File.separator;
try {
final File workingDirectory = new File(configuration.getDir());
if (workingDirectory.exists()) {
Files.assertDir(workingDirectory);
} else {
Files.mkdir(workingDirectory);
Files.deleteOnExit(workingDirectory);
}
Files.readable(workingDirectory);
Files.writable(workingDirectory);
openejbHome = Setup.findHome(workingDirectory);
Installer installer = null;
if (openejbHome == null) {
downloadTomcat(workingDirectory, configuration.getTomcatVersion(), configuration.getDir());
openejbHome = Setup.findHome(workingDirectory);
Files.deleteOnExit(openejbHome);
final File webapp = new File(openejbHome, "webapps" + s + "tomee");
Files.mkdir(webapp);
downloadOpenEJBWebapp(webapp, configuration.getDir());
System.setProperty("catalina.home", openejbHome.getAbsolutePath());
System.setProperty("catalina.base", openejbHome.getAbsolutePath());
System.setProperty("openejb.deploymentId.format", System.getProperty("openejb.deploymentId.format", "{appId}/{ejbJarId}/{ejbName}"));
final Paths paths = new Paths(webapp);
installer = new Installer(paths, true);
if (!configuration.isUseInstallerServlet()) {
installer.installAll();
}
wereOpenejbHomeSet = false;
}
Files.assertDir(openejbHome);
Files.readable(openejbHome);
Files.writable(openejbHome);
Setup.configureServerXml(openejbHome, configuration);
Setup.configureSystemProperties(openejbHome, configuration);
Setup.exportProperties(openejbHome, configuration, true);
final URL logging = Thread.currentThread().getContextClassLoader().getResource("default.remote.logging.properties");
if (logging != null) {
write(logging, new File(openejbHome, "conf" + s + "logging.properties"));
}
if (configuration.isRemoveUnusedWebapps()) {
Setup.removeUselessWebapps(openejbHome, "tomee");
}
if (logger.isLoggable(Level.FINE)) {
final Map<Object, Object> map = new TreeMap<>(System.getProperties());
for (final Map.Entry<Object, Object> entry : map.entrySet()) {
System.out.printf("%s = %s\n", entry.getKey(), entry.getValue());
}
}
Setup.installArquillianBeanDiscoverer(openejbHome);
if (!wereOpenejbHomeSet && configuration.isUseInstallerServlet()) {
// instead of calling the Installer, let's just do like users do
// call the servlet installer instead
final String baseUrl = "http://" + configuration.getHost() + ":" + httpPort + "/tomee/installer";
assert installer != null;
installer.addTomEEAdminConfInTomcatUsers(true);
final RemoteServer tmpContainer = new RemoteServer();
tmpContainer.setPortStartup(httpPort);
try {
tmpContainer.start();
} catch (final Exception e) {
tmpContainer.destroy();
throw e;
}
final URL url = new URL(baseUrl);
logger.info("Calling TomEE Installer Servlet on " + url);
for (int i = 0; i < Integer.getInteger("tomee.webapp.container.client.retries", 3); i++) {
final URLConnection uc = url.openConnection();
// dG9tZWU6dG9tZWU= --> Base64 of tomee:tomee
final String authorizationString = "Basic dG9tZWU6dG9tZWU=";
final int timeout = Integer.getInteger("tomee.webapp.container.client.timeout", 60000);
uc.setConnectTimeout(timeout);
uc.setReadTimeout(timeout);
uc.setRequestProperty("Authorization", authorizationString);
try {
final InputStream is = uc.getInputStream();
org.apache.openejb.loader.IO.slurp(is);
is.close();
break;
} catch (final Exception e) {
logger.warning(e.getMessage());
Thread.sleep(1000);
}
}
tmpContainer.stop();
tmpContainer.getServer().waitFor();
}
container = new RemoteServer();
container.setPortStartup(httpPort);
container.start(Arrays.asList("-Dopenejb.system.apps=true", "-Dtomee.remote.support=true", "-Dorg.apache.openejb.servlet.filters=" + ArquillianFilterRunner.class.getName() + "=" + ServletMethodExecutor.ARQUILLIAN_SERVLET_MAPPING), "start", true);
container.killOnExit();
} catch (final Exception e) {
if (null != container) {
container.destroy();
}
throw new LifecycleException("Unable to start remote container on port: " + httpPort, e);
}
}
Aggregations