cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r447344 - in /incubator/cxf/trunk/rt/databinding/jaxb/src: main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java test/java/org/apache/cxf/jaxb/resources/emptyReq.xml
Date Mon, 18 Sep 2006 09:44:15 GMT
Author: jliu
Date: Mon Sep 18 02:44:14 2006
New Revision: 447344

URL: http://svn.apache.org/viewvc?view=rev&rev=447344
Log:
CXF-14
* Make XMLMessageDataReader tolerates empty input stream in order to deal with HTTP GET. Empty
input stream is considered as a valid input, no exceptions should be thrown in this case.

Added:
    incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/resources/emptyReq.xml
Modified:
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java?view=diff&rev=447344&r1=447343&r2=447344
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/XMLMessageDataReader.java
Mon Sep 18 02:44:14 2006
@@ -42,11 +42,11 @@
 
 public class XMLMessageDataReader implements DataReader<XMLMessage> {
     final JAXBDataReaderFactory factory;
-    
+
     public XMLMessageDataReader(JAXBDataReaderFactory cb) {
         factory = cb;
     }
-    
+
     public Object read(XMLMessage input) {
         // Complete
         return null;
@@ -57,37 +57,46 @@
         return null;
     }
 
+    /**
+     * @param name
+     * @param input
+     * @param type
+     * @return
+     */
     public Object read(QName name, XMLMessage input, Class type) {
         Object obj = null;
         InputStream is = input.getContent(InputStream.class);
-        if (is == null) {
-            // TODO LOG ERROR here
-            return null;
-        }
+
         try {
+            // Tolerate empty InputStream in order to deal with HTTP GET
+            if (is == null || is.available() == 0) {
+                // TODO LOG ERROR here
+                return null;
+            }
+
             // Processing Souce type
             if (DOMSource.class.isAssignableFrom(type)) {
                 Document doc = XMLUtils.parse(is);
-                obj = new DOMSource(doc);               
-            } else if (SAXSource.class.isAssignableFrom(type)) {                
-                obj = new SAXSource(new InputSource(is));           
+                obj = new DOMSource(doc);
+            } else if (SAXSource.class.isAssignableFrom(type)) {
+                obj = new SAXSource(new InputSource(is));
             } else if (StreamSource.class.isAssignableFrom(type) || Source.class.isAssignableFrom(type))
{
                 obj = new StreamSource(is);
             }
-            
-            // Processing DataSource type            
+
+            // Processing DataSource type
             if (MimePartDataSource.class.isAssignableFrom(type)) {
                 // Support JavaMail MimePart DataSource type
                 obj = new MimePartDataSource(new MimeBodyPart(is));
-            } else if (ByteArrayDataSource.class.isAssignableFrom(type) 
-                || DataSource.class.isAssignableFrom(type)) {
+            } else if (ByteArrayDataSource.class.isAssignableFrom(type)
+                       || DataSource.class.isAssignableFrom(type)) {
                 // Support JavaMail ByteArrayDataSource
                 obj = new ByteArrayDataSource(is, null);
-            }            
+            }
         } catch (Exception ex) {
             ex.printStackTrace();
         }
-        return obj;        
+        return obj;
     }
 
 }

Added: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java?view=auto&rev=447344
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
(added)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
Mon Sep 18 02:44:14 2006
@@ -0,0 +1,79 @@
+/**
+ * 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.cxf.jaxb.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.message.XMLMessage;
+
+public class XMLMessageDataReaderTest extends TestCase {
+
+    XMLMessageDataReader reader;
+
+    public void setUp() throws Exception {
+        reader = new XMLMessageDataReader(null);
+        assertNotNull(reader);
+    }
+
+    public void tearDown() throws IOException {
+    }
+
+    public void testReadBare() throws Exception {
+        String expected = "<ns4:tickerSymbol>CXF</ns4:tickerSymbol>";
+        InputStream is = getTestStream("../resources/sayHiDocLitBareReq.xml");
+        assertNotNull(is);
+
+        MessageImpl msg = new MessageImpl();
+        msg.setContent(InputStream.class, is);
+        XMLMessage xmlMsg = new XMLMessage(msg);
+
+        Object source = reader.read(null, xmlMsg, DOMSource.class);
+        assertNotNull(source);
+        System.out.println(XMLUtils.toString((Source)source));
+        assertTrue(XMLUtils.toString((Source)source).contains(expected));
+    }
+
+    // XMLMessageDataReader needs to tolerate empty input stream
+    // in order to deal with HTTP GET, no exceptions should be thrown.
+    public void testReadEmptyInputStream() throws Exception {
+        InputStream is = getTestStream("../resources/emptyReq.xml");
+        assertNotNull(is);
+
+        MessageImpl msg = new MessageImpl();
+        msg.setContent(InputStream.class, is);
+        XMLMessage xmlMsg = new XMLMessage(msg);
+
+        Object source = reader.read(null, xmlMsg, DOMSource.class);
+        assertNull(source);
+    }
+
+    private InputStream getTestStream(String resource) {
+        return getClass().getResourceAsStream(resource);
+    }
+
+}

Added: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/resources/emptyReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/resources/emptyReq.xml?view=auto&rev=447344
==============================================================================
    (empty)



Mime
View raw message