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 2006/11/07 08:08:41 UTC

svn commit: r472011 - in /incubator/openejb/trunk/openejb3: container/openejb-core/ container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-core/src/main/java/org/apache/openejb/alt/config/ container/openejb-core/src/main/java/org/ap...

Author: dblevins
Date: Mon Nov  6 23:08:40 2006
New Revision: 472011

URL: http://svn.apache.org/viewvc?view=rev&rev=472011
Log:
Basic support for OPENEJB-304.  Not fancy and needs to be reworked.

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/ApplicationTest.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-app/
    incubator/openejb/trunk/openejb3/itests/openejb-itests-app/pom.xml
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/DeploymentLoader.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/JaxbUnmarshaller.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/JDOManagerBuilder.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/DeploymentsFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SomeoneBrokeSurefireAndThisIsADirtyHackForItTest.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssembler2Test.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssemblerTest.java
    incubator/openejb/trunk/openejb3/itests/pom.xml

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml Mon Nov  6 23:08:40 2006
@@ -253,6 +253,18 @@
     </dependency>
     <dependency>
       <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-itests-app</artifactId>
+      <version>${pom.version}-x</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-itests-beans</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
       <artifactId>openejb-itests-client</artifactId>
       <version>${pom.version}</version>
       <scope>test</scope>

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java Mon Nov  6 23:08:40 2006
@@ -87,7 +87,8 @@
                 System.out.println("" + versionInfo.get("url"));
             }
 
