Author: rmannibucau
Date: Mon Oct 1 08:42:51 2012
New Revision: 1392238
URL: http://svn.apache.org/viewvc?rev=1392238&view=rev
Log:
TOMEE-439 deploy wars as in tomcat even from DeployerEjb
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/WebAppDeployer.java
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deployment/
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deployment/TomcatWebappDeployer.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?rev=1392238&r1=1392237&r2=1392238&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
Mon Oct 1 08:42:51 2012
@@ -16,7 +16,6 @@
*/
package org.apache.openejb.assembler;
-import javax.enterprise.inject.Alternative;
import org.apache.openejb.ClassLoaderUtil;
import org.apache.openejb.NoSuchApplicationException;
import org.apache.openejb.OpenEJBException;
@@ -40,6 +39,7 @@ import org.apache.openejb.util.Logger;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
+import javax.enterprise.inject.Alternative;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -65,11 +65,12 @@ public class DeployerEjb implements Depl
public static final Logger LOGGER =
Logger.getInstance(LogCategory.OPENEJB, DeployerEjb.class);
private final static File uniqueFile;
+ private final static boolean oldWarDeployer =
"old".equalsIgnoreCase(SystemInstance.get().getOptions().get("openejb.deployer.war",
"new"));
static {
String uniqueName = "OpenEJB-" + new BigInteger(128, new
SecureRandom()).toString(Character.MAX_RADIX);
String tempDir = System.getProperty("java.io.tmpdir");
- File unique = null;
+ File unique;
try {
unique = new File(tempDir, uniqueName).getCanonicalFile();
unique.createNewFile();
@@ -133,6 +134,25 @@ public class DeployerEjb implements Depl
final File file = new File(realLocation(rawLocation));
+ final WebAppDeployer warDeployer =
SystemInstance.get().getComponent(WebAppDeployer.class);
+ if (warDeployer != null && !oldWarDeployer &&
(file.getName().endsWith(".war") || new File(file, "WEB-INF").exists())) {
+ /* this is generally slow so using the previous if as simpler
heurisitic
+ try {
+ final URL url = file.toURI().toURL();
+ final ClassLoader tempClassLoader =
ClassLoaderUtil.createClassLoader(file.getCanonicalPath(), new URL[]{url},
ParentClassLoaderFinder.Helper.get());
+ final Class<?> type = deploymentLoader.discoverModuleType(url,
tempClassLoader, true);
+ if (WebModule.class.equals(type)) {
+ return
warDeployer.deploy(appModule.getWebModules().iterator().next().getContextRoot(),
file);
+ }
+ } catch (MalformedURLException e) {
+ // no-op
+ } catch (IOException e) {
+ // no-op
+ }
+ */
+ return warDeployer.deploy(contextRoot(properties,
file.getAbsolutePath()), file);
+ }
+
AppInfo appInfo;
try {
@@ -147,7 +167,7 @@ public class DeployerEjb implements Depl
modules.put(module.getModuleId(), module);
}
for (WebModule module : appModule.getWebModules()) {
- final String contextRoot = properties.getProperty("webapp." +
module.getJarLocation() + ".context-root");
+ final String contextRoot = contextRoot(properties,
module.getJarLocation());
if (contextRoot != null) {
module.setContextRoot(contextRoot);
}
@@ -183,6 +203,7 @@ public class DeployerEjb implements Depl
}
}
}
+
appInfo = configurationFactory.configureApplication(appModule);
appInfo.autoDeploy =
Boolean.parseBoolean(properties.getProperty("openejb.app.autodeploy", "false"));
@@ -302,4 +323,8 @@ public class DeployerEjb implements Depl
}
saveDeployment(new File(moduleId), false);
}
+
+ private static String contextRoot(final Properties properties, final
String jarPath) {
+ return properties.getProperty("webapp." + jarPath + ".context-root");
+ }
}
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/WebAppDeployer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/WebAppDeployer.java?rev=1392238&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/WebAppDeployer.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/WebAppDeployer.java
Mon Oct 1 08:42:51 2012
@@ -0,0 +1,25 @@
+/*
+ * 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.assembler;
+
+import org.apache.openejb.assembler.classic.AppInfo;
+
+import java.io.File;
+
+public interface WebAppDeployer {
+ AppInfo deploy(String contextRoot, File file);
+}
Modified:
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java?rev=1392238&r1=1392237&r2=1392238&view=diff
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
(original)
+++
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
Mon Oct 1 08:42:51 2012
@@ -28,6 +28,7 @@ import org.apache.catalina.core.Standard
import org.apache.catalina.startup.Bootstrap;
import org.apache.catalina.startup.Catalina;
import org.apache.openejb.OpenEJB;
+import org.apache.openejb.assembler.WebAppDeployer;
import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
import org.apache.openejb.assembler.classic.WebAppBuilder;
import org.apache.openejb.classloader.WebAppEnricher;
@@ -50,6 +51,7 @@ import org.apache.openejb.util.LogCatego
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.OptionsLog;
import org.apache.tomcat.util.scan.Constants;
+import org.apache.tomee.catalina.deployment.TomcatWebappDeployer;
import org.apache.tomee.installer.Installer;
import org.apache.tomee.installer.Paths;
import org.apache.tomee.loader.TomcatHelper;
@@ -213,6 +215,9 @@ public class TomcatLoader implements Loa
}
SystemInstance.get().setComponent(ParentClassLoaderFinder.class,
tomcatWebAppBuilder);
+ // set webapp deployer reusing tomcat deployer instead of our custom
deployer for war
+ SystemInstance.get().setComponent(WebAppDeployer.class, new
TomcatWebappDeployer());
+
// for compatibility purpose, no more used normally by our trunk
SystemInstance.get().setComponent(WebDeploymentListeners.class, new
WebDeploymentListeners());
Modified:
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1392238&r1=1392237&r2=1392238&view=diff
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
(original)
+++
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
Mon Oct 1 08:42:51 2012
@@ -425,10 +425,12 @@ public class TomcatWebAppBuilder impleme
// Note: the line
standardContext.getLoader().setDelegate(true);
// could be hardcoded in the custom loader
// but here we have all the classloading logic
- standardContext.setParentClassLoader(classLoader);
- standardContext.setDelegate(true);
- standardContext.setLoader(new TomEEWebappLoader(appInfo.path,
classLoader));
- standardContext.getLoader().setDelegate(true);
+ if (classLoader != null) {
+ standardContext.setParentClassLoader(classLoader);
+ standardContext.setDelegate(true);
+ standardContext.setLoader(new
TomEEWebappLoader(appInfo.path, classLoader));
+ standardContext.getLoader().setDelegate(true);
+ }
String host = webApp.host;
if (host == null) {
@@ -436,29 +438,48 @@ public class TomcatWebAppBuilder impleme
logger.info("using default host: " + host);
}
- // TODO: instead of storing deployers, we could just lookup
the right hostconfig for the server.
- final HostConfig deployer = deployers.get(host);
- appInfo.autoDeploy = false;
- if (isReady(deployer)) { // if not ready using directly host
to avoid a NPE
- // host isn't set until we call deployer.manageApp, so
pass it
- // ?? host is set through an event and it can be null here
:(
- final ContextInfo contextInfo = addContextInfo(host,
standardContext);
- contextInfo.appInfo = appInfo;
- contextInfo.deployer = deployer;
- deployer.manageApp(standardContext);
- } else if (hosts.containsKey(host)) {
- final Host theHost = hosts.get(host);
-
- final ContextInfo contextInfo = addContextInfo(host,
standardContext);
- contextInfo.appInfo = appInfo;
- contextInfo.host = theHost;
-
- theHost.addChild(standardContext);
+ if (classLoader != null) {
+ appInfo.autoDeploy = false;
+ deployWar(standardContext, host, appInfo);
+ } else { // force a normal deployment with lazy building of
AppInfo
+ deployWar(standardContext, host, null);
}
}
}
}
+ public void deployWar(final StandardContext standardContext, final String
host, final AppInfo info) {
+ // TODO: instead of storing deployers, we could just lookup the right
hostconfig for the server.
+ final HostConfig deployer = deployers.get(host);
+ if (isReady(deployer)) { // if not ready using directly host to avoid
a NPE
+ if (info != null) {
+ final ContextInfo contextInfo = addContextInfo(host,
standardContext);
+ contextInfo.appInfo = info;
+ contextInfo.deployer = deployer;
+ }
+
+ deployer.manageApp(standardContext);
+ } else if (hosts.containsKey(host)) {
+ final Host theHost = hosts.get(host);
+ if (info != null) {
+ final ContextInfo contextInfo = addContextInfo(host,
standardContext);
+ contextInfo.appInfo = info;
+ contextInfo.host = theHost;
+ }
+
+ theHost.addChild(standardContext);
+ }
+ }
+
+ public AppInfo standaAloneWebAppInfo(final String path) {
+ for (ContextInfo info : infos.values()) {
+ if (info.appInfo.webAppAlone && (path.equals(info.appInfo.path) ||
path.equals(info.appInfo.path + ".war"))) {
+ return info.appInfo;
+ }
+ }
+ return null;
+ }
+
// TODO: find something more sexy
private static Field HOST_CONFIG_HOST = null;
Added:
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deployment/TomcatWebappDeployer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deployment/TomcatWebappDeployer.java?rev=1392238&view=auto
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deployment/TomcatWebappDeployer.java
(added)
+++
openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deployment/TomcatWebappDeployer.java
Mon Oct 1 08:42:51 2012
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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.deployment;
+
+import org.apache.openejb.assembler.WebAppDeployer;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.WebAppBuilder;
+import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.tomee.catalina.TomEERuntimeException;
+import org.apache.tomee.catalina.TomcatWebAppBuilder;
+
+import java.io.File;
+
+public class TomcatWebappDeployer implements WebAppDeployer {
+ @Override
+ public AppInfo deploy(final String context, final File file) {
+ final TomcatWebAppBuilder tomcatWebAppBuilder = (TomcatWebAppBuilder)
SystemInstance.get().getComponent(WebAppBuilder.class);
+ try {
+ tomcatWebAppBuilder.deployWebApps(fakeInfo(file, context), null);
+ } catch (Exception e) {
+ throw new TomEERuntimeException(e);
+ }
+ return
tomcatWebAppBuilder.standaAloneWebAppInfo(file.getAbsolutePath());
+ }
+
+ private AppInfo fakeInfo(final File file, final String context) {
+ final AppInfo info = new AppInfo();
+ info.path = file.getAbsolutePath();
+ info.webAppAlone = true;
+
+ final WebAppInfo webAppInfo = new WebAppInfo();
+ webAppInfo.path = info.path;
+
+ if (context == null) {
+ webAppInfo.contextRoot = file.getName();
+ } else {
+ webAppInfo.contextRoot = context;
+ }
+
+ webAppInfo.moduleId = webAppInfo.contextRoot;
+ info.webApps.add(webAppInfo);
+
+ return info;
+ }
+}