cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1355465 - in /cxf/branches/2.6.x-fixes: ./ api/src/main/java/org/apache/cxf/attachment/ api/src/main/java/org/apache/cxf/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ systests/jaxrs/src/test/java/org/apache...
Date Fri, 29 Jun 2012 16:41:29 GMT
Author: sergeyb
Date: Fri Jun 29 16:41:27 2012
New Revision: 1355465

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

........
  r1355462 | sergeyb | 2012-06-29 17:36:49 +0100 (Fri, 29 Jun 2012) | 1 line
  
  [CXF-4348] Ignoring optional multipart media type parameters when possible
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentOutputInterceptor.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1355462

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

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java?rev=1355465&r1=1355464&r2=1355465&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
Fri Jun 29 16:41:27 2012
@@ -31,10 +31,14 @@ import java.util.List;
 import java.util.Map;
 
 import javax.activation.DataHandler;
+
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
 
 public class AttachmentSerializer {
+    // http://tools.ietf.org/html/rfc2387
+    private static final String DEFAULT_MULTIPART_TYPE = "multipart/related";
+    
     private Message message;
     private String bodyBoundary;
     private OutputStream out;
@@ -43,15 +47,19 @@ public class AttachmentSerializer {
     private String multipartType;
     private Map<String, List<String>> rootHeaders = Collections.emptyMap();
     private boolean xop = true;
+    private boolean writeOptionalTypeParameters = true;
     
     public AttachmentSerializer(Message messageParam) {
         message = messageParam;
     }
 
-    public AttachmentSerializer(Message messageParam, String multipartType, 
+    public AttachmentSerializer(Message messageParam, 
+                                String multipartType,
+                                boolean writeOptionalTypeParameters,
                                 Map<String, List<String>> headers) {
         message = messageParam;
         this.multipartType = multipartType;
+        this.writeOptionalTypeParameters = writeOptionalTypeParameters;
         this.rootHeaders = headers;
     }
     
@@ -86,11 +94,19 @@ public class AttachmentSerializer {
         }        
         
         // Set transport mime type
-        String requestMimeType = multipartType == null ? "multipart/related" : multipartType;
+        String requestMimeType = multipartType == null ? DEFAULT_MULTIPART_TYPE : multipartType;
         
         StringBuilder ct = new StringBuilder();
         ct.append(requestMimeType);
-        if (requestMimeType.indexOf("type=") == -1) {
+        
+        // having xop set to true implies multipart/related, but just in case...
+        boolean xopOrMultipartRelated = xop 
+            || DEFAULT_MULTIPART_TYPE.equalsIgnoreCase(requestMimeType)
+            || DEFAULT_MULTIPART_TYPE.startsWith(requestMimeType);
+        
+        // type is a required parameter for multipart/related only
+        if (xopOrMultipartRelated
+            && requestMimeType.indexOf("type=") == -1) {
             ct.append("; ");
             if (xop) {
                 ct.append("type=\"application/xop+xml\"");
@@ -98,19 +114,34 @@ public class AttachmentSerializer {
                 ct.append("type=\"").append(bodyCt).append("\"");
             }    
         }
-        ct.append("; ");
         
-        String rootContentId = getHeaderValue("Content-ID", AttachmentUtil.BODY_ATTACHMENT_ID);
-        
-        ct.append("boundary=\"")
+        // boundary
+        ct.append("; ")
+            .append("boundary=\"")
             .append(bodyBoundary)
-            .append("\"; ")
-            .append("start=\"<")
-            .append(checkAngleBrackets(rootContentId))
-            .append(">\"; ")
-            .append("start-info=\"")
-            .append(bodyCt)
             .append("\"");
+            
+        String rootContentId = getHeaderValue("Content-ID", AttachmentUtil.BODY_ATTACHMENT_ID);
+        
+        // 'start' is a required parameter for XOP/MTOM, clearly defined
+        // for simpler multipart/related payloads but is not needed for
+        // multipart/mixed, multipart/form-data
+        if (xopOrMultipartRelated) {
+            ct.append("; ")
+                .append("start=\"<")
+                .append(checkAngleBrackets(rootContentId))
+                .append(">\"");
+        }
+        
+        // start-info is a required parameter for XOP/MTOM, may be needed for
+        // other WS cases but is redundant in simpler multipart/related cases
+        if (writeOptionalTypeParameters || xop) {
+            ct.append("; ")
+                .append("start-info=\"")
+                .append(bodyCt)
+                .append("\"");
+        }
+        
         
         message.put(Message.CONTENT_TYPE, ct.toString());
 

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java?rev=1355465&r1=1355464&r2=1355465&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
Fri Jun 29 16:41:27 2012
@@ -62,7 +62,10 @@ public class AttachmentOutInterceptor ex
         }
 
         AttachmentSerializer serializer = 
-            new AttachmentSerializer(message, getMultipartType(), getRootHeaders());
+            new AttachmentSerializer(message, 
+                                     getMultipartType(),
+                                     writeOptionalTypeParameters(),
+                                     getRootHeaders());
         serializer.setXop(mtomEnabled);
         
         try {
@@ -80,6 +83,10 @@ public class AttachmentOutInterceptor ex
         return "multipart/related";
     }
     
+    protected boolean writeOptionalTypeParameters() {
+        return true;
+    }
+    
     protected Map<String, List<String>> getRootHeaders() {
         return Collections.emptyMap();
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentOutputInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentOutputInterceptor.java?rev=1355465&r1=1355464&r2=1355465&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentOutputInterceptor.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentOutputInterceptor.java
Fri Jun 29 16:41:27 2012
@@ -43,4 +43,7 @@ public class AttachmentOutputInterceptor
         return Collections.unmodifiableMap(rootHeaders);
     }
     
+    protected boolean writeOptionalTypeParameters() {
+        return false;
+    }
 }

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=1355465&r1=1355464&r2=1355465&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
Fri Jun 29 16:41:27 2012
@@ -357,6 +357,16 @@ public class JAXRSMultipartTest extends 
                 "/org/apache/cxf/systest/jaxrs/resources/book.xsd"));
         String bookXsd2 = IOUtils.readStringFromStream(xop2.getAttachinfo().getInputStream());
       
         assertEquals(bookXsdOriginal, bookXsd2);
+        
+        String ctString = 
+            client.getResponse().getMetadata().getFirst("Content-Type").toString();
+        MediaType mt = MediaType.valueOf(ctString);
+        Map<String, String> params = mt.getParameters();
+        assertEquals(4, params.size());
+        assertNotNull(params.get("boundary"));
+        assertNotNull(params.get("type"));
+        assertNotNull(params.get("start"));
+        assertNotNull(params.get("start-info"));
     }
     
     private Image getImage(String name) throws Exception {
@@ -413,6 +423,14 @@ public class JAXRSMultipartTest extends 
             getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
         byte[] image2 = IOUtils.readBytesFromStream(is2);
         assertTrue(Arrays.equals(image1, image2));
+        
+        String ctString = 
+            client.getResponse().getMetadata().getFirst("Content-Type").toString();
+        MediaType mt = MediaType.valueOf(ctString);
+        Map<String, String> params = mt.getParameters();
+        assertEquals(1, params.size());
+        assertNotNull(params.get("boundary"));
+        
     }
     
     @Test



Mime
View raw message