cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1421392 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Thu, 13 Dec 2012 17:23:44 GMT
Author: sergeyb
Date: Thu Dec 13 17:23:43 2012
New Revision: 1421392

URL: http://svn.apache.org/viewvc?rev=1421392&view=rev
Log:
Merged revisions 1421386 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1421386 | sergeyb | 2012-12-13 17:12:05 +0000 (Thu, 13 Dec 2012) | 1 line
  
  [CXF-2701] Updating MultipartProvider to ignore InputStream if requested via the contextual
property
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1421386

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1421392&r1=1421391&r2=1421392&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Thu Dec 13 17:23:43 2012
@@ -65,6 +65,7 @@ import org.apache.cxf.jaxrs.ext.multipar
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
@@ -106,12 +107,20 @@ public class MultipartProvider extends A
         return isSupported(type, genericType, annotations, mt);
     }
     
-    private boolean isSupported(Class<?> type, Type genericType, Annotation[] annotations,

+    private boolean isSupported(Class<?> type, Type genericType, Annotation[] anns,

                                 MediaType mt) {
         if (DataHandler.class.isAssignableFrom(type) || DataSource.class.isAssignableFrom(type)
             || Attachment.class.isAssignableFrom(type) || MultipartBody.class.isAssignableFrom(type)
             || mediaTypeSupported(mt)
             || isSupportedFormDataType(type, mt)) {
+            
+            if (type == InputStream.class 
+                && AnnotationUtils.getAnnotation(anns, Multipart.class) == null
+                && MessageUtils.isTrue(mc.getContextualProperty(JAXRSUtils.DEFAULT_PROVIDERS_FOR_SIMPLE_TYPES)))
{
+                return false;
+            }
+            
+            
             return true;
         }
         return false;

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1421392&r1=1421391&r2=1421392&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Thu Dec 13 17:23:43 2012
@@ -109,6 +109,7 @@ public final class JAXRSUtils {
     public static final String ROOT_INSTANCE = "service.root.instance";
     public static final String ROOT_PROVIDER = "service.root.provider";
     public static final String DOC_LOCATION = "wadl.location";
+    public static final String DEFAULT_PROVIDERS_FOR_SIMPLE_TYPES = "defaultProviders.for.simpleTypes";
     
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1421392&r1=1421391&r2=1421392&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Thu Dec 13 17:23:43 2012
@@ -94,6 +94,17 @@ public class JAXRSMultipartTest extends 
     }
     
     @Test
+    public void testBookAsRootAttachmentInputStreamReadItself() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/istream2";
+        WebClient wc = WebClient.create(address);
+        wc.type("multipart/mixed;type=text/xml");
+        wc.accept("text/xml");
+        
+        Book book = wc.post(new Book("CXF in Action - 2", 12345L), Book.class);
+        assertEquals(432L, book.getId());
+    }
+    
+    @Test
     public void testBookAsMessageContextDataHandler() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/mchandlers";
         doAddBook(address, "attachmentData", 200);               

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java?rev=1421392&r1=1421391&r2=1421392&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
Thu Dec 13 17:23:43 2012
@@ -19,12 +19,14 @@
 
 package org.apache.cxf.systest.jaxrs;
 
-import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.cxf.attachment.AttachmentDeserializer;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
     
 
@@ -35,9 +37,11 @@ public class MultipartServer extends Abs
     protected void run() {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setResourceClasses(MultipartStore.class);
-        sf.setProperties(Collections.<String, Object>singletonMap(
-                AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
-                String.valueOf(1024 * 10)));
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, String.valueOf(1024 * 10));
+        props.put(JAXRSUtils.DEFAULT_PROVIDERS_FOR_SIMPLE_TYPES, "true");
+        sf.setProperties(props);
         //default lifecycle is per-request, change it to singleton
         sf.setResourceProvider(MultipartStore.class,
                                new SingletonResourceProvider(new MultipartStore()));

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1421392&r1=1421391&r2=1421392&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Thu Dec 13 17:23:43 2012
@@ -299,11 +299,24 @@ public class MultipartStore {
     @POST
     @Path("/books/istream")
     @Produces("text/xml")
-    public Response addBookFromInputStream(InputStream is) throws Exception {
+    public Response addBookFromInputStream(@Multipart("rootPart") InputStream is) throws
Exception {
         return readBookFromInputStream(is);
     }
     
     @POST
+    @Path("/books/istream2")
+    @Produces("text/xml")
+    public Book addBookFromInputStreamReadItself(InputStream is) throws Exception {
+        
+        String body = IOUtils.readStringFromStream(is);
+        if (!body.trim().startsWith("--")) {
+            throw new RuntimeException();
+        }
+        
+        return new Book("432", 432L);
+    }
+    
+    @POST
     @Path("/books/dsource")
     @Produces("text/xml")
     public Response addBookFromDataSource(DataSource ds) throws Exception {



Mime
View raw message