You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/02/14 19:25:36 UTC

svn commit: r1244147 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/assembler/ container/openejb-core/src/main/java/org/apache/openejb/config/ tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/

Author: dblevins
Date: Tue Feb 14 18:25:36 2012
New Revision: 1244147

URL: http://svn.apache.org/viewvc?rev=1244147&view=rev
Log:
Some tweaks to OPENEJB-1774 and OPENEJB-1772
Changed file to META-INF/app-info.xml
Moved logic to another class to keep the code digestable
Minor improvements to error handling and logging

Added:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PreconfiguredFactory.java
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/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=1244147&r1=1244146&r2=1244147&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 18:25:36 2012
@@ -26,6 +26,7 @@ import org.apache.openejb.config.AppModu
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.DeploymentLoader;
 import org.apache.openejb.config.DeploymentModule;
+import org.apache.openejb.config.PreconfiguredFactory;
 import org.apache.openejb.config.sys.AdditionalDeployments;
 import org.apache.openejb.config.sys.Deployments;
 import org.apache.openejb.config.sys.JaxbOpenejb;
@@ -112,11 +113,11 @@ public class DeployerEjb implements Depl
             properties = new Properties();
         }
 
-        AppInfo appInfo;
         AppModule appModule = null;
 
         final File file = new File(realLocation(rawLocation));
-        appInfo = ConfigurationFactory.loadDump(file);
+
+        AppInfo appInfo = PreconfiguredFactory.configureApplication(file);
 
         try {
             if (appInfo == null) { // using app-info.xml we ignore alt-dd

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=1244147&r1=1244146&r2=1244147&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 18:25:36 2012
@@ -32,7 +32,6 @@ import org.apache.openejb.assembler.clas
 import org.apache.openejb.assembler.classic.FacilitiesInfo;
 import org.apache.openejb.assembler.classic.HandlerChainInfo;
 import org.apache.openejb.assembler.classic.HandlerInfo;
-import org.apache.openejb.assembler.classic.Info;
 import org.apache.openejb.assembler.classic.JndiContextInfo;
 import org.apache.openejb.assembler.classic.ManagedContainerInfo;
 import org.apache.openejb.assembler.classic.MdbContainerInfo;
@@ -79,16 +78,9 @@ import org.apache.openejb.util.URLs;
 import org.apache.openejb.util.UpdateChecker;
 
 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.Writer;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -103,20 +95,15 @@ 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);
@@ -614,22 +601,28 @@ public class ConfigurationFactory implem
     public AppInfo configureApplication(final File jarFile) throws OpenEJBException {
         logger.debug("Beginning load: " + jarFile.getAbsolutePath());
 
-        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;
+        try {
+            AppInfo appInfo = PreconfiguredFactory.configureApplication(jarFile);
+            if (appInfo != null) {
+                logger.info("app-info.xml found and loaded: " + jarFile.getAbsolutePath());
+                return appInfo;
             }
+        } catch (Exception e) {
+            logger.warning("configureApplication.preloadFailed", e, jarFile.getAbsolutePath(), e.getMessage());
+        }
+
+        try {
+            final AppModule appModule = deploymentLoader.load(jarFile);
+            return 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;
     }
 
     /**
@@ -1304,79 +1297,4 @@ public class ConfigurationFactory implem
         }
     }
 
-    public static void dump(final Writer output, final AppInfo info) throws OpenEJBException {
-        FileOutputStream fos = null;
-        try {
-            Info.marshal(info, output);
-        } catch (JAXBException e) {
-            throw new OpenEJBException(e);
-        } finally {
-            IO.close(fos);
-        }
-    }
-
-    private static AppInfo loadDump(final String modulePath, final InputStream input) throws OpenEJBException {
-        if (input == null || modulePath == null) {
-            throw new OpenEJBException("input and modulePath can't be null");
-        }
-
-        String read;
-        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) {
-            throw new OpenEJBException(e);
-        } finally {
-            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;
-    }
 }

Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PreconfiguredFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PreconfiguredFactory.java?rev=1244147&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PreconfiguredFactory.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PreconfiguredFactory.java Tue Feb 14 18:25:36 2012
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Info;
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.SystemInstance;
+
+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.Writer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PreconfiguredFactory {
+
+    public static final String APP_INFO_XML = "META-INF/app-info.xml";
+    public static final String APP_INFO_XML_PATH = "$PATH";
+    public static final boolean FORCE_SCANNING = SystemInstance.get().getOptions().get("openejb.force.scanning", false);
+
+    public static void dump(final Writer output, final AppInfo info) throws OpenEJBException {
+        FileOutputStream fos = null;
+        try {
+            Info.marshal(info, output);
+        } catch (JAXBException e) {
+            throw new OpenEJBException(e);
+        } finally {
+            IO.close(fos);
+        }
+    }
+
+    public static AppInfo loadDump(final String modulePath, final InputStream input) throws OpenEJBException {
+        if (input == null || modulePath == null) {
+            throw new OpenEJBException("input and modulePath can't be null");
+        }
+
+        String read;
+        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) {
+            throw new OpenEJBException(e);
+        } finally {
+            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;
+    }
+
+    public static AppInfo configureApplication(final File file) throws OpenEJBException {
+        return loadDump(file);
+    }
+}

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=1244147&r1=1244146&r2=1244147&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 18:25:36 2012
@@ -56,6 +56,7 @@ import org.apache.openejb.assembler.clas
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.DeploymentLoader;
+import org.apache.openejb.config.PreconfiguredFactory;
 import org.apache.openejb.config.WebModule;
 import org.apache.openejb.core.CoreContainerSystem;
 import org.apache.openejb.core.WebContext;
@@ -945,7 +946,13 @@ public class TomcatWebAppBuilder impleme
                     continue;
                 }
 
-                AppInfo appInfo = ConfigurationFactory.loadDump(file);
+                AppInfo appInfo = null;
+                try {
+                    appInfo = PreconfiguredFactory.configureApplication(file);
+                } catch (OpenEJBException e) {
+                    logger.warning("Failed to load META-INF/app-info.xml " + file.getAbsolutePath(), e);
+                }
+
                 try {
                     AppModule appModule = null;
                     if (appInfo == null) {
@@ -990,10 +997,11 @@ public class TomcatWebAppBuilder impleme
                     }
 
                     getAssembler().createApplication(appInfo);
+
+                    deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
                 } catch (Throwable e) {
                     logger.warning("Error deploying application " + file.getAbsolutePath(), e);
                 }
-                deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
             }
         }
     }