Author: fmui
Date: Thu Jun 10 21:36:17 2010
New Revision: 953470

URL: http://svn.apache.org/viewvc?rev=953470&view=rev
Log:
AtomPub server: handle empty input streams more gracefully

Modified:
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java

Modified: 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
URL: 
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java?rev=953470&r1=953469&r2=953470&view=diff
==============================================================================
--- 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
 (original)
+++ 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
 Thu Jun 10 21:36:17 2010
@@ -30,6 +30,7 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -493,7 +494,11 @@ public class AtomEntryParser {
 
     private boolean next(XMLStreamReader parser) throws Exception {
         if (parser.hasNext()) {
-            parser.next();
+            try {
+                parser.next();
+            } catch (XMLStreamException e) {
+                return false;
+            }
             return true;
         }
 

Modified: 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java
URL: 
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java?rev=953470&r1=953469&r2=953470&view=diff
==============================================================================
--- 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java
 (original)
+++ 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/AtomEntryParserTest.java
 Thu Jun 10 21:36:17 2010
@@ -20,6 +20,7 @@ package org.apache.chemistry.opencmis.se
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
@@ -34,9 +35,6 @@ import org.junit.Test;
 
 /**
  * AtomEntryParser test.
- * 
- * @author <a href="mailto:[email protected]";>Florian M&uuml;ller</a>
- * 
  */
 public class AtomEntryParserTest {
 
@@ -173,6 +171,7 @@ public class AtomEntryParserTest {
     public void testAtomTitle() throws Exception {
         AtomEntryParser aep = new AtomEntryParser(new 
ByteArrayInputStream(ATOM_ENTRY_NAME.getBytes()));
 
+        assertNotNull(aep);
         assertNotNull(aep.getObject());
         assertNotNull(aep.getObject().getProperties());
         assertNotNull(aep.getObject().getProperties().getProperties());
@@ -184,6 +183,28 @@ public class AtomEntryParserTest {
         assertEquals("atom.title", nameProperty.getFirstValue());
     }
 
+    @Test
+    public void testNullStream() throws Exception {
+        AtomEntryParser aep = new AtomEntryParser(null);
+
+        assertNotNull(aep);
+        assertNull(aep.getId());
+        assertNull(aep.getObject());
+        assertNull(aep.getContentStream());
+        assertNull(aep.getProperties());
+    }
+
+    @Test
+    public void testEmptyStream() throws Exception {
+        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(new 
byte[0]));
+
+        assertNotNull(aep);
+        assertNull(aep.getId());
+        assertNull(aep.getObject());
+        assertNull(aep.getContentStream());
+        assertNull(aep.getProperties());
+    }
+
     private byte[] parse(byte[] entry) throws Exception {
         AtomEntryParser aep = new AtomEntryParser(new 
ByteArrayInputStream(entry));
         ContentStream contentStream = aep.getContentStream();


Reply via email to