cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/3] cxf git commit: [CXF-4851] Support ContentTransferEncoding on root part
Date Wed, 29 Mar 2017 12:36:22 GMT
[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/ca24a9c7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ca24a9c7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ca24a9c7

Branch: refs/heads/3.0.x-fixes
Commit: ca24a9c7b9fcfdd6981cc0e535d7ea9e74bc4661
Parents: 3707180
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Mar 28 13:21:17 2017 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Mar 29 08:36:14 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/ca24a9c7/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 6d96106..245bf6a 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/ca24a9c7/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 eade807..44e3ab9 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
@@ -398,8 +398,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);
         }
@@ -421,6 +425,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/ca24a9c7/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/ca24a9c7/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/ca24a9c7/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 6666c2a..251b1cd 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/ca24a9c7/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) {


Mime
View raw message