cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [4/4] git commit: [CXF-5835] Support for FileDataSource
Date Tue, 01 Jul 2014 12:38:31 GMT
[CXF-5835] Support for FileDataSource


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5b1cc920
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5b1cc920
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5b1cc920

Branch: refs/heads/master
Commit: 5b1cc9207c934d39c718f7d35395e00cdfb65383
Parents: daf87c8
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jul 1 13:37:57 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jul 1 13:37:57 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/DataSourceProvider.java   | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5b1cc920/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
index 99f6145..d2bec60 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
@@ -19,28 +19,33 @@
 
 package org.apache.cxf.jaxrs.provider;
 
+import java.io.File;
 import java.io.IOException;
 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.activation.DataHandler;
 import javax.activation.DataSource;
+import javax.activation.FileDataSource;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 @Provider
 public class DataSourceProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T>
{
-    
+    protected static final Logger LOG = LogUtils.getL7dLogger(DataSourceProvider.class);
     private boolean useDataSourceContentType;
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
@@ -51,7 +56,17 @@ public class DataSourceProvider<T> implements MessageBodyReader<T>,
MessageBodyW
                                MediaType type, 
                                MultivaluedMap<String, String> headers, InputStream
is)
         throws IOException {
-        DataSource ds = new InputStreamDataSource(is, type.toString());
+        
+        DataSource ds = null;
+        if (cls == FileDataSource.class) { 
+            File file = new BinaryDataProvider<File>().readFrom(File.class, File.class,
annotations, type, headers, is);
+            ds = new FileDataSource(file);    
+        } else if (cls == DataSource.class || cls == DataHandler.class) {
+            ds = new InputStreamDataSource(is, type.toString());
+        } else {
+            LOG.warning("Unsupported DataSource class: " + cls.getName());
+            throw ExceptionUtils.toWebApplicationException(null, null);
+        }
         return cls.cast(DataSource.class.isAssignableFrom(cls) ? ds : new DataHandler(ds));
     }
 


Mime
View raw message