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 2015/04/04 01:05:45 UTC
tomee git commit: correct port resolution for tomee.sh (instead of
hardcoded)
Repository: tomee
Updated Branches:
refs/heads/master b07065c30 -> 69e6a614e
correct port resolution for tomee.sh (instead of hardcoded)
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/69e6a614
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/69e6a614
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/69e6a614
Branch: refs/heads/master
Commit: 69e6a614e0909f61fa11160623d06f9ba478fdff
Parents: b07065c
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Sat Apr 4 01:05:38 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Sat Apr 4 01:05:38 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/openejb/config/Deploy.java | 21 ++-
.../openejb/config/QuickServerXmlParser.java | 174 +++++++++++++++++++
.../org/apache/openejb/config/Undeploy.java | 13 +-
tomee/apache-tomee/src/main/resources/tomee.sh | 3 +-
4 files changed, 203 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/69e6a614/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java b/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
index 415f3f7..67ae90d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
@@ -44,15 +44,15 @@ import org.apache.openejb.util.JarExtractor;
import org.apache.openejb.util.Messages;
import org.apache.openejb.util.OpenEjbVersion;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.ServiceUnavailableException;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.jar.JarFile;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.ServiceUnavailableException;
import static org.apache.openejb.util.JarExtractor.delete;
@@ -136,7 +136,18 @@ public class Deploy {
final Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
- final String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
+ String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
+ if ("auto".equalsIgnoreCase(serverUrl.trim())) {
+ try {
+ final File sXml = new File(System.getProperty("openejb.base", "conf/server.xml"));
+ if (sXml.exists()) {
+ final QuickServerXmlParser result = QuickServerXmlParser.parse(sXml);
+ serverUrl = "http://" + result.host() + ":" + result.http() + "/tomee/ejb";
+ }
+ } catch (final Throwable e) {
+ // no-op
+ }
+ }
p.put(Context.PROVIDER_URL, serverUrl);
try {
http://git-wip-us.apache.org/repos/asf/tomee/blob/69e6a614/container/openejb-core/src/main/java/org/apache/openejb/config/QuickServerXmlParser.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/QuickServerXmlParser.java b/container/openejb-core/src/main/java/org/apache/openejb/config/QuickServerXmlParser.java
new file mode 100644
index 0000000..cee93f7
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/QuickServerXmlParser.java
@@ -0,0 +1,174 @@
+/*
+ * 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.openejb.config;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.util.Map;
+import java.util.TreeMap;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+public class QuickServerXmlParser extends DefaultHandler {
+ private static final SAXParserFactory FACTORY = SAXParserFactory.newInstance();
+ static {
+ FACTORY.setNamespaceAware(true);
+ FACTORY.setValidating(false);
+ }
+
+ private static final String STOP_KEY = "STOP";
+ private static final String HTTP_KEY = "HTTP";
+ private static final String SECURED_SUFFIX = "S";
+ private static final String AJP_KEY = "AJP";
+ private static final String HOST_KEY = "host";
+ private static final String APP_BASE_KEY = "app-base";
+ private static final String DEFAULT_CONNECTOR_KEY = HTTP_KEY;
+ private static final String KEYSTORE_KEY = "keystoreFile";
+
+ public static final String DEFAULT_HTTP_PORT = "8080";
+ public static final String DEFAULT_HTTPS_PORT = "8443";
+ public static final String DEFAULT_STOP_PORT = "8005";
+ public static final String DEFAULT_AJP_PORT = "8009";
+ public static final String DEFAULT_HOST = "localhost";
+ public static final String DEFAULT_APP_BASE = "webapps";
+ public static final String DEFAULT_KEYSTORE = new File(System.getProperty("user.home"), ".keystore").getAbsolutePath();
+
+ private final Map<String, String> values = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+
+ public QuickServerXmlParser() { // ensure defaults are present
+ values.put(STOP_KEY, DEFAULT_STOP_PORT);
+ values.put(HTTP_KEY, DEFAULT_HTTP_PORT);
+ values.put(AJP_KEY, DEFAULT_AJP_PORT);
+ values.put(HOST_KEY, DEFAULT_HOST);
+ values.put(APP_BASE_KEY, DEFAULT_APP_BASE);
+ values.put(KEYSTORE_KEY, DEFAULT_KEYSTORE);
+ }
+
+ @Override
+ public void startElement(final String uri, final String localName,
+ final String qName, final Attributes attributes) throws SAXException {
+ if ("Server".equalsIgnoreCase(localName)) {
+ final String port = attributes.getValue("port");
+ if (port != null) {
+ values.put(STOP_KEY, port);
+ } else {
+ values.put(STOP_KEY, DEFAULT_STOP_PORT);
+ }
+ } else if ("Connector".equalsIgnoreCase(localName)) {
+ String protocol = attributes.getValue("protocol");
+ if (protocol == null) {
+ protocol = DEFAULT_CONNECTOR_KEY;
+ } else if (protocol.contains("/")) {
+ protocol = protocol.substring(0, protocol.indexOf("/"));
+ }
+ final String port = attributes.getValue("port");
+ final String ssl = attributes.getValue("secure");
+
+ if (ssl == null || "false".equalsIgnoreCase(ssl)) {
+ values.put(protocol.toUpperCase(), port);
+ } else {
+ values.put(protocol.toUpperCase() + SECURED_SUFFIX, port);
+ }
+
+ final String keystore = attributes.getValue("keystoreFile");
+ if (null != keystore) {
+ values.put(KEYSTORE_KEY, keystore);
+ }
+ } else if ("Host".equalsIgnoreCase(localName)) {
+ final String host = attributes.getValue("name");
+ if (host != null) {
+ values.put(HOST_KEY, host);
+ }
+
+ final String appBase = attributes.getValue("appBase");
+ if (appBase != null) {
+ values.put(APP_BASE_KEY, appBase);
+ }
+ }
+ }
+
+ public static QuickServerXmlParser parse(final File serverXml) {
+ final QuickServerXmlParser handler = new QuickServerXmlParser();
+ try {
+ final SAXParser parser = FACTORY.newSAXParser();
+ parser.parse(serverXml, handler);
+ } catch (final Exception e) {
+ // no-op: using defaults
+ }
+ return handler;
+ }
+
+ public static QuickServerXmlParser parse(final String serverXmlContents) {
+ final QuickServerXmlParser handler = new QuickServerXmlParser();
+ try {
+ final SAXParser parser = FACTORY.newSAXParser();
+ parser.parse(new ByteArrayInputStream(serverXmlContents.getBytes()), handler);
+ } catch (final Exception e) {
+ // no-op: using defaults
+ }
+ return handler;
+ }
+
+ public String http() {
+ return value(HTTP_KEY, DEFAULT_HTTP_PORT);
+ }
+
+ public String https() { // enough common to be exposed as method
+ return securedValue(HTTP_KEY, DEFAULT_HTTPS_PORT);
+ }
+
+ public String ajp() {
+ return value(AJP_KEY, DEFAULT_AJP_PORT);
+ }
+
+ public String stop() {
+ return value(STOP_KEY, DEFAULT_STOP_PORT);
+ }
+
+ public String appBase() {
+ return value(APP_BASE_KEY, DEFAULT_APP_BASE);
+ }
+
+ public String host() {
+ return value(HOST_KEY, DEFAULT_HOST);
+ }
+
+ public String keystore() {
+ return value(KEYSTORE_KEY, DEFAULT_KEYSTORE);
+ }
+
+ public String value(final String key, final String defaultValue) {
+ final String val = values.get(key);
+ if (val == null) {
+ return defaultValue;
+ }
+ return val;
+ }
+
+ public String securedValue(final String key, final String defaultValue) {
+ return value(key + SECURED_SUFFIX, defaultValue);
+ }
+
+ @Override
+ public String toString() {
+ return "QuickServerXmlParser: " + values;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/69e6a614/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java b/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
index b7112bb..cfb1990 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
@@ -87,7 +87,18 @@ public class Undeploy {
final Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
- final String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
+ String serverUrl = line.getOptionValue("server-url", defaultServerUrl);
+ if ("auto".equalsIgnoreCase(serverUrl.trim())) {
+ try {
+ final File sXml = new File(System.getProperty("openejb.base", "conf/server.xml"));
+ if (sXml.exists()) {
+ final QuickServerXmlParser result = QuickServerXmlParser.parse(sXml);
+ serverUrl = "http://" + result.host() + ":" + result.http() + "/tomee/ejb";
+ }
+ } catch (final Throwable e) {
+ // no-op
+ }
+ }
p.put(Context.PROVIDER_URL, serverUrl);
Deployer deployer = null;
http://git-wip-us.apache.org/repos/asf/tomee/blob/69e6a614/tomee/apache-tomee/src/main/resources/tomee.sh
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/main/resources/tomee.sh b/tomee/apache-tomee/src/main/resources/tomee.sh
index 3ea5279..81c9098 100644
--- a/tomee/apache-tomee/src/main/resources/tomee.sh
+++ b/tomee/apache-tomee/src/main/resources/tomee.sh
@@ -16,7 +16,6 @@
# limitations under the License.
version="${version.openejb}"
-port=8080
DEBUG=
#DEBUG="-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
@@ -77,7 +76,7 @@ done
if [ "$1" = "deploy" ] || [ "$1" = "undeploy" ]; then
if [ $# -eq 2 ]; then
echo "${1}ing $2"
- $JAVA $DEBUG -Dopenejb.base="$TOMEE_HOME" -cp "\"$CP\"" org.apache.openejb.cli.Bootstrap $1 -s http://localhost:$port/tomee/ejb $2
+ $JAVA $DEBUG -Dopenejb.base="$TOMEE_HOME" -cp "\"$CP\"" org.apache.openejb.cli.Bootstrap $1 -s auto $2
else
echo "Usage: <tomee.sh> $1 <path>"
fi