cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1302999 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider: AbstractJAXBProvider.java JAXBElementProvider.java
Date Tue, 20 Mar 2012 17:02:39 GMT
Author: sergeyb
Date: Tue Mar 20 17:02:39 2012
New Revision: 1302999

URL: http://svn.apache.org/viewvc?rev=1302999&view=rev
Log:
[CXF-4184] Also updating JAXB provider to check for Reader/Writer instances

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1302999&r1=1302998&r2=1302999&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Tue Mar 20 17:02:39 2012
@@ -187,7 +187,7 @@ public abstract class AbstractJAXBProvid
         }
     }
     
-    protected <X> X getStaxHandlerFromCurrentMessage(Class<X> staxCls) {
+    protected <X> X getStreamHandlerFromCurrentMessage(Class<X> staxCls) {
         Message m = PhaseInterceptorChain.getCurrentMessage();
         if (m != null) {
             return staxCls.cast(m.getContent(staxCls));

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1302999&r1=1302998&r2=1302999&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Tue Mar 20 17:02:39 2012
@@ -22,6 +22,8 @@ package org.apache.cxf.jaxrs.provider;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.Arrays;
@@ -222,7 +224,7 @@ public class JAXBElementProvider<T> exte
         }
         
         if (reader == null && is == null) {
-            reader = getStaxHandlerFromCurrentMessage(XMLStreamReader.class);
+            reader = getStreamHandlerFromCurrentMessage(XMLStreamReader.class);
         }
         
         reader = createTransformReaderIfNeeded(reader, is);
@@ -238,7 +240,16 @@ public class JAXBElementProvider<T> exte
     protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,
MediaType mt) 
         throws JAXBException {
         // Try to create the read before unmarshalling the stream
-        return unmarshaller.unmarshal(StaxUtils.createXMLStreamReader(is));
+        if (is == null) {
+            Reader reader = getStreamHandlerFromCurrentMessage(Reader.class);
+            if (reader == null) {
+                LOG.severe("No InputStream, Reader, or XMStreamReader is available");
+                throw new WebApplicationException(500);
+            }
+            return unmarshaller.unmarshal(StaxUtils.createXMLStreamReader(reader));
+        } else {
+            return unmarshaller.unmarshal(StaxUtils.createXMLStreamReader(is));
+        }
     }
 
     protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,
MediaType mt) 
@@ -530,14 +541,24 @@ public class JAXBElementProvider<T> exte
         } 
         
         if (writer == null && os == null) {
-            writer = getStaxHandlerFromCurrentMessage(XMLStreamWriter.class);
+            writer = getStreamHandlerFromCurrentMessage(XMLStreamWriter.class);
         }
         return createTransformWriterIfNeeded(writer, os);
     }
     
     protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, MediaType
mt) 
         throws Exception {
-        ms.marshal(obj, os);
+        if (os == null) {
+            Writer writer = getStreamHandlerFromCurrentMessage(Writer.class);
+            if (writer == null) {
+                LOG.severe("No OutputStream, Writer, or XMStreamWriter is available");
+                throw new WebApplicationException(500);
+            }
+            ms.marshal(obj, writer);
+            writer.flush();
+        } else {
+            ms.marshal(obj, os);
+        }
     }
     
     protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer, MediaType
mt) 



Mime
View raw message