You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/10/17 17:23:25 UTC

svn commit: r1399304 - in /cxf/branches/2.6.x-fixes: api/src/main/java/org/apache/cxf/attachment/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/

Author: dkulp
Date: Wed Oct 17 15:23:25 2012
New Revision: 1399304

URL: http://svn.apache.org/viewvc?rev=1399304&view=rev
Log:
Merged revisions 1399301 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1399301 | dkulp | 2012-10-17 11:13:17 -0400 (Wed, 17 Oct 2012) | 2 lines

  [CXF-4570] Some minor cleanup around the content-id and saaj

........

Modified:
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
    cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1399304&r1=1399303&r2=1399304&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Wed Oct 17 15:23:25 2012
@@ -190,10 +190,7 @@ public final class AttachmentUtil {
         return dataHandlers == null ? new LinkedHashMap<String, DataHandler>() : dataHandlers;
     }
     
-    public static Attachment createAttachment(InputStream stream, InternetHeaders headers) 
-        throws IOException {
-     
-        String id = headers.getHeader("Content-ID", null);
+    public static String cleanContentId(String id) {
         if (id != null) {
             if (id.startsWith("<")) {
                 // strip <>
@@ -204,13 +201,24 @@ public final class AttachmentUtil {
                 id = id.substring(4);
             }
             // urldecode. Is this bad even without cid:? What does decode do with malformed %-signs, anyhow?
-            id = URLDecoder.decode(id, "UTF-8");
+            try {
+                id = URLDecoder.decode(id, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                //ignore, keep id as is
+            }
         }
         if (id == null) {
             //no Content-ID, set cxf default ID
             id = "root.message@cxf.apache.org";
         }
-
+        return id;
+    }
+    
+    
+    public static Attachment createAttachment(InputStream stream, InternetHeaders headers) 
+        throws IOException {
+     
+        String id = cleanContentId(headers.getHeader("Content-ID", null));
 
         AttachmentImpl att = new AttachmentImpl(id);
         

Modified: cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=1399304&r1=1399303&r2=1399304&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java (original)
+++ cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java Wed Oct 17 15:23:25 2012
@@ -54,6 +54,7 @@ import org.apache.cxf.binding.soap.inter
 import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.headers.Header;
 import org.apache.cxf.headers.HeaderManager;
@@ -203,13 +204,15 @@ public class SAAJInInterceptor extends A
                         }
                     }
                     AttachmentPart ap = soapMessage.createAttachmentPart(a.getDataHandler());
-                    ap.setContentId(a.getId());
                     Iterator<String> i = a.getHeaderNames();
                     while (i != null && i.hasNext()) {
                         String h = i.next();
                         String val = a.getHeader(h);
                         ap.addMimeHeader(h, val);
                     }
+                    if (StringUtils.isEmpty(ap.getContentId())) {
+                        ap.setContentId(a.getId());
+                    }
                     soapMessage.addAttachmentPart(ap);
                 }
             }

Modified: cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java?rev=1399304&r1=1399303&r2=1399304&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java (original)
+++ cxf/branches/2.6.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java Wed Oct 17 15:23:25 2012
@@ -40,6 +40,7 @@ import org.w3c.dom.Node;
 
 
 import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.attachment.AttachmentUtil;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapFault;
@@ -187,7 +188,8 @@ public class SAAJOutInterceptor extends 
                     Iterator<AttachmentPart> it = CastUtils.cast(soapMessage.getAttachments());
                     while (it.hasNext()) {
                         AttachmentPart part = it.next();
-                        AttachmentImpl att = new AttachmentImpl(part.getContentId());
+                        String id = AttachmentUtil.cleanContentId(part.getContentId());
+                        AttachmentImpl att = new AttachmentImpl(id);
                         try {
                             att.setDataHandler(part.getDataHandler());
                         } catch (SOAPException e) {