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/09/30 14:24:53 UTC

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

Author: rmannibucau
Date: Sun Sep 30 12:24:52 2012
New Revision: 1392015

URL: http://svn.apache.org/viewvc?rev=1392015&view=rev
Log:
workaround for embedded case to match @WebXXX files (in embedded case we got it from the classpath 'file' instead of web-inf/X)

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1392015&r1=1392014&r2=1392015&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Sun Sep 30 12:24:52 2012
@@ -5178,13 +5178,22 @@ public class AnnotationDeployer implemen
         final Map<String, Set<String>> classes = new HashMap<String, Set<String>>(found.size());
         for (Annotated<Class<?>> clazz : found) {
             final Class<?> loadedClass = clazz.get();
-            final URL url = classLocation(loadedClass);
+
+            // url of the jar/folder containing the class
+            URL url;
+            try {
+                url = JarLocation.jarLocation(loadedClass).toURI().toURL();
+            } catch (MalformedURLException e) {
+                url = classLocation(loadedClass);
+            }
             Set<String> list = classes.get(url);
             if (list == null) {
                 list = new HashSet<String>();
                 classes.put(url.toExternalForm(), list);
             }
-            list.add(loadedClass.getName());
+
+            // saving class url
+            list.add(classLocation(loadedClass).toExternalForm());
         }
         return classes;
     }

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java?rev=1392015&r1=1392014&r2=1392015&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java (original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java Sun Sep 30 12:24:52 2012
@@ -36,6 +36,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -123,11 +124,6 @@ public class OpenEJBContextConfig extend
     }
 
     @Override
-    protected void parseWebXml(InputSource source, WebXml dest, boolean fragment) {
-        super.parseWebXml(source, dest, fragment);
-    }
-
-    @Override
     protected void processAnnotationsFile(File file, WebXml fragment, boolean handlesTypesOnly) {
         final WebAppInfo webAppInfo = info.get();
         if (webAppInfo == null) {
@@ -137,13 +133,12 @@ public class OpenEJBContextConfig extend
 
         for (ClassListInfo webAnnotated : webAppInfo.webAnnotatedClasses) {
             try {
-                final URL url = new URL(webAnnotated.name);
-                final File classAsFile = URLs.toFile(new URL(webAnnotated.name));
-                if (!isIncludedIn(file, classAsFile)) {
+                final File classContainerAsFile = URLs.toFile(new URL(webAnnotated.name));
+                if (!isIncludedIn(file, classContainerAsFile)) {
                     continue;
                 }
 
-                internalProcessAnnotationsStream(url, fragment, handlesTypesOnly);
+                internalProcessAnnotationsStream(webAnnotated.list, fragment, handlesTypesOnly);
             } catch (MalformedURLException e) {
                 throw new IllegalArgumentException(e);
             } catch (IOException e) {
@@ -162,14 +157,13 @@ public class OpenEJBContextConfig extend
 
         for (ClassListInfo webAnnotated : webAppInfo.webAnnotatedClasses) {
             try {
-                final URL url = new URL(webAnnotated.name);
-                final File classAsFile = URLs.toFile(new URL(webAppInfo.webAnnotatedClasses.iterator().next().name));
+                final File classContainerAsFile = URLs.toFile(new URL(webAnnotated.name));
                 final File currentUrlAsFile = URLs.toFile(currentUrl);
-                if (!currentUrlAsFile.equals(classAsFile)) {
+                if (!isIncludedIn(currentUrlAsFile, classContainerAsFile)) {
                     continue;
                 }
 
-                internalProcessAnnotationsStream(url, fragment, handlesTypeOnly);
+                internalProcessAnnotationsStream(webAnnotated.list, fragment, handlesTypeOnly);
             } catch (MalformedURLException e) {
                 throw new IllegalArgumentException(e);
             } catch (IOException e) {
@@ -178,28 +172,34 @@ public class OpenEJBContextConfig extend
         }
     }
 
-    private void internalProcessAnnotationsStream(final URL url, final WebXml fragment, final boolean handlesTypeOnly) {
-        InputStream is = null;
-        try {
-            is = url.openStream();
-            processAnnotationsStream(is, fragment, handlesTypeOnly);
-        } catch (MalformedURLException e) {
-            throw new IllegalArgumentException(e);
-        } catch (IOException e) {
-            throw new IllegalArgumentException(e);
-        } finally {
-            IO.close(is);
+    private void internalProcessAnnotationsStream(final Collection<String> urls, final WebXml fragment, final boolean handlesTypeOnly) {
+        for (String url : urls) {
+            InputStream is = null;
+            try {
+                is = new URL(url).openStream();
+                processAnnotationsStream(is, fragment, handlesTypeOnly);
+            } catch (MalformedURLException e) {
+                throw new IllegalArgumentException(e);
+            } catch (IOException e) {
+                throw new IllegalArgumentException(e);
+            } finally {
+                IO.close(is);
+            }
         }
     }
 
     private static boolean isIncludedIn(final File file, final File classAsFile) {
         File current = classAsFile;
+        boolean webInf = false;
         while (current != null && current.exists()) {
             if (current.equals(file)) {
                 return true;
             }
+            if (current.getName().equals("WEB-INF")) {
+                webInf = true; // if class loaded from JVM classloader we'll not find it in the war
+            }
             current = current.getParentFile();
         }
-        return false;
+        return !webInf;
     }
 }

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java?rev=1392015&r1=1392014&r2=1392015&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java (original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java Sun Sep 30 12:24:52 2012
@@ -224,7 +224,23 @@ public class TomcatJndiBuilder {
             try {
                 root.bind("global", SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup("global"));
             } catch (NamingException e) {
-                e.printStackTrace();
+                // bind only global bindings
+                if (webContext != null && webContext.getBindings() != null) {
+                    for (Map.Entry<String, Object> entry : webContext.getBindings().entrySet()) {
+                        try {
+                            final String key = entry.getKey();
+                            if (!key.startsWith("global/")) {
+                                continue;
+                            }
+
+                            final Object value = normalize(entry.getValue());
+                            Contexts.createSubcontexts(root, key);
+                            root.rebind(key, value);
+                        } catch (NamingException ignored) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
             }
         }