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 2012/02/14 11:51:32 UTC
svn commit: r1243867 - in /openejb/trunk/openejb:
container/openejb-core/src/main/java/org/apache/openejb/assembler/
container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/
container/openejb-core/src/main/java/org/apache/openejb/conf...
Author: rmannibucau
Date: Tue Feb 14 10:51:31 2012
New Revision: 1243867
URL: http://svn.apache.org/viewvc?rev=1243867&view=rev
Log:
OPENEJB-1772 some more work to be able to skip info tree build - todo: check if jaxb annotation in EjbJarInfo are ok
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.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=1243867&r1=1243866&r2=1243867&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 Tue Feb 14 10:51:31 2012
@@ -112,54 +112,60 @@ public class DeployerEjb implements Depl
properties = new Properties();
}
+ AppInfo appInfo;
AppModule appModule = null;
+
+ final File file = new File(realLocation(rawLocation));
+ appInfo = ConfigurationFactory.loadDump(file);
+
try {
- File file = new File(realLocation(rawLocation));
- appModule = deploymentLoader.load(file);
+ if (appInfo == null) { // using app-info.xml we ignore alt-dd
+ appModule = deploymentLoader.load(file);
- // Add any alternate deployment descriptors to the modules
- Map<String, DeploymentModule> modules = new TreeMap<String, DeploymentModule>();
- for (DeploymentModule module : appModule.getEjbModules()) {
- modules.put(module.getModuleId(), module);
- }
- for (DeploymentModule module : appModule.getClientModules()) {
- modules.put(module.getModuleId(), module);
- }
- for (DeploymentModule module : appModule.getWebModules()) {
- modules.put(module.getModuleId(), module);
- }
- for (DeploymentModule module : appModule.getConnectorModules()) {
- modules.put(module.getModuleId(), module);
- }
-
- for (Map.Entry<Object, Object> entry : properties.entrySet()) {
- String name = (String) entry.getKey();
- if (name.startsWith(ALT_DD + "/")) {
- name = name.substring(ALT_DD.length() + 1);
-
- DeploymentModule module;
- int slash = name.indexOf('/');
- if (slash > 0) {
- String moduleId = name.substring(0, slash);
- name = name.substring(slash + 1);
- module = modules.get(moduleId);
- } else {
- module = appModule;
- }
+ // Add any alternate deployment descriptors to the modules
+ Map<String, DeploymentModule> modules = new TreeMap<String, DeploymentModule>();
+ for (DeploymentModule module : appModule.getEjbModules()) {
+ modules.put(module.getModuleId(), module);
+ }
+ for (DeploymentModule module : appModule.getClientModules()) {
+ modules.put(module.getModuleId(), module);
+ }
+ for (DeploymentModule module : appModule.getWebModules()) {
+ modules.put(module.getModuleId(), module);
+ }
+ for (DeploymentModule module : appModule.getConnectorModules()) {
+ modules.put(module.getModuleId(), module);
+ }
- if (module != null) {
- String value = (String) entry.getValue();
- File dd = new File(value);
- if (dd.canRead()) {
- module.getAltDDs().put(name, dd.toURI().toURL());
+ for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+ String name = (String) entry.getKey();
+ if (name.startsWith(ALT_DD + "/")) {
+ name = name.substring(ALT_DD.length() + 1);
+
+ DeploymentModule module;
+ int slash = name.indexOf('/');
+ if (slash > 0) {
+ String moduleId = name.substring(0, slash);
+ name = name.substring(slash + 1);
+ module = modules.get(moduleId);
} else {
- module.getAltDDs().put(name, value);
+ module = appModule;
+ }
+
+ if (module != null) {
+ String value = (String) entry.getValue();
+ File dd = new File(value);
+ if (dd.canRead()) {
+ module.getAltDDs().put(name, dd.toURI().toURL());
+ } else {
+ module.getAltDDs().put(name, value);
+ }
}
}
}
+ appInfo = configurationFactory.configureApplication(appModule);
}
- AppInfo appInfo = configurationFactory.configureApplication(appModule);
if (properties != null && properties.containsKey(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP)) {
appInfo.appId = properties.getProperty(OPENEJB_DEPLOYER_FORCED_APP_ID_PROP);
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java?rev=1243867&r1=1243866&r2=1243867&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java Tue Feb 14 10:51:31 2012
@@ -16,6 +16,8 @@
*/
package org.apache.openejb.assembler.classic;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
import java.net.URI;
import java.util.List;
import java.util.ArrayList;
@@ -29,7 +31,16 @@ public class EjbJarInfo extends CommonIn
public String moduleName;
public URI moduleUri;
public String path;
- public final List<EnterpriseBeanInfo> enterpriseBeans = new ArrayList<EnterpriseBeanInfo>();
+
+ @XmlElements({ // needed for unmarshalling
+ @XmlElement(name = "stateless", type = StatelessBeanInfo.class),
+ @XmlElement(name = "entity", type = EntityBeanInfo.class),
+ @XmlElement(name = "stateful", type = StatefulBeanInfo.class),
+ @XmlElement(name = "singleton", type = SingletonBeanInfo.class),
+ @XmlElement(name = "message-driven", type = MessageDrivenBeanInfo.class),
+ @XmlElement(name = "managed-bean", type = ManagedBeanInfo.class)
+ })
+ public final List<? extends EnterpriseBeanInfo> enterpriseBeans = new ArrayList<EnterpriseBeanInfo>();
public final List<SecurityRoleInfo> securityRoles = new ArrayList<SecurityRoleInfo>();
public final List<MethodPermissionInfo> methodPermissions= new ArrayList<MethodPermissionInfo>();
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java?rev=1243867&r1=1243866&r2=1243867&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java Tue Feb 14 10:51:31 2012
@@ -23,6 +23,7 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Writer;
/**
* @version $Rev$ $Date$
@@ -57,6 +58,10 @@ public class Info {
marshaller().marshal(new Info(appInfo), out);
}
+ public static void marshal(AppInfo appInfo, Writer out) throws JAXBException {
+ marshaller().marshal(new Info(appInfo), out);
+ }
+
public static AppInfo unmarshal(InputStream in) throws JAXBException {
return ((Info) unmarshaller().unmarshal(in)).appInfo;
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1243867&r1=1243866&r2=1243867&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Tue Feb 14 10:51:31 2012
@@ -81,12 +81,15 @@ import org.apache.openejb.util.UpdateChe
import javax.ejb.embeddable.EJBContainer;
import javax.xml.bind.JAXBException;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
+import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -101,15 +104,20 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
import static org.apache.openejb.config.ServiceUtils.implies;
public class ConfigurationFactory implements OpenEjbConfigurationFactory {
public static final String APP_INFO_XML = "openejb/app-info.xml";
+ public static final String APP_INFO_XML_PATH = "$PATH";
+
public static final String ADDITIONAL_DEPLOYMENTS = "conf/deployments.xml";
static final String CONFIGURATION_PROPERTY = "openejb.configuration";
static final String CONF_FILE_PROPERTY = "openejb.conf.file";
+ private static final boolean FORCE_SCANNING = Boolean.getBoolean("openejb.force.scanning");
private static final String DEBUGGABLE_VM_HACKERY_PROPERTY = "openejb.debuggable-vm-hackery";
protected static final String VALIDATION_SKIP_PROPERTY = "openejb.validation.skip";
private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, ConfigurationFactory.class);
@@ -607,18 +615,20 @@ public class ConfigurationFactory implem
public AppInfo configureApplication(final File jarFile) throws OpenEJBException {
logger.debug("Beginning load: " + jarFile.getAbsolutePath());
- final AppInfo appInfo;
- try {
- final AppModule appModule = deploymentLoader.load(jarFile);
- appInfo = configureApplication(appModule);
- } catch (ValidationFailedException e) {
- logger.warning("configureApplication.loadFailed", jarFile.getAbsolutePath(), e.getMessage()); // DO not include the stacktrace in the message
- throw e;
- } catch (OpenEJBException e) {
- // DO NOT REMOVE THE EXCEPTION FROM THIS LOG MESSAGE
- // removing this message causes NO messages to be printed when embedded
- logger.warning("configureApplication.loadFailed", e, jarFile.getAbsolutePath(), e.getMessage());
- throw e;
+ AppInfo appInfo = loadDump(jarFile);
+ if (appInfo == null) {
+ try {
+ final AppModule appModule = deploymentLoader.load(jarFile);
+ appInfo = configureApplication(appModule);
+ } catch (ValidationFailedException e) {
+ logger.warning("configureApplication.loadFailed", jarFile.getAbsolutePath(), e.getMessage()); // DO not include the stacktrace in the message
+ throw e;
+ } catch (OpenEJBException e) {
+ // DO NOT REMOVE THE EXCEPTION FROM THIS LOG MESSAGE
+ // removing this message causes NO messages to be printed when embedded
+ logger.warning("configureApplication.loadFailed", e, jarFile.getAbsolutePath(), e.getMessage());
+ throw e;
+ }
}
return appInfo;
}
@@ -1295,18 +1305,10 @@ public class ConfigurationFactory implem
}
}
- public void dump(final File output, final AppInfo info) throws OpenEJBException {
- final File parent = output.getParentFile();
- if (!parent.exists() && !parent.mkdirs()) {
- throw new OpenEJBException("can't create directory " + output.getParent());
- }
-
+ public static void dump(final Writer output, final AppInfo info) throws OpenEJBException {
FileOutputStream fos = null;
try {
- fos = new FileOutputStream(output);
- Info.marshal(info, fos);
- } catch (FileNotFoundException e) {
- throw new OpenEJBException(e);
+ Info.marshal(info, output);
} catch (JAXBException e) {
throw new OpenEJBException(e);
} finally {
@@ -1314,13 +1316,24 @@ public class ConfigurationFactory implem
}
}
- public AppInfo loadDump(final InputStream input) throws OpenEJBException {
- if (input == null) {
+ private static AppInfo loadDump(final String modulePath, final InputStream input) throws OpenEJBException {
+ if (input == null || modulePath == null) {
throw new NullPointerException("input can't be null");
}
- // TODO: something else is surely better than java serialization!
- final InputStream fis = new BufferedInputStream(input);
+ String read = null;
+ try {
+ read = IO.slurp(input);
+ } catch (IOException e) {
+ throw new OpenEJBException(e);
+ }
+
+ // manage path
+ read = read.replace(APP_INFO_XML_PATH, modulePath);
+
+ // TODO: manage resources + containers
+
+ final InputStream fis = new BufferedInputStream(new ByteArrayInputStream(read.getBytes()));
try {
return Info.unmarshal(fis);
} catch (JAXBException e) {
@@ -1329,4 +1342,42 @@ public class ConfigurationFactory implem
IO.close(fis);
}
}
+
+ public static AppInfo loadDump(final File file) {
+ if (!file.exists() || FORCE_SCANNING) {
+ return null;
+ }
+
+ InputStream is = null;
+ if (file.isDirectory()) {
+ final File xml = new File(file, APP_INFO_XML);
+ if (xml.exists()) {
+ try {
+ is = new FileInputStream(xml);
+ } catch (FileNotFoundException e) {
+ // ignored: if this method returns null simply deploy the app normally
+ }
+ }
+ } else { // an archive
+ try {
+ final JarFile jar = new JarFile(file);
+ final JarEntry entry = jar.getJarEntry(APP_INFO_XML);
+ if (entry != null) {
+ is = jar.getInputStream(entry);
+ }
+ } catch (Exception e) {
+ // ignored too
+ }
+ }
+
+ try {
+ return loadDump(file.getAbsolutePath(), is);
+ } catch (OpenEJBException e) {
+ // ignored, it will return null and a standard deployment should be tried
+ } finally {
+ IO.close(is);
+ }
+
+ return null;
+ }
}
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=1243867&r1=1243866&r2=1243867&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 Tue Feb 14 10:51:31 2012
@@ -945,17 +945,30 @@ public class TomcatWebAppBuilder impleme
continue;
}
- AppInfo appInfo = null;
+ AppInfo appInfo = ConfigurationFactory.loadDump(file);
try {
- file = file.getCanonicalFile().getAbsoluteFile();
+ AppModule appModule = null;
+ if (appInfo == null) {
+ file = file.getCanonicalFile().getAbsoluteFile();
+ appModule = deploymentLoader.load(file);
+
+ // Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
+ if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
+ WebModule webModule = appModule.getWebModules().iterator().next();
+ if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
+ continue;
+ }
+ }
- AppModule appModule = deploymentLoader.load(file);
+ // tell web modules to deploy using this host
+ for (WebModule webModule : appModule.getWebModules()) {
+ webModule.setHost(standardHost.getName());
+ }
- // Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
- if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
- WebModule webModule = appModule.getWebModules().iterator().next();
- if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
- continue;
+ appInfo = configurationFactory.configureApplication(appModule);
+ } else {
+ for (WebAppInfo webAppInfo : appInfo.webApps) {
+ webAppInfo.host = standardHost.getName();
}
}
@@ -976,12 +989,6 @@ public class TomcatWebAppBuilder impleme
}
}
- // tell web modules to deploy using this host
- for (WebModule webModule : appModule.getWebModules()) {
- webModule.setHost(standardHost.getName());
- }
-
- appInfo = configurationFactory.configureApplication(appModule);
getAssembler().createApplication(appInfo);
} catch (Throwable e) {
logger.warning("Error deploying application " + file.getAbsolutePath(), e);