Author: dblevins
Date: Thu Sep  9 05:36:59 2010
New Revision: 995317

URL: http://svn.apache.org/viewvc?rev=995317&view=rev
Log:
OPENEJB-1353: Be more tolerant of truly empty beans.xml and ejb-jar.xml

Modified:
    
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/resources/cdi-suite.xml

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=995317&r1=995316&r2=995317&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
 Thu Sep  9 05:36:59 2010
@@ -54,6 +54,7 @@ import javax.xml.parsers.SAXParserFactor
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -363,6 +364,7 @@ public class ReadDescriptors implements 
 
     public static Beans readBeans(URL url) throws OpenEJBException {
         try {
+            if (isEmptyBeansXml(url)) return new Beans();
             return (Beans) JaxbJavaee.unmarshalJavaee(Beans.class, 
url.openStream());
         } catch (SAXException e) {
             throw new OpenEJBException("Cannot parse the beans.xml file: " + 
url.toExternalForm(), e);
@@ -376,7 +378,8 @@ public class ReadDescriptors implements 
     }
 
     private static boolean isEmptyEjbJar(URL url) throws IOException, 
ParserConfigurationException, SAXException {
-        InputSource inputSource = new InputSource(url.openStream());
+        final LengthInputStream in = new LengthInputStream(url.openStream());
+        InputSource inputSource = new InputSource(in);
 
         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setNamespaceAware(true);
@@ -395,7 +398,33 @@ public class ReadDescriptors implements 
             });
             return true;
         } catch (SAXException e) {
-            return false;
+            return in.getLength() == 0;
+        }
+    }
+
+    private static boolean isEmptyBeansXml(URL url) throws IOException, 
ParserConfigurationException, SAXException {
+
+        final LengthInputStream in = new LengthInputStream(url.openStream());
+        InputSource inputSource = new InputSource(in);
+
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setValidating(false);
+        SAXParser parser = factory.newSAXParser();
+
+        try {
+            parser.parse(inputSource, new DefaultHandler(){
+                public void startElement(String uri, String localName, String 
qName, Attributes att) throws SAXException {
+                    if (!localName.equals("beans")) throw new 
SAXException(localName);
+                }
+
+                public InputSource resolveEntity(String publicId, String 
systemId) throws IOException, SAXException {
+                    return new InputSource(new ByteArrayInputStream(new 
byte[0]));
+                }
+            });
+            return true;
+        } catch (SAXException e) {
+            return in.getLength() == 0;
         }
     }
 
@@ -579,4 +608,36 @@ public class ReadDescriptors implements 
         }
     }
 
+    private static class LengthInputStream extends FilterInputStream {
+        private long length;
+
+        public LengthInputStream(InputStream in) throws IOException {
+            super(in);
+        }
+
+        @Override
+        public int read() throws IOException {
+            final int i = super.read();
+            if (i > 0) length++;
+            return i;
+        }
+
+        @Override
+        public int read(byte[] b) throws IOException {
+            final int i = super.read(b);
+            if (i > 0) length += i;
+            return i;
+        }
+
+        @Override
+        public int read(byte[] b, int off, int len) throws IOException {
+            final int i = super.read(b, off, len);
+            if (i > 0) length += i;
+            return i;
+        }
+
+        public long getLength() {
+            return length;
+        }
+    }
 }

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/test/resources/cdi-suite.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/resources/cdi-suite.xml?rev=995317&r1=995316&r2=995317&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/resources/cdi-suite.xml 
(original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/resources/cdi-suite.xml 
Thu Sep  9 05:36:59 2010
@@ -4,15 +4,15 @@
 
 <suite name="CDI TCK" verbose="0">
   <test name="CDI TCK">
-    <!--<method-selectors>-->
-    <!--<method-selector>-->
-    <!--<selector-class name=" org.apache.openejb.cdi.tck.TestMethodSelector" 
/>-->
-    <!--</method-selector>-->
-    <!--</method-selectors>-->
+    <method-selectors>
+    <method-selector>
+    <selector-class name="org.jboss.jsr299.tck.impl.WebProfileMethodSelector" 
/>
+    </method-selector>
+    </method-selectors>
     <packages>
-      <!--<package name="org.jboss.jsr299.tck.tests.*" />-->
-      <!--<package name="org.jboss.jsr299.tck.interceptors.tests.*" />-->
-      <package name="org.jboss.jsr299.tck.tests.interceptors.definition.*"/>
+      <package name="org.jboss.jsr299.tck.tests.*" />
+      <package name="org.jboss.jsr299.tck.interceptors.tests.*" />
+      <!--<package 
name="org.jboss.jsr299.tck.tests.interceptors.definition.*"/>-->
     </packages>
     <classes>
       <!--<class 
name="org.jboss.jsr299.tck.tests.decorators.invocation.observer.DecoratorInvocationTest">-->


Reply via email to