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 2017/03/29 12:35:44 UTC

[2/3] cxf git commit: [CXF-4851] Support ContentTransferEncoding on root part

[CXF-4851] Support ContentTransferEncoding on root part


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/03dd596d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/03dd596d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/03dd596d

Branch: refs/heads/3.1.x-fixes
Commit: 03dd596d9270a0257de7ea2f5f0590c6ef02e6ec
Parents: c0ff648
Author: Daniel Kulp <dk...@apache.org>
Authored: Tue Mar 28 13:21:17 2017 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Wed Mar 29 08:35:32 2017 -0400

----------------------------------------------------------------------
 .../apache/cxf/attachment/AttachmentDeserializer.java    |  9 +++++++--
 .../java/org/apache/cxf/attachment/AttachmentUtil.java   | 11 +++++++++--
 .../org/apache/cxf/attachment/Base64DecoderStream.java   |  3 ++-
 .../apache/cxf/interceptor/AttachmentOutInterceptor.java |  4 ++++
 .../cxf/binding/soap/interceptor/SoapOutInterceptor.java |  4 ++++
 .../soap/interceptor/SoapPreProtocolOutInterceptor.java  |  6 ++++++
 6 files changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/03dd596d/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
index e8dd326..05a5598 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
@@ -132,9 +132,14 @@ public class AttachmentDeserializer {
                     message.put(Message.ENCODING, HttpHeaderHelper.mapCharset(cs));
                 }
             }
+            val = AttachmentUtil.getHeader(ih, "Content-Transfer-Encoding");
 
-            body = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount),
-                                             this);
+            MimeBodyPartInputStream mmps = new MimeBodyPartInputStream(stream, boundary, pbAmount);
+            InputStream ins = AttachmentUtil.decode(mmps, val);
+            if (ins != mmps) {
+                ih.remove("Content-Transfer-Encoding");
+            }
+            body = new DelegatingInputStream(ins, this);
             createCount++;
             message.setContent(InputStream.class, body);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/03dd596d/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
index 79af3b1..e9ffc88 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
@@ -400,8 +400,12 @@ public final class AttachmentUtil {
         if (encoding == null) {
             encoding = "binary";
         }
-        DataSource source = new AttachmentDataSource(ct, 
-                                                     decode(stream, encoding));
+
+        InputStream ins =  decode(stream, encoding);
+        if (ins != stream) {
+            headers.remove("Content-Transfer-Encoding");
+        }
+        DataSource source = new AttachmentDataSource(ct, ins);
         if (!StringUtils.isEmpty(fileName)) {
             ((AttachmentDataSource)source).setName(fileName);
         }
@@ -423,6 +427,9 @@ public final class AttachmentUtil {
     }
     
     public static InputStream decode(InputStream in, String encoding) throws IOException {
+        if (encoding == null) {
+            return in;
+        }
         encoding = encoding.toLowerCase();
 
         // some encodings are just pass-throughs, with no real decoding.

http://git-wip-us.apache.org/repos/asf/cxf/blob/03dd596d/core/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java b/core/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
index 6f0a97f..a1ff98e 100644
--- a/core/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
+++ b/core/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
@@ -149,7 +149,8 @@ public class Base64DecoderStream extends FilterInputStream {
                 // now check to see if this is normal, or potentially an error
                 // if we didn't get characters as a multiple of 4, we may need to complain about this.
                 if ((readCharacters % 4) != 0) {
-                    throw new IOException("Base64 encoding error, data truncated");
+                    throw new IOException("Base64 encoding error, data truncated: " + readCharacters + " "
+                                          + new String(encodedChars, 0, readCharacters));
                 }
                 // return the count.
                 return readCharacters;

http://git-wip-us.apache.org/repos/asf/cxf/blob/03dd596d/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
index 8543960..207a61f 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
@@ -105,6 +105,10 @@ public class AttachmentOutInterceptor extends AbstractPhaseInterceptor<Message>
             AttachmentSerializer ser = message.getContent(AttachmentSerializer.class);
             if (ser != null) {
                 try {
+                    String cte = (String)message.getContextualProperty(Message.CONTENT_TRANSFER_ENCODING);
+                    if (cte != null) {
+                        ser.setContentTransferEncoding(cte);
+                    }
                     ser.writeAttachments();
                 } catch (IOException e) {
                     throw new Fault(new org.apache.cxf.common.i18n.Message("WRITE_ATTACHMENTS", BUNDLE), e);

http://git-wip-us.apache.org/repos/asf/cxf/blob/03dd596d/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
index 5fbfd9e..310824d 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
@@ -94,6 +94,10 @@ public class SoapOutInterceptor extends AbstractSoapInterceptor {
             }
         }
 
+        String cte = (String)message.get("soap.attachement.content.transfer.encoding");
+        if (cte != null) {
+            message.put(Message.CONTENT_TRANSFER_ENCODING, cte);
+        }
         // Add a final interceptor to write end elements
         message.getInterceptorChain().add(new SoapOutEndingInterceptor());
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/03dd596d/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java
index 62946ca..d782ea1 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapPreProtocolOutInterceptor.java
@@ -95,6 +95,12 @@ public class SoapPreProtocolOutInterceptor extends AbstractSoapInterceptor {
         if (message.get(MIME_HEADERS) == null) {
             message.put(MIME_HEADERS, new HashMap<String, List<String>>());
         }
+        String cte = (String)message.getContextualProperty(Message.CONTENT_TRANSFER_ENCODING);
+        if (cte != null) {
+            //root part MUST be binary
+            message.put(Message.CONTENT_TRANSFER_ENCODING, "binary");
+            message.put("soap.attachement.content.transfer.encoding", cte);
+        }
     }
     
     private void setSoapAction(SoapMessage message) {