Repository: cxf Updated Branches: refs/heads/master 9bbf1acd7 -> a392a38b5
[CXF-6431] Attachment serialization fix (part 2) Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a392a38b Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a392a38b Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a392a38b Branch: refs/heads/master Commit: a392a38b5ab5ac19005fa4598834a0bdf9d6046f Parents: 9bbf1ac Author: Akitoshi Yoshida <[email protected]> Authored: Tue Jun 2 13:22:46 2015 +0200 Committer: Akitoshi Yoshida <[email protected]> Committed: Tue Jun 2 13:22:46 2015 +0200 ---------------------------------------------------------------------- .../cxf/attachment/AttachmentSerializer.java | 15 ++++++--- .../attachment/AttachmentSerializerTest.java | 34 ++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a392a38b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java index 62f2bb6..539fcc6 100644 --- a/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java +++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java @@ -73,6 +73,7 @@ public class AttachmentSerializer { String bodyCt = (String) message.get(Message.CONTENT_TYPE); String bodyCtParams = null; + String bodyCtParamsEscaped = null; // split the bodyCt to its head that is the type and its properties so that we // can insert the values at the right places based on the soap version and the mtom option // bodyCt will be of the form @@ -82,6 +83,7 @@ public class AttachmentSerializer { int pos = bodyCt.indexOf(';'); // get everything from the semi-colon bodyCtParams = bodyCt.substring(pos); + bodyCtParamsEscaped = escapeQuotes(bodyCtParams); // keep the type/subtype part in bodyCt bodyCt = bodyCt.substring(0, pos); } @@ -128,8 +130,8 @@ public class AttachmentSerializer { if (writeOptionalTypeParameters || xop) { ct.append("; start-info=\"") .append(bodyCt); - if (bodyCtParams != null) { - ct.append(escapeQuotes(bodyCtParams)); + if (bodyCtParamsEscaped != null) { + ct.append(bodyCtParamsEscaped); } ct.append("\""); } @@ -154,9 +156,12 @@ public class AttachmentSerializer { mimeBodyCt.append(xop ? "application/xop+xml" : bodyCt) .append("; charset=").append(encoding); if (xop) { - mimeBodyCt.append("; type=\"").append(bodyCt).append("\""); - } - if (bodyCtParams != null) { + mimeBodyCt.append("; type=\"").append(bodyCt); + if (bodyCtParamsEscaped != null) { + mimeBodyCt.append(bodyCtParamsEscaped); + } + mimeBodyCt.append("\""); + } else if (bodyCtParams != null) { mimeBodyCt.append(bodyCtParams); } } else { http://git-wip-us.apache.org/repos/asf/cxf/blob/a392a38b/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java b/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java index 7645929..661b69f 100644 --- a/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java +++ b/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java @@ -81,12 +81,15 @@ public class AttachmentSerializerTest extends Assert { msg.put(Message.CONTENT_TYPE, soapContentType); String soapCtType = null; String soapCtParams = null; + String soapCtParamsEscaped = null; int p = soapContentType.indexOf(';'); if (p != -1) { soapCtParams = soapContentType.substring(p); + soapCtParamsEscaped = escapeQuotes(soapCtParams); soapCtType = soapContentType.substring(0, p); } else { soapCtParams = ""; + soapCtParamsEscaped = ""; soapCtType = soapContentType; } ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -100,16 +103,19 @@ public class AttachmentSerializerTest extends Assert { serializer.writeProlog(); - // we expect - // - the package header must have type multipart/related - // - the start-info property must be present for mtom but otherwise optional - // - the action property should not appear directly - // - the type property must be application/xop+xml for mtom but otherwise text/xml or application/soap+xml + // we expect the following rules at the package header level + // - the package header must have media type multipart/related. + // - the start-info property must be present for mtom but otherwise optional. its + // value must contain the content type associated with the root content's xml serialization, + // including its parameters as appropriate. + // - the action property should not appear directly in the package header level + // - the type property must contain the media type type/subtype of the root content part. + // namely application/xop+xml for mtom but otherwise text/xml or application/soap+xml + // depending on the soap version 1.1 or 1.2, respectively. String ct = (String) msg.get(Message.CONTENT_TYPE); - System.out.println("##teset ct=" + ct); assertTrue(ct.indexOf("multipart/related;") == 0); assertTrue(ct.indexOf("start=\"<[email protected]>\"") > -1); - assertTrue(ct.indexOf("start-info=\"" + escapeQuotes(soapContentType) + "\"") > -1); + assertTrue(ct.indexOf("start-info=\"" + soapCtType + soapCtParamsEscaped + "\"") > -1); assertTrue(ct.indexOf("action=\"") == -1); if (xop) { assertTrue(ct.indexOf("type=\"application/xop+xml\"") > -1); @@ -132,13 +138,15 @@ public class AttachmentSerializerTest extends Assert { MimeMultipart multipart = (MimeMultipart) inMsg.getContent(); MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(0); - // we expect - // - the envelope header must have type application/xop+xml for mtom but otherwise t - // - the start-info property must be present for mtom but otherwise text/xml or application/soap+xml - // - the action must appear if it was present in the original message + // we expect the following rules at the root content level + // - the envelope header must have type application/xop+xml for mtom but otherwise the content's + // serialization type. + // - the type property must be present for mtom and it must contain the content's serialization type + // including its parameters if appropriate. + // - the action must appear if it was present in the original message (i.e., for soap 1.2) if (xop) { - assertEquals("application/xop+xml; charset=UTF-8; type=\"" + soapCtType + "\"" + soapCtParams, - part.getHeader("Content-Type")[0]); + assertEquals("application/xop+xml; charset=UTF-8; type=\"" + soapCtType + soapCtParamsEscaped + "\"", + part.getHeader("Content-Type")[0]); } else { assertEquals(soapCtType + "; charset=UTF-8" + soapCtParams, part.getHeader("Content-Type")[0]);
