cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1382763 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java test/java/org/apache/cxf/jaxrs/provider/DataSourceProviderTest.java
Date Mon, 10 Sep 2012 11:36:25 GMT
Author: sergeyb
Date: Mon Sep 10 11:36:25 2012
New Revision: 1382763

URL: http://svn.apache.org/viewvc?rev=1382763&view=rev
Log:
Updating DataSourceProvider to ignore DataSource content type property by default

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataSourceProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java?rev=1382763&r1=1382762&r2=1382763&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
Mon Sep 10 11:36:25 2012
@@ -40,6 +40,8 @@ import org.apache.cxf.jaxrs.ext.multipar
 @Provider
 public class DataSourceProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T>
{
     
+    private boolean useDataSourceContentType;
+    
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
         return isSupported(type, mt);
     }
@@ -71,7 +73,9 @@ public class DataSourceProvider<T> imple
         throws IOException {
         DataSource ds = DataSource.class.isAssignableFrom(cls) 
             ? (DataSource)src : ((DataHandler)src).getDataSource();
-        setContentTypeIfNeeded(type, headers, ds.getContentType());
+        if (useDataSourceContentType) {    
+            setContentTypeIfNeeded(type, headers, ds.getContentType());
+        }
         IOUtils.copy(ds.getInputStream(), os);
     }
     
@@ -82,6 +86,10 @@ public class DataSourceProvider<T> imple
             headers.putSingle("Content-Type", ct);
         }
     }
+
+    public void setUseDataSourceContentType(boolean useDataSourceContentType) {
+        this.useDataSourceContentType = useDataSourceContentType;
+    }
     
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataSourceProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataSourceProviderTest.java?rev=1382763&r1=1382762&r2=1382763&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataSourceProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataSourceProviderTest.java
Mon Sep 10 11:36:25 2012
@@ -88,12 +88,13 @@ public class DataSourceProviderTest exte
     @Test
     public void testWriteDataSourceWithDiffCT() throws Exception {
         DataSourceProvider<DataSource> p = new DataSourceProvider<DataSource>();
+        p.setUseDataSourceContentType(true);
         DataSource ds = new InputStreamDataSource(new ByteArrayInputStream("image".getBytes()),

                                                   "image/png"); 
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         MultivaluedMap<String, Object> outHeaders = new MetadataMap<String, Object>();
         p.writeTo(ds, DataSource.class, DataSource.class, new Annotation[]{}, 
-                   MediaType.valueOf("image/bar"), outHeaders, os);
+                   MediaType.valueOf("image/jpeg"), outHeaders, os);
         assertEquals("image", os.toString());
         assertEquals("image/png", outHeaders.getFirst("Content-Type"));
     }



Mime
View raw message