You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/07/18 06:35:26 UTC
tomee git commit: TOMEE-1872 TOMEE-1873 wiring more options of tomee
embedded to its main and adding FatApp for fatjar which is a Main for shades
Repository: tomee
Updated Branches:
refs/heads/master 0486f3f7f -> e5b374b54
TOMEE-1872 TOMEE-1873 wiring more options of tomee embedded to its main and adding FatApp for fatjar which is a Main for shades
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e5b374b5
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e5b374b5
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e5b374b5
Branch: refs/heads/master
Commit: e5b374b54b9f287707ec961d969eb0a5422ec517
Parents: 0486f3f
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Mon Jul 18 08:34:51 2016 +0200
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Mon Jul 18 08:34:51 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/tomee/embedded/FatApp.java | 41 ++++
.../apache/tomee/embedded/LifecycleTask.java | 23 +++
.../java/org/apache/tomee/embedded/Main.java | 186 ++++++++++++++++++-
.../junit/TomEEEmbeddedSingleRunner.java | 7 +-
4 files changed, 244 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/e5b374b5/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
new file mode 100644
index 0000000..19e8bd4
--- /dev/null
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/FatApp.java
@@ -0,0 +1,41 @@
+/**
+ * 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.embedded;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static java.util.Arrays.asList;
+
+// Main like forcing --as-war --single-classloader
+// commong for fatjars
+public class FatApp {
+ public static void main(final String[] args) {
+ final Collection<String> a = args == null || args.length == 0 ? new ArrayList<String>() : new ArrayList<>(asList(args));
+ if (!a.contains("--as-war")) {
+ a.add("--as-war");
+ }
+ if (!a.contains("--single-classloader")) {
+ a.add("--single-classloader");
+ }
+ Main.main(a.toArray(new String[a.size()]));
+ }
+
+ private FatApp() {
+ // no-op
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/e5b374b5/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/LifecycleTask.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/LifecycleTask.java b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/LifecycleTask.java
new file mode 100644
index 0000000..194806b
--- /dev/null
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/LifecycleTask.java
@@ -0,0 +1,23 @@
+/*
+ * 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.embedded;
+
+import java.io.Closeable;
+
+public interface LifecycleTask {
+ Closeable beforeContainerStartup();
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/e5b374b5/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
index fef1b9a..f9cd5af 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java
@@ -5,17 +5,18 @@
* 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.
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.embedded;
+import org.apache.catalina.realm.JAASRealm;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
@@ -24,14 +25,24 @@ import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.openejb.loader.ProvisioningUtil;
+import java.io.Closeable;
import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.ServiceLoader;
import java.util.Set;
import static org.apache.openejb.loader.JarLocation.jarLocation;
+import static org.apache.openejb.util.PropertyPlaceHolderHelper.simpleValue;
public class Main {
public static final String PORT = "port";
public static final String SHUTDOWN = "shutdown";
+ public static final String HOST = "host";
public static final String PATH = "path";
public static final String CONTEXT = "context";
public static final String DIRECTORY = "directory";
@@ -42,6 +53,22 @@ public class Main {
public static final String TOMEE_XML = "tomeexml";
public static final String PROPERTY = "property";
public static final String SINGLE_CLASSLOADER = "single-classloader";
+ public static final String QUICK_SESSION = "quick-session";
+ public static final String SKIP_HTTP = "skip-http";
+ public static final String HTTPS_PORT = "https-port";
+ public static final String SSL = "ssl";
+ public static final String KEYSTORE_FILE = "keystore";
+ public static final String KEYSTORE_PASS = "keystore-pass";
+ public static final String KEYSTORE_TYPE = "keystore-type";
+ public static final String CLIENT_AUTH = "client-auth";
+ public static final String KEY_ALIAS = "key-alias";
+ public static final String SSL_PROTOCOL = "ssl-protocol";
+ public static final String WEB_XML = "web-xml";
+ public static final String JAAS_CONFIG = "jaas";
+ public static final String CACHE_WEB_RESOURCES = "cache-web-resources";
+ public static final String BASIC = "basic";
+ public static final String SIMPLE_LOG = "simple-log";
+ public static final String PRE_TASK = "pre-task";
public static void main(final String[] args) {
final CommandLineParser parser = new PosixParser();
@@ -56,6 +83,35 @@ public class Main {
return;
}
+ final Collection<Closeable> post = new ArrayList<>();
+ for (final LifecycleTask task : ServiceLoader.load(LifecycleTask.class)) {
+ final Closeable closeable = task.beforeContainerStartup();
+ if (closeable != null) {
+ post.add(closeable);
+ }
+ }
+ if (line.hasOption(PRE_TASK)) {
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ for (final String type : line.getOptionValues(PRE_TASK)) {
+ final Object task;
+ try {
+ task = loader.loadClass(type).newInstance();
+ } catch (final Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ if (Runnable.class.isInstance(task)) {
+ Runnable.class.cast(task).run();
+ } else if (LifecycleTask.class.isInstance(task)) {
+ final Closeable closeable = LifecycleTask.class.cast(task).beforeContainerStartup();
+ if (closeable != null) {
+ post.add(closeable);
+ }
+ } else {
+ throw new IllegalArgumentException(task + " can't be executed");
+ }
+ }
+ }
+
// run TomEE
try {
final Container container = new Container(createConfiguration(line));
@@ -66,7 +122,7 @@ public class Main {
contexts = null;
}
- boolean autoWar = true;
+ boolean autoWar;
if (line.hasOption(PATH)) {
int i = 0;
for (final String path : line.getOptionValues(PATH)) {
@@ -108,12 +164,29 @@ public class Main {
container.stop();
} catch (final Exception e) {
e.printStackTrace(); // just log the exception
+ } finally {
+ close(post);
}
}
});
container.await();
} catch (final Exception e) {
e.printStackTrace();
+ } finally {
+ close(post);
+ }
+ }
+
+ private static void close(final Collection<Closeable> post) {
+ synchronized (post) {
+ for (final Closeable p : post) {
+ try {
+ p.close();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+ post.clear();
}
}
@@ -137,6 +210,22 @@ public class Main {
options.addOption(null, SERVER_XML, true, "the server.xml path");
options.addOption(null, TOMEE_XML, true, "the tomee.xml path");
options.addOption(null, PROPERTY, true, "some container properties");
+ options.addOption(null, HOST, true, "server host");
+ options.addOption(null, QUICK_SESSION, true, "use a quick session - it uses Random instead of SecureRandom");
+ options.addOption(null, SKIP_HTTP, true, "should http connector be ignored");
+ options.addOption(null, HTTPS_PORT, true, "the https port if needed");
+ options.addOption(null, SSL, true, "Is https enabled");
+ options.addOption(null, KEYSTORE_FILE, true, "the https keystore");
+ options.addOption(null, KEYSTORE_PASS, true, "the https keystore password (can use cipher:xxx)");
+ options.addOption(null, KEYSTORE_TYPE, true, "the https keystore type");
+ options.addOption(null, CLIENT_AUTH, true, "is client_auth used");
+ options.addOption(null, KEY_ALIAS, true, "the https key alias");
+ options.addOption(null, SSL_PROTOCOL, true, "the https SSL protocols");
+ options.addOption(null, WEB_XML, true, "override global web.xml");
+ options.addOption(null, JAAS_CONFIG, true, "forces tomee to use JAAS with the set config");
+ options.addOption(null, CACHE_WEB_RESOURCES, true, "should web resources be cached");
+ options.addOption(null, BASIC, true, "basic authentication if set");
+ options.addOption(null, SIMPLE_LOG, true, "should tomee use simple log format (level - message) - demo intended");
return options;
}
@@ -148,9 +237,15 @@ public class Main {
if (args.hasOption(SERVER_XML)) {
config.setServerXml(args.getOptionValue(SERVER_XML));
}
+ if (args.hasOption(WEB_XML)) {
+ config.setWebXml(args.getOptionValue(WEB_XML));
+ }
if (args.hasOption(TOMEE_XML)) {
config.property("openejb.conf.file", args.getOptionValue(TOMEE_XML));
}
+ if (args.hasOption(SIMPLE_LOG) && Boolean.parseBoolean(args.getOptionValue(SIMPLE_LOG))) {
+ config.property("openejb.jul.forceReload", "true");
+ }
if (args.hasOption(PROPERTY)) {
for (final String opt : args.getOptionValues(PROPERTY)) {
final int sep = opt.indexOf('=');
@@ -161,6 +256,79 @@ public class Main {
}
}
}
+ if (args.hasOption(JAAS_CONFIG)) {
+ final String jaas = args.getOptionValue(JAAS_CONFIG);
+ final File file = new File(jaas);
+ System.setProperty("java.security.auth.login.config", file.getAbsolutePath());
+ final JAASRealm realm = new JAASRealm() {
+ @Override
+ protected javax.security.auth.login.Configuration getConfig() {
+ try {
+ if (jaasConfigurationLoaded) {
+ return jaasConfiguration;
+ }
+ synchronized (this) {
+ if (configFile == null) {
+ jaasConfigurationLoaded = true;
+ return null;
+ }
+ configFile = file.getAbsolutePath();
+ final Class<?> sunConfigFile = Class.forName("com.sun.security.auth.login.ConfigFile");
+ final Constructor<?> constructor = sunConfigFile.getConstructor(URI.class);
+ javax.security.auth.login.Configuration config = javax.security.auth.login.Configuration.class.cast(constructor.newInstance(file.toURI()));
+ this.jaasConfiguration = config;
+ this.jaasConfigurationLoaded = true;
+ return this.jaasConfiguration;
+ }
+ } catch (final NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException |
+ InstantiationException | InvocationTargetException | ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+ };
+ realm.setAppName("eyes-of-the-tiger");
+ realm.setConfigFile(new File(jaas).getAbsolutePath());
+ config.setRealm(realm);
+ }
+ if (args.hasOption(BASIC)) {
+ config.loginConfig(new LoginConfigBuilder().basic()
+ .setRealmName(System.getProperty("tomee.embedded.main.basic.realm", "Security")));
+ config.securityConstaint(new SecurityConstaintBuilder().authConstraint(true)
+ .addAuthRole(System.getProperty("tomee.embedded.main.basic.role", "*"))
+ .addCollection("Basic", System.getProperty("tomee.embedded.main.basic.pattern", "/*"))
+ .setDisplayName(System.getProperty("tomee.embedded.main.basic.display-name", "Basic security")));
+ }
+ if (args.hasOption(CACHE_WEB_RESOURCES)) {
+ config.setWebResourceCached(Boolean.parseBoolean(args.getOptionValue(CACHE_WEB_RESOURCES)));
+ }
+ if (args.hasOption(SSL_PROTOCOL)) {
+ config.setSslProtocol(args.getOptionValue(SSL_PROTOCOL));
+ }
+ if (args.hasOption(KEY_ALIAS)) {
+ config.setKeyAlias(args.getOptionValue(KEY_ALIAS));
+ }
+ if (args.hasOption(KEYSTORE_TYPE)) {
+ config.setKeystoreType(args.getOptionValue(KEYSTORE_TYPE));
+ }
+ if (args.hasOption(KEYSTORE_PASS)) {
+ config.setKeystorePass(simpleValue(args.getOptionValue(KEYSTORE_PASS)));
+ }
+ if (args.hasOption(KEYSTORE_FILE)) {
+ config.setKeystoreFile(args.getOptionValue(KEYSTORE_FILE));
+ }
+ if (args.hasOption(SSL)) {
+ config.setSsl(Boolean.parseBoolean(args.getOptionValue(SSL)));
+ }
+ if (args.hasOption(HTTPS_PORT)) {
+ config.setHttpsPort(Integer.parseInt(args.getOptionValue(HTTPS_PORT)));
+ }
+ if (args.hasOption(SKIP_HTTP)) {
+ config.setSkipHttp(Boolean.parseBoolean(args.getOptionValue(SKIP_HTTP)));
+ }
+ if (args.hasOption(QUICK_SESSION)) {
+ config.setQuickSession(Boolean.parseBoolean(args.getOptionValue(QUICK_SESSION)));
+ }
return config;
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/e5b374b5/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
index b223663..dbc04a5 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedSingleRunner.java
@@ -219,7 +219,7 @@ public class TomEEEmbeddedSingleRunner extends BlockJUnit4ClassRunner {
final Collection<Closeable> postTasks = new ArrayList<>();
final LifecycleTasks tasks = appClass.getAnnotation(LifecycleTasks.class);
if (tasks != null) {
- for (final Class<? extends LifecycleTask> type : tasks.value()) {
+ for (final Class<? extends org.apache.tomee.embedded.LifecycleTask> type : tasks.value()) {
postTasks.add(type.newInstance().beforeContainerStartup());
}
}
@@ -366,13 +366,12 @@ public class TomEEEmbeddedSingleRunner extends BlockJUnit4ClassRunner {
}
}
- public interface LifecycleTask {
- Closeable beforeContainerStartup();
+ public interface LifecycleTask extends org.apache.tomee.embedded.LifecycleTask {
}
@Retention(RUNTIME)
@Target(TYPE)
public @interface LifecycleTasks {
- Class<? extends LifecycleTask>[] value();
+ Class<? extends org.apache.tomee.embedded.LifecycleTask>[] value();
}
}