Author: dkulp
Date: Wed Oct 17 15:13:17 2012
New Revision: 1399301
URL: http://svn.apache.org/viewvc?rev=1399301&view=rev
Log:
[CXF-4570] Some minor cleanup around the content-id and saaj
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1399301&r1=1399300&r2=1399301&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
Wed Oct 17 15:13:17 2012
@@ -186,10 +186,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 <>
@@ -200,13 +197,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 = "[email protected]";
}
-
+ 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/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=1399301&r1=1399300&r2=1399301&view=diff
==============================================================================
---
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
(original)
+++
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
Wed Oct 17 15:13:17 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/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java?rev=1399301&r1=1399300&r2=1399301&view=diff
==============================================================================
---
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
(original)
+++
cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
Wed Oct 17 15:13:17 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) {