cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1415213 - in /cxf/branches/2.6.x-fixes: ./ api/src/main/java/org/apache/cxf/io/CachedOutputStream.java api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
Date Thu, 29 Nov 2012 15:33:02 GMT
Author: ay
Date: Thu Nov 29 15:33:02 2012
New Revision: 1415213

URL: http://svn.apache.org/viewvc?rev=1415213&view=rev
Log:
Merged revisions 1414962 via  svn merge from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1414962 | ay | 2012-11-28 23:09:07 +0100 (Wed, 28 Nov 2012) | 1 line
  
  use setThreadDefaultBus for CXF-4661
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java

Propchange: cxf/branches/2.6.x-fixes/
            ('svn:mergeinfo' removed)

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=1415213&r1=1415212&r2=1415213&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Thu
Nov 29 15:33:02 2012
@@ -44,6 +44,8 @@ import javax.crypto.CipherOutputStream;
 import javax.crypto.KeyGenerator;
 import javax.crypto.spec.IvParameterSpec;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.helpers.IOUtils;
@@ -99,6 +101,7 @@ public class CachedOutputStream extends 
     public CachedOutputStream(PipedInputStream stream) throws IOException {
         currentStream = new PipedOutputStream(stream);
         inmem = true;
+        readBusProperties();
     }
 
     public CachedOutputStream() {
@@ -109,6 +112,30 @@ public class CachedOutputStream extends 
         this.threshold = threshold; 
         currentStream = new LoadingByteArrayOutputStream(2048);
         inmem = true;
+        readBusProperties();
+    }
+
+    private void readBusProperties() {
+        Bus b = BusFactory.getThreadDefaultBus(false);
+        if (b != null) {
+            String v = getBusProperty(b, "bus.io.CachedOutputStream.Threshold", null);
+            if (v != null && threshold == defaultThreshold) {
+                threshold = Integer.parseInt(v);
+            }
+            v = getBusProperty(b, "bus.io.CachedOutputStream.MaxSize", null);
+            if (v != null) {
+                maxSize = Integer.parseInt(v);
+            }
+            v = getBusProperty(b, "bus.io.CachedOutputStream.CipherTransformation", null);
+            if (v != null) {
+                cipherTransformation = v;
+            }
+        }
+    }
+
+    private static String getBusProperty(Bus b, String key, String dflt) {
+        String v = (String)b.getProperty(key);
+        return v != null ? v : dflt;
     }
 
     public void holdTempFile() {

Modified: cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java?rev=1415213&r1=1415212&r2=1415213&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
Thu Nov 29 15:33:02 2012
@@ -24,6 +24,11 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -114,6 +119,39 @@ public class CachedOutputStreamTest exte
         assertFalse("file is not deleted", tmpfile.exists());
     }
 
+    @Test
+    public void testUseBusProps() throws Exception {
+        Bus oldbus = BusFactory.getThreadDefaultBus(false); 
+        try {
+            CachedOutputStream cos = new CachedOutputStream();
+            cos.write("Hello World!".getBytes());
+            cos.flush();
+            assertNull("expects no tmp file", cos.getTempFile());
+            cos.close();
+            
+            IMocksControl control = EasyMock.createControl();
+            
+            Bus b = control.createMock(Bus.class);
+            EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.Threshold")).andReturn("4");
+            EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.MaxSize")).andReturn(null);
+            EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.CipherTransformation")).andReturn(null);
+        
+            BusFactory.setThreadDefaultBus(b);
+            
+            control.replay();
+
+            cos = new CachedOutputStream();
+            cos.write("Hello World!".getBytes());
+            cos.flush();
+            assertNotNull("expects a tmp file", cos.getTempFile());
+            cos.close();
+            
+            control.verify();
+        } finally {
+            BusFactory.setThreadDefaultBus(oldbus);
+        }
+    }
+    
     private static String readFromStream(InputStream is) throws IOException {
         ByteArrayOutputStream buf = new ByteArrayOutputStream();
         try {



Mime
View raw message