cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r798749 - in /cxf/trunk/rt: bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/ core/src/main/java/org/apache/cxf/attachment/ databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/
Date Wed, 29 Jul 2009 02:14:11 GMT
Author: dkulp
Date: Wed Jul 29 02:14:11 2009
New Revision: 798749

URL: http://svn.apache.org/viewvc?rev=798749&view=rev
Log:
SAAJ requires the attachments to be cached as well as it breaks the
streaming.

Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java

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=798749&r1=798748&r2=798749&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 Jul 29 02:14:11 2009
@@ -20,6 +20,7 @@
 package org.apache.cxf.binding.soap.saaj;
 
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.ResourceBundle;
@@ -43,6 +44,7 @@
 import org.w3c.dom.Node;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.attachment.AttachmentDataSource;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapHeader;
@@ -112,6 +114,13 @@
             Collection<Attachment> atts = message.getAttachments();
             if (atts != null) {
                 for (Attachment a : atts) {
+                    if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource)
{
+                        try {
+                            ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache();
+                        } catch (IOException e) {
+                            throw new Fault(e);
+                        }
+                    }
                     AttachmentPart ap = soapMessage.createAttachmentPart(a.getDataHandler());
                     ap.setContentId(a.getId());
                     Iterator<String> i = a.getHeaderNames();

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=798749&r1=798748&r2=798749&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Wed
Jul 29 02:14:11 2009
@@ -33,34 +33,44 @@
     private final String ct;    
     private CachedOutputStream cache;
     private InputStream ins;
-    private DelegatingInputStream lastIns;
+    private DelegatingInputStream delegating;
     
     public AttachmentDataSource(String ctParam, InputStream inParam) throws IOException {
         this.ct = ctParam;        
         ins = inParam;
+        if (ins instanceof DelegatingInputStream) {
+            delegating = (DelegatingInputStream)ins;
+        }
+    }
+    public AttachmentDataSource(String ctParam, 
+                                InputStream inParam,
+                                InputStream delegate) throws IOException {
+        this.ct = ctParam;        
+        ins = inParam;
+        if (delegate instanceof DelegatingInputStream) {
+            delegating = (DelegatingInputStream)delegate;
+        }
     }
 
     public boolean isCached() {
         return cache != null;
     }
-    
-    public void hold() {
-        try {
-            if (cache == null) {
-                cache = new CachedOutputStream();
-                IOUtils.copy(ins, cache);
-                cache.lockOutputStream();
-                cache.holdTempFile();
-                ins.close();
-                ins = null;
-                if (lastIns != null) {
-                    lastIns.setInputStream(cache.getInputStream());
-                }
+    public void cache() throws IOException {
+        if (cache == null) {
+            cache = new CachedOutputStream();
+            IOUtils.copy(ins, cache);
+            cache.lockOutputStream();  
+            ins.close();
+            ins = null;
+            if (delegating != null) {
+                delegating.setInputStream(cache.getInputStream());
             }
-        } catch (IOException e) {
-            //shouldn't happen
         }
     }
+    public void hold() throws IOException {
+        cache();
+        cache.holdTempFile();
+    }
     public void release() {
         cache.releaseTempFileHold();
     }
@@ -68,15 +78,14 @@
     public String getContentType() {
         return ct;
     }
-
+    public DelegatingInputStream getDelegatingInputStream() {
+        return delegating;
+    }
     public InputStream getInputStream() {
         try {
             if (cache != null) {
                 return cache.getInputStream();
             }
-            if (ins instanceof DelegatingInputStream) {
-                lastIns = (DelegatingInputStream)ins;
-            }
             return ins;
         } catch (IOException e) {
             return null;

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=798749&r1=798748&r2=798749&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Wed Jul 29 02:14:11 2009
@@ -208,8 +208,8 @@
         for (Attachment a : attachments.getLoadedAttachments()) {
             DataSource s = a.getDataHandler().getDataSource();
             if (s instanceof AttachmentDataSource) {
-                if (!((AttachmentDataSource)s).isCached()) {
-                    cache((DelegatingInputStream) s.getInputStream(), false);
+                if (((AttachmentDataSource)s).getDelegatingInputStream() != null) {
+                    cache(((AttachmentDataSource)s).getDelegatingInputStream(), false);
                 }
             } else {
                 cache((DelegatingInputStream) s.getInputStream(), false);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=798749&r1=798748&r2=798749&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Wed Jul
29 02:14:11 2009
@@ -162,7 +162,9 @@
         }
         
         if (quotedPrintable) {
-            DataSource source = new AttachmentDataSource(ct, new QuotedPrintableDecoderStream(stream));
+            DataSource source = new AttachmentDataSource(ct, 
+                                                         new QuotedPrintableDecoderStream(stream),
+                                                         stream);
             att.setDataHandler(new DataHandler(source));
         } else {
             DataSource source = new AttachmentDataSource(ct, stream);

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java?rev=798749&r1=798748&r2=798749&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java
Wed Jul 29 02:14:11 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxb.attachment;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -51,7 +52,11 @@
             for (Attachment at : message.getAttachments()) {
                 if (at.getDataHandler().getDataSource() instanceof AttachmentDataSource)
{
                     AttachmentDataSource ds = (AttachmentDataSource)at.getDataHandler().getDataSource();
-                    ds.hold();
+                    try {
+                        ds.hold();
+                    } catch (IOException e) {
+                        throw new Fault(e);
+                    }
                     dss.add(ds);
                 }
             }



Mime
View raw message