cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r668214 - /cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
Date Mon, 16 Jun 2008 16:08:58 GMT
Author: dkulp
Date: Mon Jun 16 09:08:57 2008
New Revision: 668214

URL: http://svn.apache.org/viewvc?rev=668214&view=rev
Log:
Make sure attachements get copied over.

Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java

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=668214&r1=668213&r2=668214&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
Mon Jun 16 09:08:57 2008
@@ -21,9 +21,13 @@
 
 
 import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.ResourceBundle;
 
+import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeader;
 import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
@@ -32,13 +36,16 @@
 import javax.xml.stream.XMLStreamWriter;
 
 
+import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Attachment;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamReader;
@@ -126,11 +133,35 @@
             SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
  
             if (soapMessage != null) {
+                if (soapMessage.countAttachments() > 0) {
+                    if (message.getAttachments() == null) {
+                        message.setAttachments(new ArrayList<Attachment>(soapMessage
+                                .countAttachments()));
+                    }
+                    Iterator<AttachmentPart> it = CastUtils.cast(soapMessage.getAttachments());
+                    while (it.hasNext()) {
+                        AttachmentPart part = it.next();
+                        AttachmentImpl att = new AttachmentImpl(part.getContentId());
+                        try {
+                            att.setDataHandler(part.getDataHandler());
+                        } catch (SOAPException e) {
+                            throw new Fault(e);
+                        }
+                        Iterator<MimeHeader> it2 = CastUtils.cast(part.getAllMimeHeaders());
+                        while (it2.hasNext()) {
+                            MimeHeader header = it2.next();
+                            att.setHeader(header.getName(), header.getValue());
+                        }
+                        message.getAttachments().add(att);
+                    }
+                }
+                
                 XMLStreamWriter writer = (XMLStreamWriter)message.get(ORIGINAL_XML_WRITER);
                 try {
                     StaxUtils.copy(new W3CDOMStreamReader(soapMessage.getSOAPPart()), writer);
                     writer.flush();
                     message.setContent(XMLStreamWriter.class, writer);
+
                 } catch (XMLStreamException e) {
                     throw new SoapFault(new Message("SOAPEXCEPTION", BUNDLE), e, message.getVersion()
                                         .getSender());
@@ -138,22 +169,5 @@
             }
         }
 
-        protected void setMessageContent(SoapMessage message, SOAPMessage soapMessage) 
-            throws SOAPException {
-            
-            if (soapMessage.getAttachments().hasNext()) {
-                StringBuffer sb = new StringBuffer();
-                for (String str : soapMessage.getMimeHeaders().getHeader("Content-Type"))
{
-                    sb.append(str);
-                }
-                String contentType = sb.toString();
-                if (contentType != null && contentType.length() > 0) {
-                    message.put(org.apache.cxf.message.Message.CONTENT_TYPE, contentType);
-                }
-                    
-            }
-            
-        }
-
     }
 }



Mime
View raw message