-            logger.i18n.info("startup.banner", versionInfo.get("url"), new Date(), versionInfo.get("copyright"),
+            Logger logger2 = Logger.getInstance("OpenEJB", "org.apache.openejb.util.resources");
+            logger2.i18n.info("startup.banner", versionInfo.get("url"), new Date(), versionInfo.get("copyright"),
                     versionInfo.get("version"), versionInfo.get("date"), versionInfo.get("time"));
 
             logger.info("openejb.home = " + SystemInstance.get().getHome().getDirectory().getAbsolutePath());

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/DeploymentLoader.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/DeploymentLoader.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/DeploymentLoader.java Mon Nov  6 23:08:40 2006
@@ -18,23 +18,33 @@
 package org.apache.openejb.alt.config;
 
 import org.apache.openejb.alt.config.sys.Deployments;
+import org.apache.openejb.alt.config.ejb.OpenejbJar;
 import org.apache.openejb.loader.FileUtils;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.OpenEJB;
+import org.apache.openejb.jee.Application;
+import org.apache.openejb.jee.Module;
+import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.util.Logger;
-import org.apache.xbean.finder.ClassFinder;
 
-import javax.ejb.Stateless;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.jar.JarFile;
+import java.util.jar.JarEntry;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.BufferedOutputStream;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.MalformedURLException;
+import java.net.JarURLConnection;
+import java.nio.channels.FileChannel;
 
 /**
  * @version $Revision$ $Date$
@@ -86,6 +96,14 @@
             return;
         }
 
+        File appXml = new File(dir, "META-INF" + File.separator + "application.xml");
+        if (appXml.exists()) {
+            if (!jarList.contains(dir.getAbsolutePath())) {
+                jarList.add(dir.getAbsolutePath());
+            }
+            return;
+        }
+
         ////////////////////////////////
         //
         //  Directory container Jar files
@@ -93,7 +111,7 @@
         ////////////////////////////////
         String[] jarFiles = dir.list(new FilenameFilter() {
             public boolean accept(File dir, String name) {
-                return name.endsWith(".jar");
+                return name.endsWith(".jar") || name.endsWith(".ear");
             }
         });
 
@@ -136,9 +154,11 @@
         }
 
         deployer = new AnnotationDeployer(deployer);
-        
+
         if (!SystemInstance.get().getProperty("openejb.validation.skip", "false").equalsIgnoreCase("true")){
             deployer = new ValidateEjbModule(deployer);
+        } else {
+            logger.info("Validation is disabled.");
         }
 
         List<EjbModule> deployedJars = new ArrayList();
@@ -152,7 +172,21 @@
         try {
             for (Deployments deployment : deployments) {
                 if (deployment.getClasspath() != null){
-                    loadFromClasspath(base, jarList, deployment.getClasspath());
+                    ClassLoader classLoader = deployment.getClasspath();
+                    if (logger.isDebugEnabled()){
+                        Enumeration<URL> resources = null;
+                        try {
+                            resources = classLoader.getResources("META-INF");
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
+                        while (resources.hasMoreElements()) {
+                            URL url = resources.nextElement();
+                            logger.debug("Searching: "+ url.toExternalForm());
+                        }
+                    }
+                    loadFromClasspath(base, jarList, classLoader, "META-INF/ejb-jar.xml", "ejbs");
+                    loadFromClasspath(base, jarList, deployment.getClasspath(), "META-INF/application.xml", "ear");
                 } else {
                     loadFrom(deployment, base, jarList);
                 }
@@ -169,14 +203,12 @@
 
             String jarLocation = jarsToLoad[i];
             try {
-                EjbJarUtils ejbJarUtils = new EjbJarUtils(jarLocation);
 
                 ClassLoader classLoader;
-
-                File jarFile = new File(jarLocation);
-                if (jarFile.isDirectory()) {
+                File file = new File(jarLocation);
+                if (file.isDirectory()) {
                     try {
-                        URL[] urls = new URL[]{jarFile.toURL()};
+                        URL[] urls = new URL[]{file.toURL()};
                         classLoader = new URLClassLoader(urls, OpenEJB.class.getClassLoader());
         //                        classLoader = new URLClassLoader(urls, this.getClass().getClassLoader());
 
@@ -188,25 +220,142 @@
                     classLoader = tempCodebase.getClassLoader();
                 }
 
-                EjbModule undeployedModule = new EjbModule(classLoader, jarLocation, ejbJarUtils.getEjbJar(), ejbJarUtils.getOpenejbJar());
-                EjbModule ejbModule = deployer.deploy(undeployedModule);
+                URL baseUrl = null;
+                try {
+                    baseUrl = file.toURL();
+                } catch (MalformedURLException e) {
+                    throw new OpenEJBException("Malformed URL to app. "+e.getMessage(), e);
+                }
+
+                URL appXmlUrl = getResource(baseUrl, classLoader, "META-INF/application.xml");
+                if (appXmlUrl != null) {
+                    if (appXmlUrl.getProtocol().equals("jar")){
+                        String name = file.getName();
+                        if (name.endsWith(".jar") || name.endsWith(".ear")|| name.endsWith(".zip")){
+                            name = name.replaceFirst("....$","");
+                        } else {
+                            name += "_app";
+                        }
+                        try {
+                            logger.info("Extracting jar: "+appXmlUrl.toExternalForm());
+                            jarLocation = JarExtractor.extract(appXmlUrl, name);
+                            logger.info("Extracted path: "+jarLocation);
+                            file = new File(jarLocation);
+                            baseUrl = file.toURL();
+                            classLoader = new URLClassLoader(new URL[]{baseUrl}, OpenEJB.class.getClassLoader());
+                        } catch (IOException e) {
+                            throw new OpenEJBException("Unable to extract jar. "+e.getMessage(), e);
+                        }
+                    } else if (!file.isDirectory()) {
+                        throw new OpenEJBException("Application file must be a directory or jar");
+                    }
+
+                    File appDirectory = file;
+
+                    try {
+                        JaxbUnmarshaller appUnmarshaller = new JaxbUnmarshaller(Application.class, "META-INF/application.xml");
+                        JaxbUnmarshaller ejbUnmarshaller = new JaxbUnmarshaller(EjbJar.class, "META-INF/ejb-jar.xml");
+                        JaxbUnmarshaller openejbUnmarshaller = new JaxbUnmarshaller(OpenejbJar.class, "META-INF/openejb-jar.xml");
+                        Application application = (Application) appUnmarshaller.unmarshal(appXmlUrl);
+                        String[] files = appDirectory.list(new FilenameFilter(){
+                            public boolean accept(File dir, String name) {
+                                return name.endsWith(".jar") || name.endsWith(".zip");
+                            }
+                        });
+
+                        List<URL> appUrls = new ArrayList();
+                        for (String fileName : files) {
+                            File lib = new File(file, fileName);
+                            try {
+                                appUrls.add(lib.toURL());
+                            } catch (MalformedURLException e) {
+                                logger.error("Bad resource in classpath.  Unable to search for entries. ",e);
+                            }
+                        }
+                        ClassLoader appClassLoader = new URLClassLoader(appUrls.toArray(new URL[]{}), OpenEJB.class.getClassLoader());
+                        for (Module module : application.getModule()) {
+                            String ejbLocation = module.getEjb();
+                            if (ejbLocation != null){
+                                try {
+                                    URL ejbUrl = new File(appDirectory,ejbLocation).toURL();
+//                                    ClassLoader ejbClassLoader = new URLClassLoader(new URL[]{ejbUrl}, classLoader);
+
+                                    URL ejbXmlUrl = getResource(ejbUrl, appClassLoader, "META-INF/ejb-jar.xml");
+
+                                    if (ejbXmlUrl == null) {
+                                        throw new OpenEJBException("ejb-jar.xml not found.");
+                                    }
+                                    EjbJar ejbJar = (EjbJar) ejbUnmarshaller.unmarshal(ejbXmlUrl);
+
+                                    URL openejbXmlUrl = getResource(ejbUrl, appClassLoader, "META-INF/openejb-jar.xml");
+                                    OpenejbJar openejbJar = null;
+                                    if (openejbXmlUrl != null) {
+                                        openejbJar = (OpenejbJar) openejbUnmarshaller.unmarshal(openejbXmlUrl);
+                                    }
+                                    String jarURI = new File(ejbUrl.getFile()).getAbsolutePath();
+                                    EjbModule ejbModule = new EjbModule(classLoader, jarURI, ejbJar, openejbJar);
+                                    deployedJars.add(ejbModule);
+                                } catch (OpenEJBException e) {
+                                    logger.error("Unable to load EJBs from EAR: "+  appDirectory.getAbsolutePath() +", module: "+ejbLocation +". Exception: "+e.getMessage(), e);
+                                } catch (MalformedURLException e) {
+                                    logger.error("Bad resource in classpath.  Unable to search for entries. ",e);
+                                }
+                            }
+                        }
+                    } catch (OpenEJBException e) {
+                        logger.error("Unable to load EAR: "+ appXmlUrl.toExternalForm(), e);
+                    }
+                } else {
+                    EjbJarUtils ejbJarUtils = new EjbJarUtils(jarLocation);
+                    EjbModule undeployedModule = new EjbModule(classLoader, jarLocation, ejbJarUtils.getEjbJar(), ejbJarUtils.getOpenejbJar());
+                    EjbModule ejbModule = deployer.deploy(undeployedModule);
+
+                    /* Add it to the Vector ***************/
+                    deployedJars.add(ejbModule);
+                }
 
