cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1387148 - /cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java
Date Tue, 18 Sep 2012 13:33:43 GMT
Author: sergeyb
Date: Tue Sep 18 13:33:43 2012
New Revision: 1387148

URL: http://svn.apache.org/viewvc?rev=1387148&view=rev
Log:
Making it simpler customize Abdera writers, actual change missed

Modified:
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java?rev=1387148&r1=1387147&r2=1387148&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/atom/AbstractAtomProvider.java
Tue Sep 18 13:33:43 2012
@@ -24,7 +24,9 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.logging.Logger;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -34,10 +36,12 @@ import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.writer.Writer;
+import org.apache.cxf.common.logging.LogUtils;
 
 public abstract class AbstractAtomProvider<T extends Element> 
     implements MessageBodyWriter<T>, MessageBodyReader<T> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractAtomProvider.class);
     private static final Abdera ATOM_ENGINE = new Abdera();
         
     private boolean formattedOutput;
@@ -50,18 +54,29 @@ public abstract class AbstractAtomProvid
                         MediaType mt, MultivaluedMap<String, Object> headers, OutputStream
os) 
         throws IOException {
         if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mt)) {
-            Writer w = ATOM_ENGINE.getWriterFactory().getWriter("json");
+            Writer w = createWriter("json");
+            if (w == null) {
+                throw new WebApplicationException(415);
+            }
             element.writeTo(w, os);   
         } else if (formattedOutput) {
-            Writer w = ATOM_ENGINE.getWriterFactory().getWriter("prettyxml");
-            element.writeTo(w, os);
+            Writer w = createWriter("prettyxml");
+            if (w != null) {
+                element.writeTo(w, os);
+            } else {
+                element.writeTo(os);
+            }
         } else {
             element.writeTo(os);
         }
     }
 
     protected Writer createWriter(String writerName) {
-        return ATOM_ENGINE.getWriterFactory().getWriter(writerName);
+        Writer w = ATOM_ENGINE.getWriterFactory().getWriter(writerName);
+        if (w == null) {
+            LOG.fine("Atom writer \"" + writerName + "\" is not available");
+        }
+        return w;
     }
     
     public T readFrom(Class<T> clazz, Type t, Annotation[] a, MediaType mt, 



Mime
View raw message