Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D95710CFF for ; Tue, 1 Jul 2014 12:40:27 +0000 (UTC) Received: (qmail 96557 invoked by uid 500); 1 Jul 2014 12:40:27 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 96493 invoked by uid 500); 1 Jul 2014 12:40:27 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 96483 invoked by uid 99); 1 Jul 2014 12:40:27 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jul 2014 12:40:27 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C0E5699106D; Tue, 1 Jul 2014 12:40:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <5502aafc74a14cb3b3f3f9faafb1cf81@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: [CXF-5835] Support for FileDataSource Date: Tue, 1 Jul 2014 12:40:26 +0000 (UTC) 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 Authored: Tue Jul 1 13:37:57 2014 +0100 Committer: Sergey Beryozkin 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 implements MessageBodyReader, MessageBodyWriter { - + 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 implements MessageBodyReader, MessageBodyW MediaType type, MultivaluedMap headers, InputStream is) throws IOException { - DataSource ds = new InputStreamDataSource(is, type.toString()); + + DataSource ds = null; + if (cls == FileDataSource.class) { + File file = new BinaryDataProvider().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)); }