use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project tomee by apache.
the class EmbeddedTomEEContainer method start.
@Override
public void start() throws LifecycleException {
try {
this.container.start();
SystemInstance.get().setComponent(AdditionalBeanDiscoverer.class, new TestClassDiscoverer());
// this property is not mandatory by default but depending the protocol it can be relevant so adding it by default
SystemInstance.get().setProperty("org.apache.openejb.servlet.filters", ArquillianFilterRunner.class.getName() + "=/ArquillianServletRunner");
} catch (final Exception e) {
throw new LifecycleException("Something went wrong", e);
}
}
use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project tomee by apache.
the class TomEEContainer method stop.
@Override
public void stop() throws LifecycleException {
try {
final Socket socket = new Socket(configuration.getStopHost(), configuration.getStopPort());
final OutputStream out = socket.getOutputStream();
out.write((configuration.getStopCommand() + Character.toString((char) 0)).getBytes());
waitForShutdown(socket, 10);
} catch (final Exception e) {
throw new LifecycleException("Unable to stop TomEE", e);
} finally {
if (this.configuration.isUnsafeEjbd() && "-".equals(System.getProperty("tomee.serialization.class.blacklist"))) {
System.clearProperty("tomee.serialization.class.blacklist");
}
}
}
use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project tomee by apache.
the class RemoteTomEEContainer 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)) {
String host = "local";
if (!NetworkUtil.isLocalAddress(configuration.getHost())) {
// Supply at least this property so that the archive is transmitted on deploy
if (null == deployerProperties.getProperty(DeployerEjb.OPENEJB_USE_BINARIES)) {
deployerProperties.setProperty(DeployerEjb.OPENEJB_USE_BINARIES, "true");
}
host = "remote";
}
logger.info(String.format("TomEE found running on %s port %s", host, httpPort));
return;
}
shutdown = true;
final String shutdownPort = System.getProperty(RemoteServer.SERVER_SHUTDOWN_PORT);
final String shutdownHost = System.getProperty(RemoteServer.SERVER_SHUTDOWN_HOST);
final String shutdownCommand = System.getProperty(RemoteServer.SERVER_SHUTDOWN_COMMAND);
final String debug = System.getProperty(RemoteServer.OPENEJB_SERVER_DEBUG);
final String debugPort = System.getProperty(RemoteServer.SERVER_DEBUG_PORT);
try {
configure();
final int stopPort = configuration.getStopPort();
System.setProperty(RemoteServer.SERVER_SHUTDOWN_PORT, Integer.toString(stopPort));
System.setProperty(RemoteServer.SERVER_SHUTDOWN_COMMAND, configuration.getStopCommand());
System.setProperty(RemoteServer.SERVER_SHUTDOWN_HOST, configuration.getStopHost());
if (configuration.isDebug()) {
System.setProperty(RemoteServer.OPENEJB_SERVER_DEBUG, "true");
System.setProperty(RemoteServer.SERVER_DEBUG_PORT, Integer.toString(configuration.getDebugPort()));
}
container = new RemoteServer();
container.setPortStartup(httpPort);
try {
container.start(args(), "start", true);
} catch (final Exception e) {
container.destroy();
throw e;
}
container.killOnExit();
if (configuration.getProperties() != null) {
final Properties props = new Properties();
IO.readProperties(IO.read(configuration.getProperties().getBytes()), props);
containerArchives = ArquillianUtil.toDeploy(props);
for (final Archive<?> archive : containerArchives) {
deploy(archive);
}
}
} catch (final Exception e) {
if (container != null) {
container.destroy();
}
logger.log(Level.SEVERE, "Unable to start remote container", e);
throw new LifecycleException("Unable to start remote container:" + e.getMessage(), e);
} finally {
resetSystemProperty(RemoteServer.SERVER_SHUTDOWN_PORT, shutdownPort);
resetSystemProperty(RemoteServer.SERVER_SHUTDOWN_HOST, shutdownHost);
resetSystemProperty(RemoteServer.SERVER_SHUTDOWN_COMMAND, shutdownCommand);
resetSystemProperty(RemoteServer.OPENEJB_SERVER_DEBUG, debug);
resetSystemProperty(RemoteServer.SERVER_DEBUG_PORT, debugPort);
}
}
use of org.jboss.arquillian.container.spi.client.container.LifecycleException in project tomee by apache.
the class OpenEJBDeployableContainer method start.
@Override
public void start() throws LifecycleException {
try {
initialContext = new InitialContext(properties);
} catch (final NamingException e) {
throw new LifecycleException("can't start the OpenEJB container", e);
}
assembler = SystemInstance.get().getComponent(Assembler.class);
configurationFactory = (ConfigurationFactory) SystemInstance.get().getComponent(OpenEjbConfigurationFactory.class);
if ("true".equalsIgnoreCase(PROPERTIES.getProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE)) && SystemInstance.get().getComponent(WebAppBuilder.class) == null) {
SystemInstance.get().setComponent(WebAppBuilder.class, new LightweightWebAppBuilder());
}
contextProducer.set(initialContext);
containerArchives = ArquillianUtil.toDeploy(properties);
final Closeables globalScopeCloseables = new Closeables();
SystemInstance.get().setComponent(Closeables.class, globalScopeCloseables);
for (final Archive<?> archive : containerArchives) {
try {
quickDeploy(archive, testClass.get(), globalScopeCloseables);
} catch (final DeploymentException e) {
Logger.getLogger(OpenEJBDeployableContainer.class.getName()).log(Level.SEVERE, e.getMessage(), e);
}
}
}
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