cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1502203 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
Date Thu, 11 Jul 2013 12:22:54 GMT
Author: sergeyb
Date: Thu Jul 11 12:22:53 2013
New Revision: 1502203

URL: http://svn.apache.org/r1502203
Log:
Merged revisions 1502200 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1502200 | sergeyb | 2013-07-11 13:18:44 +0100 (Thu, 11 Jul 2013) | 1 line
  
  Updates to caching JAXRS providers to handle lists of delegating providers, example, when
XML and JSON providers are configured alongside it
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1502200

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java?rev=1502203&r1=1502202&r2=1502203&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
Thu Jul 11 12:22:53 2013
@@ -23,6 +23,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.NotAcceptableException;
 import javax.ws.rs.WebApplicationException;
@@ -35,16 +37,24 @@ import javax.ws.rs.ext.Provider;
 public class CachingMessageBodyReader<T> extends AbstractCachingMessageProvider<T>
     implements MessageBodyReader<T> {
     
-    private MessageBodyReader<T> delegatingReader;
+    private List<MessageBodyReader<T>> delegatingReaders;
     
     public boolean isReadable(Class<?> type, Type gType, Annotation[] anns, MediaType
mt) {
-        if (delegatingReader != null) {
-            return delegatingReader.isReadable(type, gType, anns, mt);
+        if (delegatingReaders != null) {
+            return getDelegatingReader(type, gType, anns, mt) != null;
         } else {
             return isProviderKeyNotSet();
         }
     }
 
+    private MessageBodyReader<T> getDelegatingReader(Class<?> type, Type gType,
Annotation[] anns, MediaType mt) {
+        for (MessageBodyReader<T> reader: delegatingReaders) {
+            if (reader.isReadable(type, gType, anns, mt)) {
+                return reader;
+            }
+        }
+        return null;
+    }
     
     public T readFrom(Class<T> type, Type gType, Annotation[] anns, MediaType mt,
                         MultivaluedMap<String, String> theheaders, InputStream is)

@@ -56,8 +66,8 @@ public class CachingMessageBodyReader<T>
     
     
     protected MessageBodyReader<T> getReader(Class<?> type, Type gType, Annotation[]
anns, MediaType mt) {
-        if (delegatingReader != null) {
-            return delegatingReader;
+        if (delegatingReaders != null) {
+            return getDelegatingReader(type, gType, anns, mt);
         }
         MessageBodyReader<T> r = null;
         
@@ -79,4 +89,12 @@ public class CachingMessageBodyReader<T>
         return r;
     }
 
+    public void setDelegatingReader(MessageBodyReader<T> reader) {
+        this.delegatingReaders = Collections.singletonList(reader);
+    }
+    
+    public void setDelegatingReaders(List<MessageBodyReader<T>> readers) {
+        this.delegatingReaders = readers;
+    }
+
 }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java?rev=1502203&r1=1502202&r2=1502203&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
Thu Jul 11 12:22:53 2013
@@ -23,6 +23,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
@@ -35,20 +37,28 @@ import javax.ws.rs.ext.Provider;
 public class CachingMessageBodyWriter<T> extends AbstractCachingMessageProvider<T>
     implements MessageBodyWriter<T> {
     
-    private MessageBodyWriter<T> delegatingWriter;
+    private List<MessageBodyWriter<T>> delegatingWriters;
     
     public long getSize(T t, Class<?> type, Type gType, Annotation[] anns, MediaType
mediaType) {
         return -1;
     }
 
     public boolean isWriteable(Class<?> type, Type gType, Annotation[] anns, MediaType
mt) {
-        if (delegatingWriter != null) {
-            return delegatingWriter.isWriteable(type, gType, anns, mt);
+        if (delegatingWriters != null) {
+            return getDelegatingWriter(type, gType, anns, mt) != null;
         } else {
             return isProviderKeyNotSet();
         }
     }
 
+    private MessageBodyWriter<T> getDelegatingWriter(Class<?> type, Type gType,
Annotation[] anns, MediaType mt) {
+        for (MessageBodyWriter<T> writer: delegatingWriters) {
+            if (writer.isWriteable(type, gType, anns, mt)) {
+                return writer;
+            }
+        }
+        return null;
+    }
     
     public void writeTo(T obj, Class<?> type, Type gType, Annotation[] anns, MediaType
mt,
                         MultivaluedMap<String, Object> theheaders, OutputStream os)

@@ -59,8 +69,8 @@ public class CachingMessageBodyWriter<T>
     
     
     protected MessageBodyWriter<T> getWriter(Class<?> type, Type gType, Annotation[]
anns, MediaType mt) {
-        if (delegatingWriter != null) {
-            return delegatingWriter;
+        if (delegatingWriters != null) {
+            return getDelegatingWriter(type, gType, anns, mt);
         }
         MessageBodyWriter<T> w = null;
         
@@ -81,4 +91,12 @@ public class CachingMessageBodyWriter<T>
         }
         return w;
     }
+    
+    public void setDelegatingWriter(MessageBodyWriter<T> writer) {
+        this.delegatingWriters = Collections.singletonList(writer);
+    }
+    
+    public void setDelegatingWriters(List<MessageBodyWriter<T>> writers) {
+        this.delegatingWriters = writers;
+    }
 }



Mime
View raw message