cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r565234 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/io/ rt/core/src/main/java/org/apache/cxf/attachment/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/core/src/test/java/org/apache/cxf/attachment/ systests/src/test/ja...
Date Mon, 13 Aug 2007 04:27:39 GMT
Author: ffang
Date: Sun Aug 12 21:27:38 2007
New Revision: 565234

URL: http://svn.apache.org/viewvc?view=rev&rev=565234
Log:
[CXF-888] apply patch provided by Jeff Yu-Control directory for on-disk attachments

Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?view=diff&rev=565234&r1=565233&r2=565234
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Sun Aug
12 21:27:38 2007
@@ -293,7 +293,6 @@
 
     public void setOutputDir(File outputDir) throws IOException {
         this.outputDir = outputDir;
-        createFileOutputStream();
     }
 
     public void setThreshold(long threshold) {

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?view=diff&rev=565234&r1=565233&r2=565234
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Sun Aug 12 21:27:38 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.attachment;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
@@ -46,7 +47,7 @@
 
     public static final String ATTACHMENT_MEMORY_THRESHOLD = "attachment-memory-threshold";
 
-    public static final int THRESHHOLD = 1024 * 100;
+    public static final int THRESHOLD = 1024 * 100; //100K (byte unit)
 
     private static final Pattern CONTENT_TYPE_BOUNDARY_PATTERN = Pattern.compile("boundary=\"?([^\";]*)");
 
@@ -129,7 +130,7 @@
 
     private String findBoundaryFromInputStream() throws IOException {
         CachedOutputStream bos = new CachedOutputStream();
-
+        
         InputStream is = message.getContent(InputStream.class);
         IOUtils.copy(is, bos);
 
@@ -144,6 +145,28 @@
         Matcher m = INPUT_STREAM_BOUNDARY_PATTERN.matcher(msg);
         return m.find() ? "--" + m.group(1) : null;
     }
+    
+    private void setStreamedAttachmentProperties(CachedOutputStream bos) throws IOException
{
+        Object directory = message.getContextualProperty(ATTACHMENT_DIRECTORY);
+        if (directory != null) {
+            if (directory instanceof File) {
+                bos.setOutputDir((File)directory);
+            } else {
+                bos.setOutputDir(new File((String)directory));
+            }
+        }
+        
+        Object threshold = message.getContextualProperty(ATTACHMENT_MEMORY_THRESHOLD);
+        if (threshold != null) {
+            if (threshold instanceof Long) {
+                bos.setThreshold((Long)threshold);
+            } else {
+                bos.setThreshold(Long.valueOf((String)threshold));
+            }
+        } else {
+            bos.setThreshold(THRESHOLD);
+        }
+    }
 
     public AttachmentImpl readNext() throws IOException {
         // Cache any mime parts that are currently being streamed
@@ -201,6 +224,7 @@
         CachedOutputStream out = null;
         try {
             out = new CachedOutputStream();
+            setStreamedAttachmentProperties(out);
             IOUtils.copy(input, out);
             input.setInputStream(out.getInputStream());
         } finally {

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java?view=diff&rev=565234&r1=565233&r2=565234
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
Sun Aug 12 21:27:38 2007
@@ -29,9 +29,6 @@
 
 public class AttachmentInInterceptor extends AbstractPhaseInterceptor<Message> {
 
-    public static final String ATTACHMENT_DIRECTORY = "attachment-directory";
-    public static final String ATTACHMENT_MEMORY_THRESHOLD = "attachment-memory-threshold";
-    public static final int THRESHHOLD = 1024 * 100;
     private static final Logger LOG = Logger.getLogger(AttachmentInInterceptor.class.getName());
 
     /**

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?view=diff&rev=565234&r1=565233&r2=565234
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Sun Aug 12 21:27:38 2007
@@ -20,19 +20,32 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.Iterator;
 
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 public class AttachmentDeserializerTest extends Assert {
     
+    private MessageImpl msg;
+    
+    @Before
+    public void setUp() throws Exception {
+        msg = new MessageImpl();
+        Exchange exchange = new ExchangeImpl();
+        msg.setExchange(exchange);
+    }
+    
     @Test
     public void testDeserializerMtom() throws Exception {
         InputStream is = getClass().getResourceAsStream("mimedata");
@@ -41,7 +54,6 @@
                     + "start-info=\"text/xml; charset=utf-8\"; "
                     + "boundary=\"----=_Part_4_701508.1145579811786\"";
         
-        MessageImpl msg = new MessageImpl();
         msg.put(Message.CONTENT_TYPE, ct);
         msg.setContent(InputStream.class, is);
         
@@ -89,7 +101,6 @@
                     + "start-info=\"text/xml; charset=utf-8\"; "
                     + "boundary=MIMEBoundaryurn_uuid_6BC4984D5D38EB283C1177616488109";
 
-        MessageImpl msg = new MessageImpl();
         msg.put(Message.CONTENT_TYPE, ct);
         msg.setContent(InputStream.class, is);
 
@@ -137,7 +148,6 @@
             + "boundary=\"----=_Part_0_14158819.1167275505862\"";
 
         
-        MessageImpl msg = new MessageImpl();
         msg.put(Message.CONTENT_TYPE, ct);
         msg.setContent(InputStream.class, is);
         
@@ -183,7 +193,6 @@
         String ct = "multipart/related; type=\"text/xml\"; ";
 
         
-        MessageImpl msg = new MessageImpl();
         msg.put(Message.CONTENT_TYPE, ct);
         msg.setContent(InputStream.class, is);
         
@@ -221,5 +230,40 @@
         assertTrue(attIs.read() == 'a');
         assertTrue(attIs.read() == 'r');
         assertTrue(attIs.read() == -1);
+    }
+    
+    @Test
+    public void testDeserializerWithCachedFile() throws Exception {
+        InputStream is = getClass().getResourceAsStream("mimedata");
+        String ct = "multipart/related; type=\"application/xop+xml\"; "
+                    + "start=\"<soap.xml@xfire.codehaus.org>\"; "
+                    + "start-info=\"text/xml; charset=utf-8\"; "
+                    + "boundary=\"----=_Part_4_701508.1145579811786\"";
+        
+        msg.put(Message.CONTENT_TYPE, ct);
+        msg.setContent(InputStream.class, is);
+        msg.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "10");
+        
+        AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
+        deserializer.initializeAttachments();
+        
+        InputStream attBody = msg.getContent(InputStream.class);
+        assertTrue(attBody != is);
+        assertTrue(attBody instanceof DelegatingInputStream);
+        
+        Collection<Attachment> atts = msg.getAttachments();
+        assertNotNull(atts);
+        
+        Iterator<Attachment> itr = atts.iterator();
+        assertTrue(itr.hasNext());
+        
+        Attachment a = itr.next();
+        assertNotNull(a);
+        
+        InputStream attIs = a.getDataHandler().getInputStream();
+        
+        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof FileInputStream);
+        
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java?view=diff&rev=565234&r1=565233&r2=565234
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
Sun Aug 12 21:27:38 2007
@@ -37,6 +37,7 @@
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
 import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.EndpointInfo;
@@ -136,6 +137,7 @@
         MessageImpl resMsg = new MessageImpl();
         resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
         resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
+        resMsg.setExchange(new ExchangeImpl());
         AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
         deserializer.initializeAttachments();
 

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java?view=diff&rev=565234&r1=565233&r2=565234
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
Sun Aug 12 21:27:38 2007
@@ -99,6 +99,7 @@
         MessageImpl resMsg = new MessageImpl();
         resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
         resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
+        resMsg.setExchange(new ExchangeImpl());
         AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
         deserializer.initializeAttachments();
 
@@ -165,6 +166,7 @@
         MessageImpl resMsg = new MessageImpl();
         resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
         resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
+        resMsg.setExchange(new ExchangeImpl());
         AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
         deserializer.initializeAttachments();
 



Mime
View raw message