-                /* Add it to the Vector ***************/
-                ConfigurationFactory.logger.info("Loaded EJBs from " + jarLocation);
-                deployedJars.add(ejbModule);
             } catch (OpenEJBException e) {
                 ConfigUtils.logger.i18n.warning("conf.0004", jarLocation, e.getMessage());
             }
         }
+
+        for (EjbModule ejbModule : deployedJars) {
+            logger.info("Loaded EJBs: "+ejbModule.getJarLocation());
+        }
         return deployedJars;
     }
 
-    private void loadFromClasspath(FileUtils base, List<String> jarList, ClassLoader classLoader) {
+    private URL getResource(URL baseUrl, ClassLoader classLoader, String name) {
+        try {
+            String fileUrl = baseUrl.toExternalForm();
+            URL appXmlUrl = null;
+            Enumeration<URL> urls = classLoader.getResources(name);
+            while (urls.hasMoreElements()) {
+                URL url = urls.nextElement();
+                String location = url.toExternalForm();
+                location = location.replaceFirst("^jar:","");
+                if (location.startsWith(fileUrl)){
+                    appXmlUrl = url;
+                    break;
+                }
+            }
+            return appXmlUrl;
+        } catch (IOException e) {
+            throw new IllegalStateException("Bad resource in classpath.  Unable to search for entries. ",e);
+        }
+    }
+
+    private void loadFromClasspath(FileUtils base, List<String> jarList, ClassLoader classLoader, String descriptor, String type) {
         try {
-            Enumeration resources = classLoader.getResources("META-INF/ejb-jar.xml");
+            String exclude = SystemInstance.get().getProperty("openejb.deployments.classpath.exclude", "");
+            Enumeration resources = classLoader.getResources(descriptor);
             while (resources.hasMoreElements()) {
                 URL ejbJar1 = (URL) resources.nextElement();
-
+                String urlString = ejbJar1.toExternalForm();
+                if (urlString.matches(exclude)) {
+                    ConfigurationFactory.logger.info("Excluding: "+urlString);
+                    continue;
+                }
                 String path = null;
                 Deployments deployment = new Deployments();
                 if (ejbJar1.getProtocol().equals("jar")){
@@ -221,17 +370,250 @@
                     path = ejbPackage.getAbsolutePath();
                     deployment.setDir(path);
                 } else {
-                    ConfigurationFactory.logger.warning("Not loading ejbs.  Unknown protocol "+ejbJar1.getProtocol());
+                    ConfigurationFactory.logger.warning("Not loading "+type +".  Unknown protocol "+ejbJar1.getProtocol());
                     continue;
                 }
 
-                ConfigurationFactory.logger.info("Found ejb in classpath: "+path);
+                ConfigurationFactory.logger.info("Found "+type +" in classpath: "+path);
                 loadFrom(deployment, base, jarList);
             }
         } catch (IOException e1) {
             e1.printStackTrace();
-            ConfigurationFactory.logger.warning("Unable to search classpath for ejbs: Received Exception: "+e1.getClass().getName()+" "+e1.getMessage(),e1);
+            ConfigurationFactory.logger.warning("Unable to search classpath for "+type +": Received Exception: "+e1.getClass().getName()+" "+e1.getMessage(),e1);
         }
     }
 
+    public static class JarExtractor {
+
+        /**
+         * Extract the WAR file found at the specified URL into an unpacked
+         * directory structure, and return the absolute pathname to the extracted
+         * directory.
+         *
+         * @param jar URL of the web application archive to be extracted
+         *  (must start with "jar:")
+         * @param pathname Context path name for web application
+         *
+         * @exception IllegalArgumentException if this is not a "jar:" URL
+         * @exception IOException if an input/output error was encountered
+         *  during expansion
+         */
+        public static String extract(URL jar, String pathname)
+            throws IOException {
+
+            // Make sure that there is no such directory already existing
+            FileUtils base = SystemInstance.get().getBase();
+            File appBase = base.getDirectory("apps", true);
+            if (!appBase.exists() || !appBase.isDirectory()) {
+                throw new IOException("" + appBase.getAbsolutePath());
+            }
+
+            File docBase = new File(appBase, pathname);
+            if (docBase.exists()) {
+                // War file is already installed
+                return (docBase.getAbsolutePath());
+            }
+
+            // Create the new document base directory
+            docBase.mkdir();
+
+            // Extract the JAR into the new directory
+            JarURLConnection jarURLConnection = (JarURLConnection) jar.openConnection();
+            jarURLConnection.setUseCaches(false);
+            JarFile jarFile = null;
+            InputStream input = null;
+            try {
+                jarFile = jarURLConnection.getJarFile();
+                Enumeration jarEntries = jarFile.entries();
+                while (jarEntries.hasMoreElements()) {
+                    JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
+                    String name = jarEntry.getName();
+                    int last = name.lastIndexOf('/');
+                    if (last >= 0) {
+                        File parent = new File(docBase,
+                                               name.substring(0, last));
+                        parent.mkdirs();
+                    }
+                    if (name.endsWith("/")) {
+                        continue;
+                    }
+                    input = jarFile.getInputStream(jarEntry);
+
+                    File extractedFile = extract(input, docBase, name);
+                    long lastModified = jarEntry.getTime();
+                    if ((lastModified != -1) && (lastModified != 0) && (extractedFile != null)) {
+                        extractedFile.setLastModified(lastModified);
+                    }
+
+                    input.close();
+                    input = null;
+                }
+            } catch (IOException e) {
+                // If something went wrong, delete extracted dir to keep things
+                // clean
+                deleteDir(docBase);
+                throw e;
+            } finally {
+                if (input != null) {
+                    try {
+                        input.close();
+                    } catch (Throwable t) {
+                        ;
+                    }
+                    input = null;
+                }
+                if (jarFile != null) {
+                    try {
+                        jarFile.close();
+                    } catch (Throwable t) {
+                        ;
+                    }
+                    jarFile = null;
+                }
+            }
+
+            // Return the absolute path to our new document base directory
+            return (docBase.getAbsolutePath());
+
+        }
+
+
+        /**
+         * Copy the specified file or directory to the destination.
+         *
+         * @param src File object representing the source
+         * @param dest File object representing the destination
+         */
+        public static boolean copy(File src, File dest) {
+
+            boolean result = true;
+
+            String files[] = null;
+            if (src.isDirectory()) {
+                files = src.list();
+                result = dest.mkdir();
+            } else {
+                files = new String[1];
+                files[0] = "";
+            }
+            if (files == null) {
+                files = new String[0];
+            }
+            for (int i = 0; (i < files.length) && result; i++) {
+                File fileSrc = new File(src, files[i]);
+                File fileDest = new File(dest, files[i]);
+                if (fileSrc.isDirectory()) {
+                    result = copy(fileSrc, fileDest);
+                } else {
+                    FileChannel ic = null;
+                    FileChannel oc = null;
+                    try {
+                        ic = (new FileInputStream(fileSrc)).getChannel();
+                        oc = (new FileOutputStream(fileDest)).getChannel();
+                        ic.transferTo(0, ic.size(), oc);
+                    } catch (IOException e) {
+                        logger.error("Copy failed: src: "+ fileSrc +", dest: "+ fileDest, e);
+                        result = false;
+                    } finally {
+                        if (ic != null) {
+                            try {
+                                ic.close();
+                            } catch (IOException e) {
+                            }
+                        }
+                        if (oc != null) {
+                            try {
+                                oc.close();
+                            } catch (IOException e) {
+                            }
+                        }
+                    }
+                }
+            }
+            return result;
+
+        }
+
+
+        /**
+         * Delete the specified directory, including all of its contents and
+         * subdirectories recursively.
+         *
+         * @param dir File object representing the directory to be deleted
+         */
+        public static boolean delete(File dir) {
+            if (dir.isDirectory()) {
+                return deleteDir(dir);
+            } else {
+                return dir.delete();
+            }
+        }
+
+
+        /**
+         * Delete the specified directory, including all of its contents and
+         * subdirectories recursively.
+         *
+         * @param dir File object representing the directory to be deleted
+         */
+        public static boolean deleteDir(File dir) {
+
+            String files[] = dir.list();
+            if (files == null) {
+                files = new String[0];
+            }
+            for (int i = 0; i < files.length; i++) {
+                File file = new File(dir, files[i]);
+                if (file.isDirectory()) {
+                    deleteDir(file);
+                } else {
+                    file.delete();
+                }
+            }
+            return dir.delete();
+
+        }
+
+
+        /**
+         * Extract the specified input stream into the specified directory, creating
+         * a file named from the specified relative path.
+         *
+         * @param input InputStream to be copied
+         * @param docBase Document base directory into which we are extracting
+         * @param name Relative pathname of the file to be created
+         * @return A handle to the extracted File
+         *
+         * @exception IOException if an input/output error occurs
+         */
+        protected static File extract(InputStream input, File docBase, String name)
+            throws IOException {
+
+            File file = new File(docBase, name);
+            BufferedOutputStream output = null;
+            try {
+                output =
+                    new BufferedOutputStream(new FileOutputStream(file));
+                byte buffer[] = new byte[2048];
+                while (true) {
+                    int n = input.read(buffer);
+                    if (n <= 0)
+                        break;
+                    output.write(buffer, 0, n);
+                }
+            } finally {
+                if (output != null) {
+                    try {
+                        output.close();
+                    } catch (IOException e) {
+                        // Ignore
+                    }
+                }
+            }
+
+            return file;
+        }
+
+
+    }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/JaxbUnmarshaller.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/JaxbUnmarshaller.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/JaxbUnmarshaller.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/JaxbUnmarshaller.java Mon Nov  6 23:08:40 2006
@@ -18,11 +18,19 @@
 package org.apache.openejb.alt.config;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.jee.Application;
 import org.apache.openejb.util.JarUtils;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.JAXBElement;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+import javax.xml.bind.*;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.sax.SAXSource;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -153,7 +161,12 @@
         InputStream stream = null;
 
         try {
-            URL fullURL = new URL(url, xmlFile.getPath());
+            URL fullURL;
+            if (!url.toExternalForm().endsWith(xmlFile.getPath())) {
+                fullURL = new URL(url, xmlFile.getPath());
+            } else {
+                fullURL = url;
+            }
             stream = fullURL.openConnection().getInputStream();
             reader = new InputStreamReader(stream);
             return unmarshalObject(reader, file, fullURL.getPath());
@@ -173,7 +186,22 @@
 
     private Object unmarshalObject(Reader reader, String file, String jarLocation) throws OpenEJBException {
         try {
-            Object object = unmarshaller.unmarshal(reader);
+            // create a new XML parser
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setNamespaceAware(true);
+            factory.setValidating(true);
+            SAXParser parser = factory.newSAXParser();
+
+            // Create a filter to intercept events
+            NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+
+            // Be sure the filter has the JAXB content handler set (or it wont
+            // work)
+            xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+
+            SAXSource source = new SAXSource(xmlFilter, new InputSource(reader));
+
+            Object object = unmarshaller.unmarshal(source);
             if (object instanceof JAXBElement) {
                 JAXBElement element = (JAXBElement) object;
                 object = element.getValue();
@@ -182,6 +210,26 @@
         } catch (JAXBException e) {
             e.printStackTrace();
             throw new OpenEJBException(EjbJarUtils.messages.format("xml.cannotUnmarshal", file, jarLocation, e.getLocalizedMessage()));
+        } catch (ParserConfigurationException e) {
+            throw new OpenEJBException(EjbJarUtils.messages.format("xml.cannotUnmarshal", file, jarLocation, e.getLocalizedMessage()));
+        } catch (SAXException e) {
+            throw new OpenEJBException(EjbJarUtils.messages.format("xml.cannotUnmarshal", file, jarLocation, e.getLocalizedMessage()));
+        }
+    }
+
+    public static class NamespaceFilter extends XMLFilterImpl {
+
+        public NamespaceFilter(XMLReader xmlReader) {
+            super(xmlReader);
+        }
+
+        public void startElement(String arg0, String arg1, String arg2, Attributes arg3) throws SAXException {
+            if (arg0.equals("http://www.openejb.org/openejb-jar/1.1")){
+                super.startElement(arg0, arg1, arg2, arg3);
+            } else {
+                super.startElement("http://java.sun.com/xml/ns/javaee", arg1, arg2, arg3);
+            }
         }
     }
+
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/JDOManagerBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/JDOManagerBuilder.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/JDOManagerBuilder.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/JDOManagerBuilder.java Mon Nov  6 23:08:40 2006
@@ -28,6 +28,7 @@
 import org.castor.jdo.conf.TransactionManager;
 import org.exolab.castor.jdo.JDOManager;
 import org.exolab.castor.mapping.MappingException;
+import org.apache.openejb.util.Logger;
 
 import java.net.URL;
 import java.util.ArrayList;
@@ -40,6 +41,7 @@
 public class JDOManagerBuilder {
     private static final String GLOBAL_TX_DATABASE = "Global_TX_Database";
     private static final String LOCAL_TX_DATABASE = "Local_TX_Database";
+    public Logger logger = Logger.getInstance("OpenEJB", "org.apache.openejb.alt.util.resources");
 
 //    // todo replace with ConfigKeys.TRANSACTION_MANAGER_FACTORIES after upgrade to 1.0.1
 //    public static final String TRANSACTION_MANAGER_FACTORIES = "org.castor.transactionmanager.Factories";
@@ -63,7 +65,8 @@
 
     public void addMapping(URL location){
         Mapping mapping = new Mapping();
-        mapping.setHref(location.toExternalForm());
+        String mappingURI = location.toExternalForm();
+        mapping.setHref(mappingURI);
         mappings.add(mapping);
     }
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/DeploymentsFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/DeploymentsFactory.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/DeploymentsFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/spring/DeploymentsFactory.java Mon Nov  6 23:08:40 2006
@@ -106,8 +106,6 @@
         ClassLoader classLoader = (value instanceof ClassLoader) ? (ClassLoader) value : Thread.currentThread().getContextClassLoader();
         EjbJarBuilder builder = new EjbJarBuilder(classLoader);
 
-        System.out.println("DeploymentsFactory.getObject");
-
         deployments = new HashMap();
         for (EjbModule jar : deployedJars) {
             EjbJarInfo jarInfo = infoBuilder.buildInfo(jar);

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java Mon Nov  6 23:08:40 2006
@@ -37,6 +37,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Enumeration;
 
 public class Logger {
 
@@ -766,18 +767,28 @@
         }
 
         private org.apache.log4j.Logger doFallbackConfiguration() {
-            org.apache.log4j.Logger.getLogger("CastorCMP").setLevel(Level.ERROR);
-            org.apache.log4j.Logger.getLogger("org.exolab.castor").setLevel(Level.ERROR);
+            set("CastorCMP", Level.ERROR);
+            set("org.exolab.castor", Level.ERROR);
             java.util.logging.Logger.getLogger("org.exolab.castor.jdo.engine.DatabaseImpl").setLevel(java.util.logging.Level.SEVERE);
-            org.apache.log4j.Logger.getLogger("org.exolab.castor.jdo.engine.DatabaseImpl").setLevel(Level.ERROR);
+            set("org.exolab.castor.jdo.engine.DatabaseImpl", Level.ERROR);
             //org/exolab/castor.jdo.engine.DatabaseImpl
-            org.apache.log4j.Logger.getLogger("org.castor").setLevel(Level.ERROR);
-            org.apache.log4j.Logger.getLogger("org.apache.openejb").setLevel(Level.WARN);
-            org.apache.log4j.Logger.getLogger("Transaction").setLevel(Level.WARN);
-            org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("OpenEJB");
-            logger.setLevel(Level.WARN);
-            return logger;
+            set("org.castor", Level.ERROR);
+            set("org.apache.openejb", Level.WARN);
+            set("Transaction", Level.WARN);
+            set("OpenEJB.startup", Level.INFO);
+            set("OpenEJB", Level.WARN);
+            return org.apache.log4j.Logger.getLogger("OpenEJB");
         }
+
+        private void set(String category, Level level) {
+            org.apache.log4j.Logger.getLogger(category).setLevel(level);
+            Enumeration allAppenders = org.apache.log4j.Logger.getLogger(category).getAllAppenders();
+            while (allAppenders.hasMoreElements()) {
+                Object object = allAppenders.nextElement();
+                System.out.println(category +" = " + object);
+            }
+        }
+
 
     }
 }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/ApplicationTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/ApplicationTest.java?view=auto&rev=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/ApplicationTest.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/ApplicationTest.java Mon Nov  6 23:08:40 2006
@@ -0,0 +1,32 @@
+/**
+ * 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;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+
+/**
+ * To run this from your ide, set -Dopenejb.home=target/test-classes/
+ */
+public class ApplicationTest extends TestCase {
+    public static Test suite() {
+        System.setProperty("openejb.assembler", org.apache.openejb.assembler.classic.Assembler.class.getName());
+        System.setProperty("openejb.deployments.classpath", "true");
+        System.setProperty("openejb.deployments.classpath.exclude", ".*openejb-itests-beans.*");
+        return iTest.suite();
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SomeoneBrokeSurefireAndThisIsADirtyHackForItTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SomeoneBrokeSurefireAndThisIsADirtyHackForItTest.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SomeoneBrokeSurefireAndThisIsADirtyHackForItTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SomeoneBrokeSurefireAndThisIsADirtyHackForItTest.java Mon Nov  6 23:08:40 2006
@@ -37,6 +37,7 @@
 public class SomeoneBrokeSurefireAndThisIsADirtyHackForItTest extends TestCase {
     public static Test suite() {
         System.setProperty("openejb.assembler", org.apache.openejb.assembler.classic.Assembler.class.getName());
+        System.setProperty("openejb.deployments.classpath.exclude", ".*openejb-itests-app.*");
         return iTest.suite();
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssembler2Test.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssembler2Test.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssembler2Test.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssembler2Test.java Mon Nov  6 23:08:40 2006
@@ -27,6 +27,7 @@
     public static Test suite() {
         System.setProperty("openejb.assembler", org.apache.openejb.assembler.spring.Assembler.class.getName());
         System.setProperty("openejb.spring.conf", "META-INF/org.apache.openejb/spring2.xml");
+        System.setProperty("openejb.deployments.classpath.exclude", ".*openejb-itests-app.*");
         return iTest.suite();
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssemblerTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssemblerTest.java?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssemblerTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/SpringAssemblerTest.java Mon Nov  6 23:08:40 2006
@@ -26,6 +26,7 @@
     public static Test suite() {
         System.setProperty("openejb.assembler", org.apache.openejb.assembler.spring.Assembler.class.getName());
         System.setProperty("openejb.spring.conf", "META-INF/org.apache.openejb/spring.xml");
+        System.setProperty("openejb.deployments.classpath.exclude", ".*openejb-itests-app.*");
         return org.apache.openejb.iTest.suite();
     }
 }

Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-app/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-app/pom.xml?view=auto&rev=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-app/pom.xml (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-app/pom.xml Mon Nov  6 23:08:40 2006
@@ -0,0 +1,66 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>itests</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>3.0-incubating-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-itests-app</artifactId>
+  <packaging>jar</packaging>
+  <name>OpenEJB :: iTests App</name>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>generate-application-xml</goal>
+              <goal>ear</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <modules>
+            <ejbModule>
+              <groupId>org.apache.openejb</groupId>
+              <artifactId>openejb-itests-beans</artifactId>
+            </ejbModule>
+            <javaModule>
+              <groupId>org.apache.openejb</groupId>
+              <artifactId>openejb-itests-client</artifactId>
+              <includeInApplicationXml>true</includeInApplicationXml>
+            </javaModule>
+          </modules>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-ejb_3.0_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-itests-beans</artifactId>
+      <version>${pom.version}</version>
+      <type>ejb</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-itests-client</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+</project>

Modified: incubator/openejb/trunk/openejb3/itests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/pom.xml?view=diff&rev=472011&r1=472010&r2=472011
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/pom.xml Mon Nov  6 23:08:40 2006
@@ -12,5 +12,6 @@
   <modules>
     <module>openejb-itests-client</module>
     <module>openejb-itests-beans</module>
+    <module>openejb-itests-app</module>
   </modules>
 </project>