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/23 15:15:15 UTC
[17/25] tomee git commit: EOL
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
----------------------------------------------------------------------
diff --git a/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
index e4a71f5..9515459 100644
--- a/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
+++ b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
@@ -1,169 +1,169 @@
-/*
- * 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.tck.impl;
-
-import org.apache.openejb.assembler.Deployer;
-import org.apache.openejb.assembler.classic.AppInfo;
-import org.apache.openejb.client.RemoteInitialContextFactory;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.config.ValidationException;
-import org.apache.openejb.loader.Options;
-import org.apache.openejb.tck.OpenEJBTCKRuntimeException;
-import org.apache.openejb.tck.util.ServerLocal;
-import org.jboss.testharness.api.DeploymentException;
-import org.jboss.testharness.spi.Containers;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Properties;
-
-/**
- * @version $Rev$ $Date$
- */
-public class ContainersImplTomEE extends AbstractContainers implements Containers {
- private static int count = 0;
- private final RemoteServer server;
- private Deployer deployer = null;
- private Exception exception;
- private AppInfo appInfo;
- private File currentFile = null;
- private final int port = ServerLocal.getPort(8080);
-
- private Deployer lookup() {
- final Options options = new Options(System.getProperties());
- final Properties props = new Properties();
- props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
- props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "http://localhost:" + port + "/tomee/ejb"));
-
- final String deployerJndi = System.getProperty("openejb.deployer.jndiname", "openejb/DeployerBusinessRemote");
-
- try {
- final InitialContext context = new InitialContext(props);
- return (Deployer) context.lookup(deployerJndi);
- } catch (final Exception e) {
- throw new OpenEJBTCKRuntimeException(e);
- }
- }
-
- public ContainersImplTomEE() {
- System.out.println("ContainersImpl=" + ContainersImplTomEE.class.getName());
- System.out.println("Initialized ContainersImplTomEE " + (++count));
- server = new RemoteServer();
- server.setPortStartup(this.port);
- }
-
- @Override
- public boolean deploy(final InputStream archive, final String name) throws IOException {
- exception = null;
- appInfo = null;
-
- System.out.println("Deploying " + archive + " with name " + name);
-
- currentFile = getFile(name);
- System.out.println(currentFile);
- writeToFile(currentFile, archive);
- try {
- if (deployer == null) {
- deployer = lookup();
- }
- appInfo = deployer.deploy(currentFile.getAbsolutePath());
- } catch (final Exception ex) {
- Exception e = ex;
- if (e.getCause() instanceof ValidationException) {
- e = (Exception) e.getCause();
- }
-
- if (name.contains(".broken.")) {
- // Tests that contain the name '.broken.' are expected to fail deployment
- // This is how the TCK verifies the container is doing the required error checking
- exception = (DeploymentException) new DeploymentException("deploy failed").initCause(e);
- } else {
- // This on the other hand is not good ....
- System.out.println("FIX Deployment of " + name);
- e.printStackTrace();
- exception = e;
- }
-
- return false;
- }
- return true;
- }
-
- @Override
- public DeploymentException getDeploymentException() {
- try {
- return (DeploymentException) exception;
- } catch (final Exception e) {
- System.out.println("BADCAST");
- return new DeploymentException("", exception);
- }
- }
-
- @Override
- public void undeploy(final String name) throws IOException {
- if (appInfo == null) {
- if (!(exception instanceof DeploymentException)) {
- System.out.println("Nothing to undeploy" + name);
- }
- return;
- }
-
- System.out.println("Undeploying " + name);
- try {
- deployer.undeploy(appInfo.path);
- } catch (final Exception e) {
- e.printStackTrace();
- throw new OpenEJBTCKRuntimeException(e);
- }
-
- final File toDelete;
- if (currentFile != null && (toDelete = currentFile.getParentFile()).exists()) {
- System.out.println("deleting " + toDelete.getAbsolutePath());
- delete(toDelete);
- }
- }
-
- protected File getFile(final String name) {
- final File dir = new File(tmpDir, Math.random() + "");
- if (!dir.exists() && !dir.mkdir()) {
- throw new RuntimeException("Failed to create directory: " + dir);
- }
- dir.deleteOnExit();
- return new File(dir, name);
- }
-
- @Override
- public void setup() throws IOException {
- System.out.println("Setup called");
- try {
- server.start(Arrays.asList("-Dopenejb.classloader.forced-load=org.apache.openejb.tck"), "start", true);
- } catch (final Exception e) {
- cleanup();
- e.printStackTrace();
- }
- }
-
- @Override
- public void cleanup() throws IOException {
- System.out.println("Cleanup called");
- server.destroy();
- }
-}
+/*
+ * 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.tck.impl;
+
+import org.apache.openejb.assembler.Deployer;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.config.ValidationException;
+import org.apache.openejb.loader.Options;
+import org.apache.openejb.tck.OpenEJBTCKRuntimeException;
+import org.apache.openejb.tck.util.ServerLocal;
+import org.jboss.testharness.api.DeploymentException;
+import org.jboss.testharness.spi.Containers;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContainersImplTomEE extends AbstractContainers implements Containers {
+ private static int count = 0;
+ private final RemoteServer server;
+ private Deployer deployer = null;
+ private Exception exception;
+ private AppInfo appInfo;
+ private File currentFile = null;
+ private final int port = ServerLocal.getPort(8080);
+
+ private Deployer lookup() {
+ final Options options = new Options(System.getProperties());
+ final Properties props = new Properties();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "http://localhost:" + port + "/tomee/ejb"));
+
+ final String deployerJndi = System.getProperty("openejb.deployer.jndiname", "openejb/DeployerBusinessRemote");
+
+ try {
+ final InitialContext context = new InitialContext(props);
+ return (Deployer) context.lookup(deployerJndi);
+ } catch (final Exception e) {
+ throw new OpenEJBTCKRuntimeException(e);
+ }
+ }
+
+ public ContainersImplTomEE() {
+ System.out.println("ContainersImpl=" + ContainersImplTomEE.class.getName());
+ System.out.println("Initialized ContainersImplTomEE " + (++count));
+ server = new RemoteServer();
+ server.setPortStartup(this.port);
+ }
+
+ @Override
+ public boolean deploy(final InputStream archive, final String name) throws IOException {
+ exception = null;
+ appInfo = null;
+
+ System.out.println("Deploying " + archive + " with name " + name);
+
+ currentFile = getFile(name);
+ System.out.println(currentFile);
+ writeToFile(currentFile, archive);
+ try {
+ if (deployer == null) {
+ deployer = lookup();
+ }
+ appInfo = deployer.deploy(currentFile.getAbsolutePath());
+ } catch (final Exception ex) {
+ Exception e = ex;
+ if (e.getCause() instanceof ValidationException) {
+ e = (Exception) e.getCause();
+ }
+
+ if (name.contains(".broken.")) {
+ // Tests that contain the name '.broken.' are expected to fail deployment
+ // This is how the TCK verifies the container is doing the required error checking
+ exception = (DeploymentException) new DeploymentException("deploy failed").initCause(e);
+ } else {
+ // This on the other hand is not good ....
+ System.out.println("FIX Deployment of " + name);
+ e.printStackTrace();
+ exception = e;
+ }
+
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public DeploymentException getDeploymentException() {
+ try {
+ return (DeploymentException) exception;
+ } catch (final Exception e) {
+ System.out.println("BADCAST");
+ return new DeploymentException("", exception);
+ }
+ }
+
+ @Override
+ public void undeploy(final String name) throws IOException {
+ if (appInfo == null) {
+ if (!(exception instanceof DeploymentException)) {
+ System.out.println("Nothing to undeploy" + name);
+ }
+ return;
+ }
+
+ System.out.println("Undeploying " + name);
+ try {
+ deployer.undeploy(appInfo.path);
+ } catch (final Exception e) {
+ e.printStackTrace();
+ throw new OpenEJBTCKRuntimeException(e);
+ }
+
+ final File toDelete;
+ if (currentFile != null && (toDelete = currentFile.getParentFile()).exists()) {
+ System.out.println("deleting " + toDelete.getAbsolutePath());
+ delete(toDelete);
+ }
+ }
+
+ protected File getFile(final String name) {
+ final File dir = new File(tmpDir, Math.random() + "");
+ if (!dir.exists() && !dir.mkdir()) {
+ throw new RuntimeException("Failed to create directory: " + dir);
+ }
+ dir.deleteOnExit();
+ return new File(dir, name);
+ }
+
+ @Override
+ public void setup() throws IOException {
+ System.out.println("Setup called");
+ try {
+ server.start(Arrays.asList("-Dopenejb.classloader.forced-load=org.apache.openejb.tck"), "start", true);
+ } catch (final Exception e) {
+ cleanup();
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void cleanup() throws IOException {
+ System.out.println("Cleanup called");
+ server.destroy();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
----------------------------------------------------------------------
diff --git a/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
index f4d5cd1..7dab768 100644
--- a/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
+++ b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
@@ -1,137 +1,137 @@
-/*
- * 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.tck.impl;
-
-import org.apache.openejb.client.RemoteInitialContextFactory;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.loader.Options;
-import org.apache.openejb.tck.OpenEJBTCKRuntimeException;
-import org.apache.openejb.tck.util.ServerLocal;
-import org.apache.tomee.catalina.facade.ExceptionManagerFacade;
-import org.jboss.testharness.api.DeploymentException;
-import org.jboss.testharness.spi.Containers;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * flow:
- * - copy file
- * - start the server
- * - stop the server
- * - remove the file
- */
-public class FullRestartContainer extends AbstractContainers implements Containers {
- private static final File WEBAPP_DIR = new File(System.getProperty("openejb.home"), "webapps/");
- private static final File APPS_DIR = new File(System.getProperty("openejb.home"), "apps/");
-
- private RemoteServer server;
- private Exception exception;
- private File currentFile;
-
- public FullRestartContainer() {
- System.out.println("ContainersImpl=" + FullRestartContainer.class.getName());
- }
-
- @Override
- public DeploymentException getDeploymentException() {
- if (exception instanceof DeploymentException) {
- return (DeploymentException) exception;
- }
- System.out.println("BADCAST");
- return new DeploymentException("", exception);
- }
-
- @Override
- public boolean deploy(final InputStream archive, final String name) throws IOException {
- if (name.endsWith("war")) {
- currentFile = new File(WEBAPP_DIR, name);
- } else {
- currentFile = new File(APPS_DIR, name);
- }
-
- System.out.println(currentFile);
- writeToFile(currentFile, archive);
-
- final int port = ServerLocal.getPort(-1);
- if (port > 0) {
- server = new RemoteServer(100, true);
- server.setPortStartup(port);
- } else {
- throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system property 'server.http.port'");
- }
-
- try {
- server.start();
- } catch (final Exception e) {
- server.destroy();
- e.printStackTrace();
- throw new RuntimeException(e);
- }
-
- return (exception = lookup().exception()) == null;
- }
-
- @Override
- public void undeploy(final String name) throws IOException {
-
- if (null != server) {
- server.destroy();
- }
-
- final File folder = new File(currentFile.getParentFile(), currentFile.getName().substring(0, currentFile.getName().length() - 4));
- if (folder.exists()) {
- delete(folder);
- }
- delete(currentFile);
- }
-
- @Override
- public void setup() throws IOException {
- // no-op
- }
-
- @Override
- public void cleanup() throws IOException {
- // no-op
- }
-
- private ExceptionManagerFacade lookup() {
- final Options options = new Options(System.getProperties());
- final Properties props = new Properties();
- props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
- final int port = ServerLocal.getPort(-1);
- if (port > 0) {
- System.out.println("provider url = " + "http://localhost:" + port + "/tomee/ejb");
- props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "http://localhost:" + port + "/tomee/ejb"));
- } else {
- throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system property 'server.http.port'");
- }
-
- try {
- final InitialContext context = new InitialContext(props);
- return (ExceptionManagerFacade) context.lookup("openejb/ExceptionManagerFacadeBusinessRemote");
- } catch (final Exception e) {
- throw new OpenEJBTCKRuntimeException(e);
- }
- }
-}
+/*
+ * 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.tck.impl;
+
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.loader.Options;
+import org.apache.openejb.tck.OpenEJBTCKRuntimeException;
+import org.apache.openejb.tck.util.ServerLocal;
+import org.apache.tomee.catalina.facade.ExceptionManagerFacade;
+import org.jboss.testharness.api.DeploymentException;
+import org.jboss.testharness.spi.Containers;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * flow:
+ * - copy file
+ * - start the server
+ * - stop the server
+ * - remove the file
+ */
+public class FullRestartContainer extends AbstractContainers implements Containers {
+ private static final File WEBAPP_DIR = new File(System.getProperty("openejb.home"), "webapps/");
+ private static final File APPS_DIR = new File(System.getProperty("openejb.home"), "apps/");
+
+ private RemoteServer server;
+ private Exception exception;
+ private File currentFile;
+
+ public FullRestartContainer() {
+ System.out.println("ContainersImpl=" + FullRestartContainer.class.getName());
+ }
+
+ @Override
+ public DeploymentException getDeploymentException() {
+ if (exception instanceof DeploymentException) {
+ return (DeploymentException) exception;
+ }
+ System.out.println("BADCAST");
+ return new DeploymentException("", exception);
+ }
+
+ @Override
+ public boolean deploy(final InputStream archive, final String name) throws IOException {
+ if (name.endsWith("war")) {
+ currentFile = new File(WEBAPP_DIR, name);
+ } else {
+ currentFile = new File(APPS_DIR, name);
+ }
+
+ System.out.println(currentFile);
+ writeToFile(currentFile, archive);
+
+ final int port = ServerLocal.getPort(-1);
+ if (port > 0) {
+ server = new RemoteServer(100, true);
+ server.setPortStartup(port);
+ } else {
+ throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system property 'server.http.port'");
+ }
+
+ try {
+ server.start();
+ } catch (final Exception e) {
+ server.destroy();
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ return (exception = lookup().exception()) == null;
+ }
+
+ @Override
+ public void undeploy(final String name) throws IOException {
+
+ if (null != server) {
+ server.destroy();
+ }
+
+ final File folder = new File(currentFile.getParentFile(), currentFile.getName().substring(0, currentFile.getName().length() - 4));
+ if (folder.exists()) {
+ delete(folder);
+ }
+ delete(currentFile);
+ }
+
+ @Override
+ public void setup() throws IOException {
+ // no-op
+ }
+
+ @Override
+ public void cleanup() throws IOException {
+ // no-op
+ }
+
+ private ExceptionManagerFacade lookup() {
+ final Options options = new Options(System.getProperties());
+ final Properties props = new Properties();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ final int port = ServerLocal.getPort(-1);
+ if (port > 0) {
+ System.out.println("provider url = " + "http://localhost:" + port + "/tomee/ejb");
+ props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "http://localhost:" + port + "/tomee/ejb"));
+ } else {
+ throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system property 'server.http.port'");
+ }
+
+ try {
+ final InitialContext context = new InitialContext(props);
+ return (ExceptionManagerFacade) context.lookup("openejb/ExceptionManagerFacadeBusinessRemote");
+ } catch (final Exception e) {
+ throw new OpenEJBTCKRuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tomee/apache-tomee/src/main/resources/service.bat
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/main/resources/service.bat b/tomee/apache-tomee/src/main/resources/service.bat
index b061f3f..457b4c0 100644
--- a/tomee/apache-tomee/src/main/resources/service.bat
+++ b/tomee/apache-tomee/src/main/resources/service.bat
@@ -1,226 +1,226 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one or more
-rem contributor license agreements. See the NOTICE file distributed with
-rem this work for additional information regarding copyright ownership.
-rem The ASF licenses this file to You under the Apache License, Version 2.0
-rem (the "License"); you may not use this file except in compliance with
-rem the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-rem The following line can be used to define a specific jre or jdk path
-rem set "JAVA_HOME=C:/JDK"
-
-REM Prefer a local JRE if we find one in the current bin directory
-IF EXIST "%~dp0jre" (
- SET "JRE_HOME=%~dp0jre"
-)
-
-REM Prefer a local JDK if we find one in the current bin directory
-IF EXIST "%~dp0jdk" (
- SET "JAVA_HOME=%~dp0jdk"
-)
-
-@IF NOT "%ECHO%" == "" ECHO %ECHO%
-@IF "%OS%" == "Windows_NT" setlocal
-
-IF "%OS%" == "Windows_NT" (
- SET "DIRNAME=%~dp0%"
-) ELSE (
- SET DIRNAME=.\
-)
-
-pushd %DIRNAME%
-
-rem ---------------------------------------------------------------------------
-rem NT Service Install/Uninstall script
-rem
-rem Options
-rem install Install the service using TomEE as service name.
-rem Service is installed using default settings.
-rem remove Remove the service from the System.
-rem
-rem name (optional) If the second argument is present it is considered
-rem to be new service name
-rem
-rem $Id: service.bat 1000718 2010-09-24 06:00:00Z mturk $
-rem ---------------------------------------------------------------------------
-
-SET proc=undefined
-
-IF /i %PROCESSOR_ARCHITECTURE% EQU X86 SET "proc=%~dp0TomEE.x86.exe"
-IF /i %PROCESSOR_ARCHITECTURE% EQU AMD64 SET "proc=%~dp0TomEE.amd64.exe"
-IF /i %PROCESSOR_ARCHITECTURE% EQU IA64 SET "proc=%~dp0TomEE.ia64.exe"
-
-IF /i "%proc%" EQU undefined (
- ECHO Failed to determine OS architecture
- GOTO end
-)
-
-set "SELF=%~dp0%service.bat"
-rem Guess CATALINA_HOME if not defined
-set "CURRENT_DIR=%cd%"
-if not "%CATALINA_HOME%" == "" goto gotHome
-set "CATALINA_HOME=%cd%"
-if exist "%CATALINA_HOME%\bin\service.bat" goto okHome
-rem CD to the upper dir
-cd ..
-set "CATALINA_HOME=%cd%"
-:gotHome
-if exist "%CATALINA_HOME%\bin\service.bat" goto okHome
-echo The service exe was not found...
-echo The CATALINA_HOME environment variable is not defined correctly.
-echo This environment variable is needed to run this program
-goto end
-:okHome
-rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJdkHome
-if not "%JRE_HOME%" == "" goto gotJreHome
-echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
-echo Service will try to guess them from the registry.
-goto okJavaHome
-:gotJreHome
-if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
-if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
-goto okJavaHome
-:gotJdkHome
-if not exist "%JAVA_HOME%\jre\bin\java.exe" goto noJavaHome
-if not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
-if not "%JRE_HOME%" == "" goto okJavaHome
-set "JRE_HOME=%JAVA_HOME%\jre"
-goto okJavaHome
-:noJavaHome
-echo The JAVA_HOME environment variable is not defined correctly
-echo This environment variable is needed to run this program
-echo NB: JAVA_HOME should point to a JDK not a JRE
-goto end
-:okJavaHome
-if not "%CATALINA_BASE%" == "" goto gotBase
-set "CATALINA_BASE=%CATALINA_HOME%"
-:gotBase
-
-set "EXECUTABLE=%proc%"
-
-rem Set default Service name (If you change this then rename also TomEE.exe to the same name)
-set SERVICE_NAME=TomEE
-set PR_DISPLAYNAME=Apache TomEE
-
-if "x%1x" == "xx" goto displayUsage
-set SERVICE_CMD=%1
-shift
-if "x%1x" == "xx" goto checkServiceCmd
-:checkUser
-if "x%1x" == "x/userx" goto runAsUser
-if "x%1x" == "x--userx" goto runAsUser
-set SERVICE_NAME=%1
-set PR_DISPLAYNAME=Apache TomEE (%1)
-shift
-if "x%1x" == "xx" goto checkServiceCmd
-goto checkUser
-:runAsUser
-shift
-if "x%1x" == "xx" goto displayUsage
-set SERVICE_USER=%1
-shift
-runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
-goto end
-:checkServiceCmd
-if /i %SERVICE_CMD% == install goto doInstall
-if /i %SERVICE_CMD% == remove goto doRemove
-if /i %SERVICE_CMD% == uninstall goto doRemove
-echo Unknown parameter "%1"
-:displayUsage
-echo.
-echo Usage: service.bat install/remove [service_name] [/user username]
-goto end
-
-:doRemove
-rem Remove the service
-"%EXECUTABLE%" //DS//%SERVICE_NAME%
-if not errorlevel 1 goto removed
-echo Failed removing '%SERVICE_NAME%' service
-goto end
-:removed
-echo The service '%SERVICE_NAME%' has been removed
-goto end
-
-:doInstall
-rem Install the service
-echo Installing the service '%SERVICE_NAME%' ...
-echo Using CATALINA_HOME: "%CATALINA_HOME%"
-echo Using CATALINA_BASE: "%CATALINA_BASE%"
-echo Using JAVA_HOME: "%JAVA_HOME%"
-echo Using JRE_HOME: "%JRE_HOME%"
-
-rem Use the environment variables as an example
-rem Each command line option is prefixed with PR_
-
-set "PR_DESCRIPTION=Apache TomEE - http://tomee.apache.org/"
-set "PR_INSTALL=%EXECUTABLE%"
-set "PR_LOGPATH=%CATALINA_BASE%\logs"
-set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
-rem Set the server jvm from JAVA_HOME
-set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
-if exist "%PR_JVM%" goto foundJvm
-rem Set the client jvm from JAVA_HOME
-set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
-if exist "%PR_JVM%" goto foundJvm
-set PR_JVM=auto
-:foundJvm
-echo Using JVM: "%PR_JVM%"
-
-"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
- --DisplayName=%SERVICE_NAME% ^
- --StartClass org.apache.catalina.startup.Bootstrap ^
- --StopClass org.apache.catalina.startup.Bootstrap ^
- --StartParams start ^
- --StopParams stop ^
- --Startup auto ^
- --JvmMs=512 ^
- --JvmMx=1024 ^
- --JvmSs=2048 ^
- --StartMode jvm ^
- --StopMode jvm ^
- --LogLevel Info ^
- --LogPrefix TomEE
-
-echo Installed, will now configure TomEE
-
-if not errorlevel 1 goto installed
-echo Failed installing '%SERVICE_NAME%' service
-goto end
-
-:installed
-rem Clear the environment variables. They are not needed any more.
-set PR_DISPLAYNAME=
-set PR_DESCRIPTION=
-set PR_INSTALL=
-set PR_LOGPATH=
-set PR_CLASSPATH=
-set PR_JVM=
-
-rem Set extra parameters
-"%EXECUTABLE%" //US//%SERVICE_NAME% ^
- ++JvmOptions "-javaagent:%CATALINA_HOME%\lib\openejb-javaagent.jar;-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed"
-
-rem More extra parameters
-set "PR_LOGPATH=%CATALINA_BASE%\logs"
-set PR_STDOUTPUT=auto
-set PR_STDERROR=auto
-
-rem before this option was added: "++JvmOptions=-Djava.library.path="%CATALINA_BASE%\bin" ^"
-rem the drawback was it was preventing custom native lib to be loaded even if added to Path
-"%EXECUTABLE%" //US//%SERVICE_NAME% ^
- ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;-Djava.awt.headless=true;-XX:+UseParallelGC;-XX:MaxPermSize=256M"
-
-echo The service '%SERVICE_NAME%' has been installed.
-
-:end
-cd "%CURRENT_DIR%"
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements. See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License. You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+rem The following line can be used to define a specific jre or jdk path
+rem set "JAVA_HOME=C:/JDK"
+
+REM Prefer a local JRE if we find one in the current bin directory
+IF EXIST "%~dp0jre" (
+ SET "JRE_HOME=%~dp0jre"
+)
+
+REM Prefer a local JDK if we find one in the current bin directory
+IF EXIST "%~dp0jdk" (
+ SET "JAVA_HOME=%~dp0jdk"
+)
+
+@IF NOT "%ECHO%" == "" ECHO %ECHO%
+@IF "%OS%" == "Windows_NT" setlocal
+
+IF "%OS%" == "Windows_NT" (
+ SET "DIRNAME=%~dp0%"
+) ELSE (
+ SET DIRNAME=.\
+)
+
+pushd %DIRNAME%
+
+rem ---------------------------------------------------------------------------
+rem NT Service Install/Uninstall script
+rem
+rem Options
+rem install Install the service using TomEE as service name.
+rem Service is installed using default settings.
+rem remove Remove the service from the System.
+rem
+rem name (optional) If the second argument is present it is considered
+rem to be new service name
+rem
+rem $Id: service.bat 1000718 2010-09-24 06:00:00Z mturk $
+rem ---------------------------------------------------------------------------
+
+SET proc=undefined
+
+IF /i %PROCESSOR_ARCHITECTURE% EQU X86 SET "proc=%~dp0TomEE.x86.exe"
+IF /i %PROCESSOR_ARCHITECTURE% EQU AMD64 SET "proc=%~dp0TomEE.amd64.exe"
+IF /i %PROCESSOR_ARCHITECTURE% EQU IA64 SET "proc=%~dp0TomEE.ia64.exe"
+
+IF /i "%proc%" EQU undefined (
+ ECHO Failed to determine OS architecture
+ GOTO end
+)
+
+set "SELF=%~dp0%service.bat"
+rem Guess CATALINA_HOME if not defined
+set "CURRENT_DIR=%cd%"
+if not "%CATALINA_HOME%" == "" goto gotHome
+set "CATALINA_HOME=%cd%"
+if exist "%CATALINA_HOME%\bin\service.bat" goto okHome
+rem CD to the upper dir
+cd ..
+set "CATALINA_HOME=%cd%"
+:gotHome
+if exist "%CATALINA_HOME%\bin\service.bat" goto okHome
+echo The service exe was not found...
+echo The CATALINA_HOME environment variable is not defined correctly.
+echo This environment variable is needed to run this program
+goto end
+:okHome
+rem Make sure prerequisite environment variables are set
+if not "%JAVA_HOME%" == "" goto gotJdkHome
+if not "%JRE_HOME%" == "" goto gotJreHome
+echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
+echo Service will try to guess them from the registry.
+goto okJavaHome
+:gotJreHome
+if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
+if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
+goto okJavaHome
+:gotJdkHome
+if not exist "%JAVA_HOME%\jre\bin\java.exe" goto noJavaHome
+if not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHome
+if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
+if not "%JRE_HOME%" == "" goto okJavaHome
+set "JRE_HOME=%JAVA_HOME%\jre"
+goto okJavaHome
+:noJavaHome
+echo The JAVA_HOME environment variable is not defined correctly
+echo This environment variable is needed to run this program
+echo NB: JAVA_HOME should point to a JDK not a JRE
+goto end
+:okJavaHome
+if not "%CATALINA_BASE%" == "" goto gotBase
+set "CATALINA_BASE=%CATALINA_HOME%"
+:gotBase
+
+set "EXECUTABLE=%proc%"
+
+rem Set default Service name (If you change this then rename also TomEE.exe to the same name)
+set SERVICE_NAME=TomEE
+set PR_DISPLAYNAME=Apache TomEE
+
+if "x%1x" == "xx" goto displayUsage
+set SERVICE_CMD=%1
+shift
+if "x%1x" == "xx" goto checkServiceCmd
+:checkUser
+if "x%1x" == "x/userx" goto runAsUser
+if "x%1x" == "x--userx" goto runAsUser
+set SERVICE_NAME=%1
+set PR_DISPLAYNAME=Apache TomEE (%1)
+shift
+if "x%1x" == "xx" goto checkServiceCmd
+goto checkUser
+:runAsUser
+shift
+if "x%1x" == "xx" goto displayUsage
+set SERVICE_USER=%1
+shift
+runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
+goto end
+:checkServiceCmd
+if /i %SERVICE_CMD% == install goto doInstall
+if /i %SERVICE_CMD% == remove goto doRemove
+if /i %SERVICE_CMD% == uninstall goto doRemove
+echo Unknown parameter "%1"
+:displayUsage
+echo.
+echo Usage: service.bat install/remove [service_name] [/user username]
+goto end
+
+:doRemove
+rem Remove the service
+"%EXECUTABLE%" //DS//%SERVICE_NAME%
+if not errorlevel 1 goto removed
+echo Failed removing '%SERVICE_NAME%' service
+goto end
+:removed
+echo The service '%SERVICE_NAME%' has been removed
+goto end
+
+:doInstall
+rem Install the service
+echo Installing the service '%SERVICE_NAME%' ...
+echo Using CATALINA_HOME: "%CATALINA_HOME%"
+echo Using CATALINA_BASE: "%CATALINA_BASE%"
+echo Using JAVA_HOME: "%JAVA_HOME%"
+echo Using JRE_HOME: "%JRE_HOME%"
+
+rem Use the environment variables as an example
+rem Each command line option is prefixed with PR_
+
+set "PR_DESCRIPTION=Apache TomEE - http://tomee.apache.org/"
+set "PR_INSTALL=%EXECUTABLE%"
+set "PR_LOGPATH=%CATALINA_BASE%\logs"
+set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
+rem Set the server jvm from JAVA_HOME
+set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
+if exist "%PR_JVM%" goto foundJvm
+rem Set the client jvm from JAVA_HOME
+set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
+if exist "%PR_JVM%" goto foundJvm
+set PR_JVM=auto
+:foundJvm
+echo Using JVM: "%PR_JVM%"
+
+"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
+ --DisplayName=%SERVICE_NAME% ^
+ --StartClass org.apache.catalina.startup.Bootstrap ^
+ --StopClass org.apache.catalina.startup.Bootstrap ^
+ --StartParams start ^
+ --StopParams stop ^
+ --Startup auto ^
+ --JvmMs=512 ^
+ --JvmMx=1024 ^
+ --JvmSs=2048 ^
+ --StartMode jvm ^
+ --StopMode jvm ^
+ --LogLevel Info ^
+ --LogPrefix TomEE
+
+echo Installed, will now configure TomEE
+
+if not errorlevel 1 goto installed
+echo Failed installing '%SERVICE_NAME%' service
+goto end
+
+:installed
+rem Clear the environment variables. They are not needed any more.
+set PR_DISPLAYNAME=
+set PR_DESCRIPTION=
+set PR_INSTALL=
+set PR_LOGPATH=
+set PR_CLASSPATH=
+set PR_JVM=
+
+rem Set extra parameters
+"%EXECUTABLE%" //US//%SERVICE_NAME% ^
+ ++JvmOptions "-javaagent:%CATALINA_HOME%\lib\openejb-javaagent.jar;-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed"
+
+rem More extra parameters
+set "PR_LOGPATH=%CATALINA_BASE%\logs"
+set PR_STDOUTPUT=auto
+set PR_STDERROR=auto
+
+rem before this option was added: "++JvmOptions=-Djava.library.path="%CATALINA_BASE%\bin" ^"
+rem the drawback was it was preventing custom native lib to be loaded even if added to Path
+"%EXECUTABLE%" //US//%SERVICE_NAME% ^
+ ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;-Djava.awt.headless=true;-XX:+UseParallelGC;-XX:MaxPermSize=256M"
+
+echo The service '%SERVICE_NAME%' has been installed.
+
+:end
+cd "%CURRENT_DIR%"
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tomee/apache-tomee/src/main/resources/tomee.bat
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/main/resources/tomee.bat b/tomee/apache-tomee/src/main/resources/tomee.bat
index a945bbd..6c6045e 100644
--- a/tomee/apache-tomee/src/main/resources/tomee.bat
+++ b/tomee/apache-tomee/src/main/resources/tomee.bat
@@ -1,85 +1,85 @@
-@echo off
-rem Licensed to the Apache Software Foundation (ASF) under one or more
-rem contributor license agreements. See the NOTICE file distributed with
-rem this work for additional information regarding copyright ownership.
-rem The ASF licenses this file to You under the Apache License, Version 2.0
-rem (the "License"); you may not use this file except in compliance with
-rem the License. You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-if "%OS%" == "Windows_NT" setlocal
-
-set port=8080
-
-rem Guess CATALINA_HOME if not defined
-set "CURRENT_DIR=%cd%"
-if not "%CATALINA_HOME%" == "" goto gotHome
-set "CATALINA_HOME=%CURRENT_DIR%"
-if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
-cd ..
-set "CATALINA_HOME=%cd%"
-cd "%CURRENT_DIR%"
-:gotHome
-
-if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
-echo The CATALINA_HOME environment variable is not defined correctly
-echo This environment variable is needed to run this program
-goto end
-:okHome
-
-rem Copy CATALINA_BASE from CATALINA_HOME if not defined
-if not "%CATALINA_BASE%" == "" goto gotBase
-set "CATALINA_BASE=%CATALINA_HOME%"
-:gotBase
-
-rem Ensure that any user defined CLASSPATH variables are not used on startup,
-rem but allow them to be specified in setenv.bat, in rare case when it is needed.
-set CLASSPATH=
-
-rem Get standard Java environment variables
-if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
-echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
-echo This file is needed to run this program
-goto end
-:okSetclasspath
-call "%CATALINA_HOME%\bin\setclasspath.bat" %1
-if errorlevel 1 goto end
-
-
-if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
-set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
-:gotTmpdir
-
-
-rem create classpath
-setlocal enabledelayedexpansion
-
-set cp="%CATALINA_HOME%\bin\tomcat-juli.jar"
-set lib="%CATALINA_HOME%\lib\"
-echo %lib%
-for %%F in (%lib%/*.jar) do (
- set cp=!cp!;%%F%
-)
-
-if ""%1"" == ""deploy"" goto doDeploy
-if ""%1"" == ""undeploy"" goto doUndeploy
-goto doExec
-
-:doDeploy
-:doUndeploy
-%_RUNJAVA% -cp "%cp%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" org.apache.openejb.cli.Bootstrap %1 -s http://localhost:%port%/tomee/ejb %2
-goto end
-
-:doExec
-%_RUNJAVA% -cp "%cp%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" org.apache.openejb.cli.Bootstrap %*
-goto end
-
-:end
-
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements. See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License. You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+if "%OS%" == "Windows_NT" setlocal
+
+set port=8080
+
+rem Guess CATALINA_HOME if not defined
+set "CURRENT_DIR=%cd%"
+if not "%CATALINA_HOME%" == "" goto gotHome
+set "CATALINA_HOME=%CURRENT_DIR%"
+if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
+cd ..
+set "CATALINA_HOME=%cd%"
+cd "%CURRENT_DIR%"
+:gotHome
+
+if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
+echo The CATALINA_HOME environment variable is not defined correctly
+echo This environment variable is needed to run this program
+goto end
+:okHome
+
+rem Copy CATALINA_BASE from CATALINA_HOME if not defined
+if not "%CATALINA_BASE%" == "" goto gotBase
+set "CATALINA_BASE=%CATALINA_HOME%"
+:gotBase
+
+rem Ensure that any user defined CLASSPATH variables are not used on startup,
+rem but allow them to be specified in setenv.bat, in rare case when it is needed.
+set CLASSPATH=
+
+rem Get standard Java environment variables
+if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
+echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"
+echo This file is needed to run this program
+goto end
+:okSetclasspath
+call "%CATALINA_HOME%\bin\setclasspath.bat" %1
+if errorlevel 1 goto end
+
+
+if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
+set "CATALINA_TMPDIR=%CATALINA_BASE%\temp"
+:gotTmpdir
+
+
+rem create classpath
+setlocal enabledelayedexpansion
+
+set cp="%CATALINA_HOME%\bin\tomcat-juli.jar"
+set lib="%CATALINA_HOME%\lib\"
+echo %lib%
+for %%F in (%lib%/*.jar) do (
+ set cp=!cp!;%%F%
+)
+
+if ""%1"" == ""deploy"" goto doDeploy
+if ""%1"" == ""undeploy"" goto doUndeploy
+goto doExec
+
+:doDeploy
+:doUndeploy
+%_RUNJAVA% -cp "%cp%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" org.apache.openejb.cli.Bootstrap %1 -s http://localhost:%port%/tomee/ejb %2
+goto end
+
+:doExec
+%_RUNJAVA% -cp "%cp%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" org.apache.openejb.cli.Bootstrap %*
+goto end
+
+:end
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/Contexts.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/Contexts.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/Contexts.java
index 78434d0..dd8a6b1 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/Contexts.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/Contexts.java
@@ -1,148 +1,148 @@
-/*
- * 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.catalina;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Context;
-import org.apache.catalina.Globals;
-import org.apache.catalina.Host;
-import org.apache.catalina.core.StandardContext;
-import org.apache.catalina.core.StandardEngine;
-import org.apache.catalina.core.StandardHost;
-import org.apache.catalina.util.ContextName;
-
-import java.io.File;
-
-public class Contexts {
- public static String getHostname(final StandardContext ctx) {
- String hostName = null;
- final Container parentHost = ctx.getParent();
- if (parentHost != null) {
- hostName = parentHost.getName();
- }
- if ((hostName == null) || (hostName.length() < 1)) {
- hostName = "_";
- }
- return hostName;
- }
-
- public static File warPath(final Context standardContext) {
- final File file = realWarPath(standardContext);
- if (file == null) {
- return null;
- }
-
- final String name = file.getName();
- if (!file.isDirectory() && name.endsWith(".war")) {
- final File extracted = new File(file.getParentFile(), name.substring(0, name.length() - ".war".length()));
- if (extracted.exists()) {
- return extracted;
- }
- }
- return file;
- }
-
- public static File realWarPath(final Context standardContext) {
- if (standardContext == null) {
- return null;
- }
-
- final File docBase;
- Container container = standardContext;
- while (container != null) {
- if (container instanceof Host) {
- break;
- }
- container = container.getParent();
- }
-
- if (standardContext.getDocBase() != null) {
- File file = new File(standardContext.getDocBase());
- if (!file.isAbsolute()) {
- if (container == null) {
- docBase = new File(engineBase(standardContext), standardContext.getDocBase());
- } else {
- final String appBase = ((Host) container).getAppBase();
- file = new File(appBase);
- if (!file.isAbsolute()) {
- file = new File(engineBase(standardContext), appBase);
- }
- docBase = new File(file, standardContext.getDocBase());
- }
- } else {
- docBase = file;
- }
- } else {
- final String path = standardContext.getPath();
- if (path == null) {
- throw new IllegalStateException("Can't find docBase");
- } else {
- docBase = new File(new ContextName(path, standardContext.getWebappVersion()).getBaseName());
- }
- }
-
- if (!docBase.exists()) { // for old compatibility, will be removed soon
- return oldRealWarPath(standardContext);
- }
-
- final String name = docBase.getName();
- if (name.endsWith(".war")) {
- final File extracted = new File(docBase.getParentFile(), name.substring(0, name.length() - ".war".length()));
- if (extracted.exists()) {
- return extracted;
- }
- }
-
- return docBase;
- }
-
- private static File engineBase(final Context standardContext) {
- String base=System.getProperty(Globals.CATALINA_BASE_PROP);
- if( base == null ) {
- final StandardEngine eng = (StandardEngine) standardContext.getParent().getParent();
- base = eng.getBaseDir();
- }
- return new File(base);
- }
-
- @Deprecated
- private static File oldRealWarPath(final Context standardContext) {
- String doc = standardContext.getDocBase();
- // handle ROOT case
- if (doc == null || doc.length() == 0) {
- doc = "ROOT";
- }
-
- File war = new File(doc);
- if (war.exists()) {
- return war;
- }
-
- final StandardHost host = (StandardHost) standardContext.getParent();
- final String base = host.getAppBase();
- war = new File(base, doc);
- if (war.exists()) {
- return war;
- }
-
- war = new File(new File(System.getProperty("catalina.home"), base), doc);
- if (war.exists()) {
- return war;
- }
- return new File(new File(System.getProperty("catalina.base"), base), doc); // shouldn't occur
- }
-}
+/*
+ * 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.catalina;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.Globals;
+import org.apache.catalina.Host;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.util.ContextName;
+
+import java.io.File;
+
+public class Contexts {
+ public static String getHostname(final StandardContext ctx) {
+ String hostName = null;
+ final Container parentHost = ctx.getParent();
+ if (parentHost != null) {
+ hostName = parentHost.getName();
+ }
+ if ((hostName == null) || (hostName.length() < 1)) {
+ hostName = "_";
+ }
+ return hostName;
+ }
+
+ public static File warPath(final Context standardContext) {
+ final File file = realWarPath(standardContext);
+ if (file == null) {
+ return null;
+ }
+
+ final String name = file.getName();
+ if (!file.isDirectory() && name.endsWith(".war")) {
+ final File extracted = new File(file.getParentFile(), name.substring(0, name.length() - ".war".length()));
+ if (extracted.exists()) {
+ return extracted;
+ }
+ }
+ return file;
+ }
+
+ public static File realWarPath(final Context standardContext) {
+ if (standardContext == null) {
+ return null;
+ }
+
+ final File docBase;
+ Container container = standardContext;
+ while (container != null) {
+ if (container instanceof Host) {
+ break;
+ }
+ container = container.getParent();
+ }
+
+ if (standardContext.getDocBase() != null) {
+ File file = new File(standardContext.getDocBase());
+ if (!file.isAbsolute()) {
+ if (container == null) {
+ docBase = new File(engineBase(standardContext), standardContext.getDocBase());
+ } else {
+ final String appBase = ((Host) container).getAppBase();
+ file = new File(appBase);
+ if (!file.isAbsolute()) {
+ file = new File(engineBase(standardContext), appBase);
+ }
+ docBase = new File(file, standardContext.getDocBase());
+ }
+ } else {
+ docBase = file;
+ }
+ } else {
+ final String path = standardContext.getPath();
+ if (path == null) {
+ throw new IllegalStateException("Can't find docBase");
+ } else {
+ docBase = new File(new ContextName(path, standardContext.getWebappVersion()).getBaseName());
+ }
+ }
+
+ if (!docBase.exists()) { // for old compatibility, will be removed soon
+ return oldRealWarPath(standardContext);
+ }
+
+ final String name = docBase.getName();
+ if (name.endsWith(".war")) {
+ final File extracted = new File(docBase.getParentFile(), name.substring(0, name.length() - ".war".length()));
+ if (extracted.exists()) {
+ return extracted;
+ }
+ }
+
+ return docBase;
+ }
+
+ private static File engineBase(final Context standardContext) {
+ String base=System.getProperty(Globals.CATALINA_BASE_PROP);
+ if( base == null ) {
+ final StandardEngine eng = (StandardEngine) standardContext.getParent().getParent();
+ base = eng.getBaseDir();
+ }
+ return new File(base);
+ }
+
+ @Deprecated
+ private static File oldRealWarPath(final Context standardContext) {
+ String doc = standardContext.getDocBase();
+ // handle ROOT case
+ if (doc == null || doc.length() == 0) {
+ doc = "ROOT";
+ }
+
+ File war = new File(doc);
+ if (war.exists()) {
+ return war;
+ }
+
+ final StandardHost host = (StandardHost) standardContext.getParent();
+ final String base = host.getAppBase();
+ war = new File(base, doc);
+ if (war.exists()) {
+ return war;
+ }
+
+ war = new File(new File(System.getProperty("catalina.home"), base), doc);
+ if (war.exists()) {
+ return war;
+ }
+ return new File(new File(System.getProperty("catalina.base"), base), doc); // shouldn't occur
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ProvisioningWebappLoader.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ProvisioningWebappLoader.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ProvisioningWebappLoader.java
index 1357bcc..ab6fc11 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ProvisioningWebappLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ProvisioningWebappLoader.java
@@ -1,119 +1,119 @@
-/*
- * 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.catalina;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.loader.VirtualWebappLoader;
-import org.apache.openejb.ClassLoaderUtil;
-import org.apache.openejb.classloader.ClassLoaderConfigurer;
-import org.apache.openejb.classloader.CompositeClassLoaderConfigurer;
-import org.apache.openejb.config.QuickJarsTxtParser;
-import org.apache.openejb.loader.ProvisioningUtil;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.util.reflection.Reflections;
-
-import java.io.File;
-
-/**
- * Usage example in META-INF/context.xml
- * <p/>
- * <p/>
- * <Context antiJARLocking="true" >
- * <Loader
- * className="org.apache.tomee.catalina.ProvisioningWebappLoader"
- * searchExternalFirst="true"
- * virtualClasspath="mvn:commons-el:commons-el:1.0;mvn:commons-el:commons-el:1.0"
- * searchVirtualFirst="true"
- * />
- * </Context>
- */
-public class ProvisioningWebappLoader extends VirtualWebappLoader {
- public static final boolean SKIP_BACKGROUND_PROCESS = "true".equals(SystemInstance.get().getProperty("tomee.classloader.skip-background-process", "false"));
-
- @Override
- public void backgroundProcess() {
- if (SKIP_BACKGROUND_PROCESS) {
- return;
- }
-
- final ClassLoader classloader = super.getClassLoader();
- if (classloader instanceof LazyStopWebappClassLoader) {
- final LazyStopWebappClassLoader lazyStopWebappClassLoader = (LazyStopWebappClassLoader) classloader;
- lazyStopWebappClassLoader.restarting();
- try {
- super.backgroundProcess();
- } finally {
- lazyStopWebappClassLoader.restarted();
- }
- } else {
- super.backgroundProcess();
- }
- }
-
- @Override
- public boolean modified() {
- if (SKIP_BACKGROUND_PROCESS) {
- return false;
- }
- return super.modified();
- }
-
- @Override
- protected void startInternal() throws LifecycleException {
- // standard tomcat part
- final StringBuilder builder = new StringBuilder();
- final String classpath = String.class.cast(Reflections.get(this, "virtualClasspath"));
- if (classpath != null && !classpath.isEmpty()) {
- for (final String s : String.class.cast(classpath).split(";")) {
- builder.append(ProvisioningUtil.realLocation(s)).append(";");
- }
- }
-
- ClassLoaderConfigurer configurer = ClassLoaderUtil.configurer(getContainer().getName());
-
- // WEB-INF/jars.xml
- if (Context.class.isInstance(getContainer())) {
- final File war = Contexts.warPath(Context.class.cast(getContainer()));
- final File jarsXml = new File(war, "WEB-INF/" + QuickJarsTxtParser.FILE_NAME);
- final ClassLoaderConfigurer configurerTxt = QuickJarsTxtParser.parse(jarsXml);
- if (configurerTxt != null) {
- configurer = new CompositeClassLoaderConfigurer(configurer, configurerTxt);
- }
- }
-
- // clean up builder and set classpath to delegate to parent init
- String cp = builder.toString();
- if (cp.endsWith(";")) {
- cp = cp.substring(0, cp.length() - 1);
- }
- Reflections.set(this, "virtualClasspath", cp);
-
- LazyStopWebappClassLoader.initContext(configurer);
- LazyStopWebappClassLoader.initContext(Context.class.cast(getContainer()));
- try {
- super.startInternal();
- } finally {
- LazyStopWebappClassLoader.cleanContext();
- }
- }
-
- @Override
- public String toString() {
- return "Provisioning" + super.toString();
- }
-}
+/*
+ * 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.catalina;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.loader.VirtualWebappLoader;
+import org.apache.openejb.ClassLoaderUtil;
+import org.apache.openejb.classloader.ClassLoaderConfigurer;
+import org.apache.openejb.classloader.CompositeClassLoaderConfigurer;
+import org.apache.openejb.config.QuickJarsTxtParser;
+import org.apache.openejb.loader.ProvisioningUtil;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.reflection.Reflections;
+
+import java.io.File;
+
+/**
+ * Usage example in META-INF/context.xml
+ * <p/>
+ * <p/>
+ * <Context antiJARLocking="true" >
+ * <Loader
+ * className="org.apache.tomee.catalina.ProvisioningWebappLoader"
+ * searchExternalFirst="true"
+ * virtualClasspath="mvn:commons-el:commons-el:1.0;mvn:commons-el:commons-el:1.0"
+ * searchVirtualFirst="true"
+ * />
+ * </Context>
+ */
+public class ProvisioningWebappLoader extends VirtualWebappLoader {
+ public static final boolean SKIP_BACKGROUND_PROCESS = "true".equals(SystemInstance.get().getProperty("tomee.classloader.skip-background-process", "false"));
+
+ @Override
+ public void backgroundProcess() {
+ if (SKIP_BACKGROUND_PROCESS) {
+ return;
+ }
+
+ final ClassLoader classloader = super.getClassLoader();
+ if (classloader instanceof LazyStopWebappClassLoader) {
+ final LazyStopWebappClassLoader lazyStopWebappClassLoader = (LazyStopWebappClassLoader) classloader;
+ lazyStopWebappClassLoader.restarting();
+ try {
+ super.backgroundProcess();
+ } finally {
+ lazyStopWebappClassLoader.restarted();
+ }
+ } else {
+ super.backgroundProcess();
+ }
+ }
+
+ @Override
+ public boolean modified() {
+ if (SKIP_BACKGROUND_PROCESS) {
+ return false;
+ }
+ return super.modified();
+ }
+
+ @Override
+ protected void startInternal() throws LifecycleException {
+ // standard tomcat part
+ final StringBuilder builder = new StringBuilder();
+ final String classpath = String.class.cast(Reflections.get(this, "virtualClasspath"));
+ if (classpath != null && !classpath.isEmpty()) {
+ for (final String s : String.class.cast(classpath).split(";")) {
+ builder.append(ProvisioningUtil.realLocation(s)).append(";");
+ }
+ }
+
+ ClassLoaderConfigurer configurer = ClassLoaderUtil.configurer(getContainer().getName());
+
+ // WEB-INF/jars.xml
+ if (Context.class.isInstance(getContainer())) {
+ final File war = Contexts.warPath(Context.class.cast(getContainer()));
+ final File jarsXml = new File(war, "WEB-INF/" + QuickJarsTxtParser.FILE_NAME);
+ final ClassLoaderConfigurer configurerTxt = QuickJarsTxtParser.parse(jarsXml);
+ if (configurerTxt != null) {
+ configurer = new CompositeClassLoaderConfigurer(configurer, configurerTxt);
+ }
+ }
+
+ // clean up builder and set classpath to delegate to parent init
+ String cp = builder.toString();
+ if (cp.endsWith(";")) {
+ cp = cp.substring(0, cp.length() - 1);
+ }
+ Reflections.set(this, "virtualClasspath", cp);
+
+ LazyStopWebappClassLoader.initContext(configurer);
+ LazyStopWebappClassLoader.initContext(Context.class.cast(getContainer()));
+ try {
+ super.startInternal();
+ } finally {
+ LazyStopWebappClassLoader.cleanContext();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Provisioning" + super.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5dd70c83/tomee/tomee-common/src/main/java/org/apache/tomee/common/NamingUtil.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-common/src/main/java/org/apache/tomee/common/NamingUtil.java b/tomee/tomee-common/src/main/java/org/apache/tomee/common/NamingUtil.java
index 0bdceff..b452c3e 100644
--- a/tomee/tomee-common/src/main/java/org/apache/tomee/common/NamingUtil.java
+++ b/tomee/tomee-common/src/main/java/org/apache/tomee/common/NamingUtil.java
@@ -1,149 +1,149 @@
-/**
- *
- * 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.common;
-
-import org.apache.catalina.core.StandardContext;
-import org.apache.naming.EjbRef;
-
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-public class NamingUtil {
- public static final String NAME = "name";
- public static final String DEPLOYMENT_ID = "deploymentid";
- public static final String EXTERNAL = "external";
- public static final String LOCAL = "local";
- public static final String LOCALBEAN = "localbean";
- public static final String REMOTE = EjbRef.REMOTE;
- public static final String JNDI_NAME = "jndiname";
- public static final String JNDI_PROVIDER_ID = "jndiproviderid";
- public static final String UNIT = "unit";
- public static final String EXTENDED = "extended";
- public static final String PROPERTIES = "properties";
- public static final String RESOURCE_ID = "resourceid";
- public static final String COMPONENT_TYPE = "componenttype";
- public static final String WS_ID = "wsid";
- public static final String WS_CLASS = "wsclass";
- public static final String WS_QNAME = "wsqname";
- public static final String WS_PORT_QNAME = "wsportqname";
- public static final String WSDL_URL = "wsdlurl";
-
- private static final AtomicInteger id = new AtomicInteger(31);
- private static final Map<String,Object> registry = new ConcurrentHashMap<String, Object>();
-
- // these two attributes are used to be able to cleanup quickly the registry (otherwise we need to duplicate a lot of logic)
- private static StandardContext currentContext;
- private static final Map<StandardContext, Collection<String>> ID_BY_CONTEXT = new HashMap<StandardContext, Collection<String>>();
-
- public static String getProperty(final Reference ref, final String name) {
- final RefAddr addr = ref.get(name);
- if (addr == null) {
- return null;
- }
- final Object value = addr.getContent();
- return (String) value;
- }
-
- public static boolean isPropertyTrue(final Reference ref, final String name) {
- final RefAddr addr = ref.get(name);
- if (addr == null) {
- return false;
- }
- final Object value = addr.getContent();
- return Boolean.parseBoolean(String.valueOf(value));
- }
-
- public static void setStaticValue(final Resource resource, final Object value) {
- setStaticValue(resource, null, value);
- }
-
- public static void setStaticValue(final Resource resource, final String name, final Object value) {
- final String token = String.valueOf(id.incrementAndGet());
- registry.put(token, value);
- resource.setProperty("static-token" + (name != null ? "-" + name : ""), token);
- if (currentContext != null) {
- Collection<String> ids = ID_BY_CONTEXT.get(currentContext);
- if (ids == null) {
- ids = new ArrayList<String>();
- ID_BY_CONTEXT.put(currentContext, ids);
- }
- ids.add(token);
- }
- }
-
- @SuppressWarnings({"unchecked"})
- public static<T> T getStaticValue(final Reference ref) {
- return (T) getStaticValue(ref, null);
- }
-
- @SuppressWarnings({"unchecked"})
- public static <T> T getStaticValue(final Reference ref, String name) {
- name = name != null ? "-" + name : "";
- final String token = getProperty(ref, "static-token" + name);
- if (token == null) {
- return null;
- }
- return (T) registry.get(token);
- }
-
- public static Class<?> loadClass(final String className) {
- if (className == null) {
- return null;
- }
- try {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (classLoader != null) {
- try {
- return classLoader.loadClass(className);
- } catch(final ClassNotFoundException e) {
- // no-op
- }
- }
- return Class.forName(className);
- } catch (final ClassNotFoundException e) {
- return null;
- }
- }
-
- /**
- * This interface exists because the class org.apache.catalina.deploy.ContextResource
- * is not available in the common classloader in tomcat 55
- */
- public interface Resource {
- void setProperty(String name, Object value);
- }
-
- public static void setCurrentContext(final StandardContext currentContext) {
- NamingUtil.currentContext = currentContext;
- }
-
- public static void cleanUpContextResource(final StandardContext context) {
- final Collection<String> keys = ID_BY_CONTEXT.remove(context);
- if (keys != null) {
- for (final String k : keys) {
- registry.remove(k);
- }
- }
- }
-}
+/**
+ *
+ * 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.common;
+
+import org.apache.catalina.core.StandardContext;
+import org.apache.naming.EjbRef;
+
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class NamingUtil {
+ public static final String NAME = "name";
+ public static final String DEPLOYMENT_ID = "deploymentid";
+ public static final String EXTERNAL = "external";
+ public static final String LOCAL = "local";
+ public static final String LOCALBEAN = "localbean";
+ public static final String REMOTE = EjbRef.REMOTE;
+ public static final String JNDI_NAME = "jndiname";
+ public static final String JNDI_PROVIDER_ID = "jndiproviderid";
+ public static final String UNIT = "unit";
+ public static final String EXTENDED = "extended";
+ public static final String PROPERTIES = "properties";
+ public static final String RESOURCE_ID = "resourceid";
+ public static final String COMPONENT_TYPE = "componenttype";
+ public static final String WS_ID = "wsid";
+ public static final String WS_CLASS = "wsclass";
+ public static final String WS_QNAME = "wsqname";
+ public static final String WS_PORT_QNAME = "wsportqname";
+ public static final String WSDL_URL = "wsdlurl";
+
+ private static final AtomicInteger id = new AtomicInteger(31);
+ private static final Map<String,Object> registry = new ConcurrentHashMap<String, Object>();
+
+ // these two attributes are used to be able to cleanup quickly the registry (otherwise we need to duplicate a lot of logic)
+ private static StandardContext currentContext;
+ private static final Map<StandardContext, Collection<String>> ID_BY_CONTEXT = new HashMap<StandardContext, Collection<String>>();
+
+ public static String getProperty(final Reference ref, final String name) {
+ final RefAddr addr = ref.get(name);
+ if (addr == null) {
+ return null;
+ }
+ final Object value = addr.getContent();
+ return (String) value;
+ }
+
+ public static boolean isPropertyTrue(final Reference ref, final String name) {
+ final RefAddr addr = ref.get(name);
+ if (addr == null) {
+ return false;
+ }
+ final Object value = addr.getContent();
+ return Boolean.parseBoolean(String.valueOf(value));
+ }
+
+ public static void setStaticValue(final Resource resource, final Object value) {
+ setStaticValue(resource, null, value);
+ }
+
+ public static void setStaticValue(final Resource resource, final String name, final Object value) {
+ final String token = String.valueOf(id.incrementAndGet());
+ registry.put(token, value);
+ resource.setProperty("static-token" + (name != null ? "-" + name : ""), token);
+ if (currentContext != null) {
+ Collection<String> ids = ID_BY_CONTEXT.get(currentContext);
+ if (ids == null) {
+ ids = new ArrayList<String>();
+ ID_BY_CONTEXT.put(currentContext, ids);
+ }
+ ids.add(token);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static<T> T getStaticValue(final Reference ref) {
+ return (T) getStaticValue(ref, null);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public static <T> T getStaticValue(final Reference ref, String name) {
+ name = name != null ? "-" + name : "";
+ final String token = getProperty(ref, "static-token" + name);
+ if (token == null) {
+ return null;
+ }
+ return (T) registry.get(token);
+ }
+
+ public static Class<?> loadClass(final String className) {
+ if (className == null) {
+ return null;
+ }
+ try {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if (classLoader != null) {
+ try {
+ return classLoader.loadClass(className);
+ } catch(final ClassNotFoundException e) {
+ // no-op
+ }
+ }
+ return Class.forName(className);
+ } catch (final ClassNotFoundException e) {
+ return null;
+ }
+ }
+
+ /**
+ * This interface exists because the class org.apache.catalina.deploy.ContextResource
+ * is not available in the common classloader in tomcat 55
+ */
+ public interface Resource {
+ void setProperty(String name, Object value);
+ }
+
+ public static void setCurrentContext(final StandardContext currentContext) {
+ NamingUtil.currentContext = currentContext;
+ }
+
+ public static void cleanUpContextResource(final StandardContext context) {
+ final Collection<String> keys = ID_BY_CONTEXT.remove(context);
+ if (keys != null) {
+ for (final String k : keys) {
+ registry.remove(k);
+ }
+ }
+ }
+}