You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/11/07 02:27:25 UTC
[3/3] tomee git commit: Delegate RemoteServer.destroy() to usage -
Try/catch
Delegate RemoteServer.destroy() to usage - Try/catch
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/6df9839b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/6df9839b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/6df9839b
Branch: refs/heads/tomee-1.7.x
Commit: 6df9839b2804e4e3870e9797f1c01f01264a466f
Parents: e113c06
Author: AndyGee <an...@gmx.de>
Authored: Sat Nov 7 02:26:52 2015 +0100
Committer: AndyGee <an...@gmx.de>
Committed: Sat Nov 7 02:26:52 2015 +0100
----------------------------------------------------------------------
.../arquillian/remote/RemoteTomEEContainer.java | 713 ++++-----
.../arquillian/webapp/TomEEWebappContainer.java | 489 +++---
.../org/apache/openejb/config/RemoteServer.java | 1418 +++++++++---------
.../openejb/maven/plugin/AbstractTomEEMojo.java | 78 +-
.../openejb/maven/plugin/runner/ExecRunner.java | 24 +-
.../openejb/tck/impl/ContainersImplTomEE.java | 333 ++--
.../openejb/tck/impl/FullRestartContainer.java | 273 ++--
.../apache/tomee/RemoteTomEEEJBContainer.java | 315 ++--
8 files changed, 1843 insertions(+), 1800 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/6df9839b/arquillian/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java b/arquillian/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
index 15fb446..80e3173 100644
--- a/arquillian/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
+++ b/arquillian/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
@@ -1,356 +1,357 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomee.arquillian.remote;
-
-import org.apache.openejb.arquillian.common.ArquillianFilterRunner;
-import org.apache.openejb.arquillian.common.ArquillianUtil;
-import org.apache.openejb.arquillian.common.Files;
-import org.apache.openejb.arquillian.common.IO;
-import org.apache.openejb.arquillian.common.Setup;
-import org.apache.openejb.arquillian.common.TomEEContainer;
-import org.apache.openejb.assembler.Deployer;
-import org.apache.openejb.assembler.DeployerEjb;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.util.NetworkUtil;
-import org.jboss.arquillian.container.spi.client.container.LifecycleException;
-import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
-import org.jboss.shrinkwrap.api.Archive;
-
-import javax.naming.NamingException;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class RemoteTomEEContainer extends TomEEContainer<RemoteTomEEConfiguration> {
- private static final Logger logger = Logger.getLogger(RemoteTomEEContainer.class.getName());
-
- private static final String ARQUILLIAN_FILTER = "-Dorg.apache.openejb.servlet.filters=" + ArquillianFilterRunner.class.getName() + "=" + ServletMethodExecutor.ARQUILLIAN_SERVLET_MAPPING;
-
- private RemoteServer container;
- private boolean shutdown;
- private File tomeeHome;
- private Collection<Archive<?>> containerArchives;
- private final Properties deployerProperties = new Properties();
-
- @Override
- public void setup(final RemoteTomEEConfiguration configuration) {
- super.setup(configuration);
-
- if (configuration.getDeployerProperties() != null) {
- try {
- final InputStream bytes = IO.read(configuration.getDeployerProperties().getBytes());
- IO.readProperties(bytes, deployerProperties);
- } catch (final IOException e) {
- logger.log(Level.SEVERE, "Can't parse <property name=\"properties\"> value '" + configuration.getProperties() + "'", e);
- }
- }
- }
-
- @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);
- container.start(args(), "start", true);
- 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) {
- 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);
- }
- }
-
- @Override
- protected Properties getDeployerProperties() {
- if (deployerProperties.isEmpty()) {
- return null;
- }
- return deployerProperties;
- }
-
- private List<String> args() {
- String opts = configuration.getCatalina_opts();
- if (opts != null) {
- opts = opts.trim();
- }
- if (opts == null || opts.isEmpty()) {
- return Arrays.asList("-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=false", ARQUILLIAN_FILTER);
- }
-
- final List<String> splitOnSpace = new ArrayList<String>();
-
- final Iterator<String> it = new ArgsIterator(opts);
- while (it.hasNext()) {
- splitOnSpace.add(it.next());
- }
-
- if (!splitOnSpace.contains("-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true")) {
- splitOnSpace.add("-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=false");
- }
- splitOnSpace.add(ARQUILLIAN_FILTER);
- return splitOnSpace;
- }
-
- private static void resetSystemProperty(final String key, final String value) {
- if (value == null) {
- System.getProperties().remove(key);
- } else {
- System.setProperty(key, value);
- }
- }
-
- private void configure() throws LifecycleException, IOException {
- final File workingDirectory = new File(configuration.getDir()).getAbsoluteFile();
-
- if (configuration.getCleanOnStartUp()) {
- Files.delete(workingDirectory);
- }
-
- if (workingDirectory.exists()) {
-
- Files.assertDir(workingDirectory);
-
- } else {
-
- Files.mkdir(workingDirectory);
- Files.deleteOnExit(workingDirectory);
- }
-
- Files.readable(workingDirectory);
- Files.writable(workingDirectory);
-
- tomeeHome = Setup.findHome(workingDirectory);
-
- if (tomeeHome == null) {
- tomeeHome = Setup.downloadAndUnpack(workingDirectory, configuration.getArtifactName());
-
- logger.log(Level.INFO, "Downloaded container to: " + tomeeHome);
- }
-
- Files.assertDir(tomeeHome);
- Files.readable(tomeeHome);
- Files.writable(tomeeHome);
-
- Setup.synchronizeFolder(tomeeHome, configuration.getConf(), "conf");
- Setup.synchronizeFolder(tomeeHome, configuration.getBin(), "bin");
- Setup.synchronizeFolder(tomeeHome, configuration.getLib(), "lib");
- Setup.addTomEELibraries(tomeeHome, configuration.getAdditionalLibs());
-
- Setup.configureServerXml(tomeeHome, configuration);
-
- Setup.configureSystemProperties(tomeeHome, configuration);
-
- final String opts = configuration.getCatalina_opts();
-
- Setup.exportProperties(tomeeHome, configuration, opts == null || (!opts.contains("-Xm") && !opts.matches(".*-XX:[^=]*Size=.*")));
- Setup.installArquillianBeanDiscoverer(tomeeHome);
-
- if (configuration.isRemoveUnusedWebapps()) {
- Setup.removeUselessWebapps(tomeeHome);
- }
-
- if (configuration.isSimpleLog() && noLoggingConfigProvided()) {
- final File loggingProperties = Files.path(tomeeHome, "conf", "logging.properties");
-
- final Properties logging = new Properties();
- logging.put("handlers", "java.util.logging.ConsoleHandler");
- logging.put(".handlers", "java.util.logging.ConsoleHandler");
- logging.put("java.util.logging.ConsoleHandler.level", "INFO");
- logging.put("java.util.logging.ConsoleHandler.formatter", "org.apache.tomee.jul.formatter.SimpleTomEEFormatter");
-
- IO.writeProperties(loggingProperties, logging);
- }
-
- if (logger.isLoggable(Level.FINE)) {
- final Map<Object, Object> map = new TreeMap<Object, Object>(System.getProperties());
- for (final Map.Entry<Object, Object> entry : map.entrySet()) {
- logger.log(Level.FINE, String.format("%s = %s\n", entry.getKey(), entry.getValue()));
- }
- }
- }
-
- private boolean noLoggingConfigProvided() {
- if (configuration.getConf() == null) {
- return true;
- }
-
- final File conf = new File(configuration.getConf());
-
- return !(conf.exists()
- && (new File(conf, "logging.properties").exists()
- || new File(conf, "log4j.properties").exists()
- || new File(conf, "log4j.xml").exists()));
- }
-
- @Override
- public void stop() throws LifecycleException {
- ArquillianUtil.undeploy(this, containerArchives);
-
- // only stop the container if we started it
- if (shutdown) {
- Setup.removeArquillianBeanDiscoverer(tomeeHome);
- container.destroy();
- }
- }
-
- @Override
- public Class<RemoteTomEEConfiguration> getConfigurationClass() {
- return RemoteTomEEConfiguration.class;
- }
-
- @Override
- protected Deployer deployer() throws NamingException {
- try {
- return super.deployer();
- } catch (final RuntimeException ne) {
- // some debug lines
- if (Boolean.getBoolean("openejb.arquillian.debug")) {
- container.kill3UNIX();
- LOGGER.info("Can't connect to deployer through: " + providerUrl());
- try {
- LOGGER.info("Here is the server.xml:\n" + IO.slurp(new File(Setup.findHome(new File(configuration.getDir()).getAbsoluteFile()), "conf/server.xml")));
- } catch (final IOException ignored) {
- // no-op
- }
- }
- throw ne;
- }
- }
-
- private static class ArgsIterator implements Iterator<String> {
- private final String string;
- private int currentIndex;
-
- public ArgsIterator(final String opts) {
- string = opts;
- currentIndex = 0;
- }
-
- @Override
- public boolean hasNext() {
- return string != null && currentIndex < string.length();
- }
-
- @Override
- public String next() {
- skipWhiteCharacters();
-
- if (done()) {
- throw new UnsupportedOperationException("No more element");
- }
-
- final char endChar;
- if (string.charAt(currentIndex) == '"') {
- currentIndex++;
- endChar = '"';
- } else {
- endChar = ' ';
- }
-
- final int start = currentIndex;
- int end = string.indexOf(endChar, currentIndex + 1);
- if (end <= 0) {
- end = string.length();
- }
-
- currentIndex = end + 1;
-
- return string.substring(start, end);
- }
-
- private void skipWhiteCharacters() {
- while (!done() && (string.charAt(currentIndex) == ' ' || string.charAt(currentIndex) == '\t')) {
- currentIndex++;
- }
- }
-
- private boolean done() {
- return currentIndex >= string.length();
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.arquillian.remote;
+
+import org.apache.openejb.arquillian.common.ArquillianFilterRunner;
+import org.apache.openejb.arquillian.common.ArquillianUtil;
+import org.apache.openejb.arquillian.common.Files;
+import org.apache.openejb.arquillian.common.IO;
+import org.apache.openejb.arquillian.common.Setup;
+import org.apache.openejb.arquillian.common.TomEEContainer;
+import org.apache.openejb.assembler.Deployer;
+import org.apache.openejb.assembler.DeployerEjb;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.util.NetworkUtil;
+import org.jboss.arquillian.container.spi.client.container.LifecycleException;
+import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
+import org.jboss.shrinkwrap.api.Archive;
+
+import javax.naming.NamingException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class RemoteTomEEContainer extends TomEEContainer<RemoteTomEEConfiguration> {
+ private static final Logger logger = Logger.getLogger(RemoteTomEEContainer.class.getName());
+
+ private static final String ARQUILLIAN_FILTER = "-Dorg.apache.openejb.servlet.filters=" + ArquillianFilterRunner.class.getName() + "=" + ServletMethodExecutor.ARQUILLIAN_SERVLET_MAPPING;
+
+ private RemoteServer container;
+ private boolean shutdown;
+ private File tomeeHome;
+ private Collection<Archive<?>> containerArchives;
+ private final Properties deployerProperties = new Properties();
+
+ @Override
+ public void setup(final RemoteTomEEConfiguration configuration) {
+ super.setup(configuration);
+
+ if (configuration.getDeployerProperties() != null) {
+ try {
+ final InputStream bytes = IO.read(configuration.getDeployerProperties().getBytes());
+ IO.readProperties(bytes, deployerProperties);
+ } catch (final IOException e) {
+ logger.log(Level.SEVERE, "Can't parse <property name=\"properties\"> value '" + configuration.getProperties() + "'", e);
+ }
+ }
+ }
+
+ @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);
+ container.start(args(), "start", true);
+ 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) {
+ 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);
+ }
+ }
+
+ @Override
+ protected Properties getDeployerProperties() {
+ if (deployerProperties.isEmpty()) {
+ return null;
+ }
+ return deployerProperties;
+ }
+
+ private List<String> args() {
+ String opts = configuration.getCatalina_opts();
+ if (opts != null) {
+ opts = opts.trim();
+ }
+ if (opts == null || opts.isEmpty()) {
+ return Arrays.asList("-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=false", ARQUILLIAN_FILTER);
+ }
+
+ final List<String> splitOnSpace = new ArrayList<String>();
+
+ final Iterator<String> it = new ArgsIterator(opts);
+ while (it.hasNext()) {
+ splitOnSpace.add(it.next());
+ }
+
+ if (!splitOnSpace.contains("-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true")) {
+ splitOnSpace.add("-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=false");
+ }
+ splitOnSpace.add(ARQUILLIAN_FILTER);
+ return splitOnSpace;
+ }
+
+ private static void resetSystemProperty(final String key, final String value) {
+ if (value == null) {
+ System.getProperties().remove(key);
+ } else {
+ System.setProperty(key, value);
+ }
+ }
+
+ private void configure() throws LifecycleException, IOException {
+ final File workingDirectory = new File(configuration.getDir()).getAbsoluteFile();
+
+ if (configuration.getCleanOnStartUp()) {
+ Files.delete(workingDirectory);
+ }
+
+ if (workingDirectory.exists()) {
+
+ Files.assertDir(workingDirectory);
+
+ } else {
+
+ Files.mkdir(workingDirectory);
+ Files.deleteOnExit(workingDirectory);
+ }
+
+ Files.readable(workingDirectory);
+ Files.writable(workingDirectory);
+
+ tomeeHome = Setup.findHome(workingDirectory);
+
+ if (tomeeHome == null) {
+ tomeeHome = Setup.downloadAndUnpack(workingDirectory, configuration.getArtifactName());
+
+ logger.log(Level.INFO, "Downloaded container to: " + tomeeHome);
+ }
+
+ Files.assertDir(tomeeHome);
+ Files.readable(tomeeHome);
+ Files.writable(tomeeHome);
+
+ Setup.synchronizeFolder(tomeeHome, configuration.getConf(), "conf");
+ Setup.synchronizeFolder(tomeeHome, configuration.getBin(), "bin");
+ Setup.synchronizeFolder(tomeeHome, configuration.getLib(), "lib");
+ Setup.addTomEELibraries(tomeeHome, configuration.getAdditionalLibs());
+
+ Setup.configureServerXml(tomeeHome, configuration);
+
+ Setup.configureSystemProperties(tomeeHome, configuration);
+
+ final String opts = configuration.getCatalina_opts();
+
+ Setup.exportProperties(tomeeHome, configuration, opts == null || (!opts.contains("-Xm") && !opts.matches(".*-XX:[^=]*Size=.*")));
+ Setup.installArquillianBeanDiscoverer(tomeeHome);
+
+ if (configuration.isRemoveUnusedWebapps()) {
+ Setup.removeUselessWebapps(tomeeHome);
+ }
+
+ if (configuration.isSimpleLog() && noLoggingConfigProvided()) {
+ final File loggingProperties = Files.path(tomeeHome, "conf", "logging.properties");
+
+ final Properties logging = new Properties();
+ logging.put("handlers", "java.util.logging.ConsoleHandler");
+ logging.put(".handlers", "java.util.logging.ConsoleHandler");
+ logging.put("java.util.logging.ConsoleHandler.level", "INFO");
+ logging.put("java.util.logging.ConsoleHandler.formatter", "org.apache.tomee.jul.formatter.SimpleTomEEFormatter");
+
+ IO.writeProperties(loggingProperties, logging);
+ }
+
+ if (logger.isLoggable(Level.FINE)) {
+ final Map<Object, Object> map = new TreeMap<Object, Object>(System.getProperties());
+ for (final Map.Entry<Object, Object> entry : map.entrySet()) {
+ logger.log(Level.FINE, String.format("%s = %s\n", entry.getKey(), entry.getValue()));
+ }
+ }
+ }
+
+ private boolean noLoggingConfigProvided() {
+ if (configuration.getConf() == null) {
+ return true;
+ }
+
+ final File conf = new File(configuration.getConf());
+
+ return !(conf.exists()
+ && (new File(conf, "logging.properties").exists()
+ || new File(conf, "log4j.properties").exists()
+ || new File(conf, "log4j.xml").exists()));
+ }
+
+ @Override
+ public void stop() throws LifecycleException {
+ ArquillianUtil.undeploy(this, containerArchives);
+
+ // only stop the container if we started it
+ if (shutdown) {
+ Setup.removeArquillianBeanDiscoverer(tomeeHome);
+ container.destroy();
+ }
+ }
+
+ @Override
+ public Class<RemoteTomEEConfiguration> getConfigurationClass() {
+ return RemoteTomEEConfiguration.class;
+ }
+
+ @Override
+ protected Deployer deployer() throws NamingException {
+ try {
+ return super.deployer();
+ } catch (final RuntimeException ne) {
+ // some debug lines
+ if (Boolean.getBoolean("openejb.arquillian.debug")) {
+ container.kill3UNIX();
+ LOGGER.info("Can't connect to deployer through: " + providerUrl());
+ try {
+ LOGGER.info("Here is the server.xml:\n" + IO.slurp(new File(Setup.findHome(new File(configuration.getDir()).getAbsoluteFile()), "conf/server.xml")));
+ } catch (final IOException ignored) {
+ // no-op
+ }
+ }
+ throw ne;
+ }
+ }
+
+ private static class ArgsIterator implements Iterator<String> {
+ private final String string;
+ private int currentIndex;
+
+ public ArgsIterator(final String opts) {
+ string = opts;
+ currentIndex = 0;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return string != null && currentIndex < string.length();
+ }
+
+ @Override
+ public String next() {
+ skipWhiteCharacters();
+
+ if (done()) {
+ throw new UnsupportedOperationException("No more element");
+ }
+
+ final char endChar;
+ if (string.charAt(currentIndex) == '"') {
+ currentIndex++;
+ endChar = '"';
+ } else {
+ endChar = ' ';
+ }
+
+ final int start = currentIndex;
+ int end = string.indexOf(endChar, currentIndex + 1);
+ if (end <= 0) {
+ end = string.length();
+ }
+
+ currentIndex = end + 1;
+
+ return string.substring(start, end);
+ }
+
+ private void skipWhiteCharacters() {
+ while (!done() && (string.charAt(currentIndex) == ' ' || string.charAt(currentIndex) == '\t')) {
+ currentIndex++;
+ }
+ }
+
+ private boolean done() {
+ return currentIndex >= string.length();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6df9839b/arquillian/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java b/arquillian/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java
index ddd0301..3e07e81 100644
--- a/arquillian/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java
+++ b/arquillian/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java
@@ -1,241 +1,248 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomee.arquillian.webapp;
-
-import org.apache.openejb.arquillian.common.ArquillianFilterRunner;
-import org.apache.openejb.arquillian.common.Files;
-import org.apache.openejb.arquillian.common.IO;
-import org.apache.openejb.arquillian.common.Setup;
-import org.apache.openejb.arquillian.common.TomEEContainer;
-import org.apache.openejb.arquillian.common.Zips;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.tomee.installer.Installer;
-import org.apache.tomee.installer.Paths;
-import org.jboss.arquillian.container.spi.client.container.LifecycleException;
-import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/*
- * TODO: delete old embedded adapter, move the tests and set those up
- */
-public class TomEEWebappContainer extends TomEEContainer<TomEEWebappConfiguration> {
-
- private static final Logger logger = Logger.getLogger(TomEEWebappContainer.class.getName());
-
- private RemoteServer container;
- private boolean shutdown;
- private File openejbHome;
- private boolean wereOpenejbHomeSet = true;
-
- @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());
-
- openejbHome = Setup.findHome(workingDirectory);
-
- Files.deleteOnExit(openejbHome);
-
- final File webapp = new File(openejbHome, "webapps" + s + "tomee");
-
- Files.mkdir(webapp);
- downloadOpenEJBWebapp(webapp);
-
- 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<Object, Object>(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);
- tmpContainer.start();
-
- final URL url = new URL(baseUrl);
- logger.info("Calling TomEE Installer Servlet on " + url);
-
- for (int i = 0; i < 3; i++) {
- final URLConnection uc = url.openConnection();
- // dG9tZWU6dG9tZWU= --> Base64 of tomee:tomee
- final String authorizationString = "Basic dG9tZWU6dG9tZWU=";
- 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("-Dorg.apache.openejb.servlet.filters=" + ArquillianFilterRunner.class.getName() + "=" + ServletMethodExecutor.ARQUILLIAN_SERVLET_MAPPING), "start", true);
- container.killOnExit();
- } catch (final Exception e) {
- throw new LifecycleException("Unable to start remote container", e);
- }
- }
-
- private static void write(final URL resource, final File file) throws IOException {
- if (file.exists()) {
- Files.delete(file);
- }
- final InputStream is = org.apache.openejb.loader.IO.read(resource);
-
- try {
- IO.copy(is, file);
- } finally {
- is.close();
- }
- }
-
- protected void downloadOpenEJBWebapp(final File targetDirectory) throws LifecycleException {
- final String artifactName = configuration.getArtifactName();
- final File zipFile = Setup.downloadFile(artifactName, null);
- Zips.unzip(zipFile, targetDirectory);
- }
-
- protected void downloadTomcat(final File catalinaDirectory, final String tomcatVersion) throws LifecycleException {
- String source = null;
-
- if (tomcatVersion.startsWith("7.")) {
- source = "http://archive.apache.org/dist/tomcat/tomcat-7/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
- }
-
- if (tomcatVersion.startsWith("6.")) {
- source = "http://archive.apache.org/dist/tomcat/tomcat-6/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
- }
-
- if (tomcatVersion.startsWith("5.5")) {
- source = "http://archive.apache.org/dist/tomcat/tomcat-5/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
- }
-
- if (source == null) {
- throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
- }
-
- final File zipFile = Setup.downloadFile("org.apache.tomcat:tomcat:" + tomcatVersion + ":zip", source);
- Zips.unzip(zipFile, catalinaDirectory);
- }
-
- @Override
- public void stop() throws LifecycleException {
- // only stop the container if we started it
- if (shutdown) {
- Setup.removeArquillianBeanDiscoverer(openejbHome);
- container.destroy();
- }
- }
-
- @Override
- public Class<TomEEWebappConfiguration> getConfigurationClass() {
- return TomEEWebappConfiguration.class;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.arquillian.webapp;
+
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.arquillian.common.ArquillianFilterRunner;
+import org.apache.openejb.arquillian.common.Files;
+import org.apache.openejb.arquillian.common.IO;
+import org.apache.openejb.arquillian.common.Setup;
+import org.apache.openejb.arquillian.common.TomEEContainer;
+import org.apache.openejb.arquillian.common.Zips;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.tomee.installer.Installer;
+import org.apache.tomee.installer.Paths;
+import org.jboss.arquillian.container.spi.client.container.LifecycleException;
+import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/*
+ * TODO: delete old embedded adapter, move the tests and set those up
+ */
+public class TomEEWebappContainer extends TomEEContainer<TomEEWebappConfiguration> {
+
+ private static final Logger logger = Logger.getLogger(TomEEWebappContainer.class.getName());
+
+ private RemoteServer container;
+ private boolean shutdown;
+ private File openejbHome;
+ private boolean wereOpenejbHomeSet = true;
+
+ @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());
+
+ openejbHome = Setup.findHome(workingDirectory);
+
+ Files.deleteOnExit(openejbHome);
+
+ final File webapp = new File(openejbHome, "webapps" + s + "tomee");
+
+ Files.mkdir(webapp);
+ downloadOpenEJBWebapp(webapp);
+
+ 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<Object, Object>(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 < 3; i++) {
+ final URLConnection uc = url.openConnection();
+ // dG9tZWU6dG9tZWU= --> Base64 of tomee:tomee
+ final String authorizationString = "Basic dG9tZWU6dG9tZWU=";
+ 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("-Dorg.apache.openejb.servlet.filters=" + ArquillianFilterRunner.class.getName() + "=" + ServletMethodExecutor.ARQUILLIAN_SERVLET_MAPPING), "start", true);
+ container.killOnExit();
+ } catch (final Exception e) {
+ container.destroy();
+ throw new LifecycleException("Unable to start remote container", e);
+ }
+ }
+
+ private static void write(final URL resource, final File file) throws IOException {
+ if (file.exists()) {
+ Files.delete(file);
+ }
+ final InputStream is = org.apache.openejb.loader.IO.read(resource);
+
+ try {
+ IO.copy(is, file);
+ } finally {
+ is.close();
+ }
+ }
+
+ protected void downloadOpenEJBWebapp(final File targetDirectory) throws LifecycleException {
+ final String artifactName = configuration.getArtifactName();
+ final File zipFile = Setup.downloadFile(artifactName, null);
+ Zips.unzip(zipFile, targetDirectory);
+ }
+
+ protected void downloadTomcat(final File catalinaDirectory, final String tomcatVersion) throws LifecycleException {
+ String source = null;
+
+ if (tomcatVersion.startsWith("7.")) {
+ source = "http://archive.apache.org/dist/tomcat/tomcat-7/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
+ }
+
+ if (tomcatVersion.startsWith("6.")) {
+ source = "http://archive.apache.org/dist/tomcat/tomcat-6/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
+ }
+
+ if (tomcatVersion.startsWith("5.5")) {
+ source = "http://archive.apache.org/dist/tomcat/tomcat-5/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
+ }
+
+ if (source == null) {
+ throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
+ }
+
+ final File zipFile = Setup.downloadFile("org.apache.tomcat:tomcat:" + tomcatVersion + ":zip", source);
+ Zips.unzip(zipFile, catalinaDirectory);
+ }
+
+ @Override
+ public void stop() throws LifecycleException {
+ // only stop the container if we started it
+ if (shutdown) {
+ Setup.removeArquillianBeanDiscoverer(openejbHome);
+ container.destroy();
+ }
+ }
+
+ @Override
+ public Class<TomEEWebappConfiguration> getConfigurationClass() {
+ return TomEEWebappConfiguration.class;
+ }
+}