You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/07/01 14:40:26 UTC
git commit: [CXF-5835] Support for FileDataSource
Repository: cxf
Updated Branches:
refs/heads/2.7.x-fixes e33448ad1 -> c296f5069
[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/c296f506
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c296f506
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c296f506
Branch: refs/heads/2.7.x-fixes
Commit: c296f50698fef48bd3fc5bc52e4114325cb71384
Parents: e33448a
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Tue Jul 1 13:37:57 2014 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Tue Jul 1 13:40:01 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/c296f506/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 4fa5469..7e40e98 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));
}