You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/10/10 20:57:21 UTC

svn commit: r583575 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/io/ common/common/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/apache/cxf/feature/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/core/src/main/res...

Author: dkulp
Date: Wed Oct 10 11:57:20 2007
New Revision: 583575

URL: http://svn.apache.org/viewvc?rev=583575&view=rev
Log:
[CXF-986, CXF-1097, CXF-1059, CXF-1099] More "large message" fixes
 * Add configurable limit to the logging interceptors (default is 100K)
 * Fix problems with WS-RM with large messages (still uses byte[], but it at least works now)
 * Change all temp files to go through FileUtils
 * Update temp file creation to go into a directory we wipe on exit via exit hook to work around memory leak in file.deleteOnExit() (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4872014)
 * Fix a BUNCH of places that were leaking temp files to properly close streams so that temp files will get deleted.
 * Make HTTPConduit.finalizeConfig protected

Added:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java   (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/resources/schemas/core.xsd
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutDatabindingInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMMessageConstants.java
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RetransmissionCallback.java
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RetransmissionQueueImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/InMessageRecorder.java
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/Compiler.java
    incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
    incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.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?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- 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 Wed Oct 10 11:57:20 2007
@@ -26,24 +26,47 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
-import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
 
 public class CachedOutputStream extends OutputStream {
+    private static final File DEFAULT_TEMP_DIR;
+    private static final int DEFAULT_THRESHOLD;
+    static {
+        String s = System.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold",
+                                      "-1");
+        int i = Integer.parseInt(s);
+        if (i <= 0) {
+            i = 64 * 1024;
+        }
+        DEFAULT_THRESHOLD = i;
+        
+        s = System.getProperty("org.apache.cxf.io.CachedOutputStream.OutputDirectory");
+        if (s != null) {
+            File f = new File(s);
+            if (f.exists() && f.isDirectory()) {
+                DEFAULT_TEMP_DIR = f;
+            } else {
+                DEFAULT_TEMP_DIR = null;
+            }
+        } else {
+            DEFAULT_TEMP_DIR = null;
+        }
+    }
 
     protected OutputStream currentStream;
 
-    private long threshold = 64 * 1024;
+    private long threshold = DEFAULT_THRESHOLD;
 
     private int totalLength;
 
@@ -51,7 +74,7 @@
 
     private File tempFile;
 
-    private File outputDir;
+    private File outputDir = DEFAULT_TEMP_DIR;
 
     private List<CachedOutputStreamCallback> callbacks;
 
@@ -61,13 +84,13 @@
     }
 
     public CachedOutputStream() {
-        currentStream = new ByteArrayOutputStream(2048);
+        currentStream = new LoadingByteArrayOutputStream(2048);
         inmem = true;
     }
 
     public CachedOutputStream(long threshold) {
         this.threshold = threshold; 
-        currentStream = new ByteArrayOutputStream(2048);
+        currentStream = new LoadingByteArrayOutputStream(2048);
         inmem = true;
     }
 
@@ -175,6 +198,9 @@
                 if (copyOldContent) {
                     IOUtils.copyAndCloseInput(fin, out);
                 }
+                tempFile.delete();
+                tempFile = null;
+                inmem = true;
             }
         }
         currentStream = out;
@@ -184,6 +210,9 @@
         IOUtils.copyAndCloseInput(in, out, bufferSize);
     }
 
+    public int size() {
+        return totalLength;
+    }
     
     public byte[] getBytes() throws IOException {
         flush();
@@ -214,6 +243,43 @@
             IOUtils.copyAndCloseInput(fin, out);
         }
     }
+    public void writeCacheTo(StringBuilder out, int limit) throws IOException {
+        flush();
+        if (totalLength < limit
+            || limit == -1) {
+            writeCacheTo(out);
+            return;
+        }
+        
+        int count = 0;
+        if (inmem) {
+            if (currentStream instanceof ByteArrayOutputStream) {
+                byte bytes[] = ((ByteArrayOutputStream)currentStream).toByteArray();
+                out.append(new String(bytes, 0, limit));
+            } else {
+                throw new IOException("Unknown format of currentStream");
+            }
+        } else {
+            // read the file
+            FileInputStream fin = new FileInputStream(tempFile);
+            byte bytes[] = new byte[1024];
+            int x = fin.read(bytes);
+            while (x != -1) {
+                if ((count + x) > limit) {
+                    x = count - limit;
+                }
+                out.append(new String(bytes, 0, x));
+                count += x;
+                
+                if (count >= limit) {
+                    x = -1;
+                } else {
+                    x = fin.read(bytes);
+                }
+            }
+            fin.close();
+        }
+    }
     public void writeCacheTo(StringBuilder out) throws IOException {
         flush();
         if (inmem) {
@@ -249,24 +315,12 @@
 
     public String toString() {
         StringBuilder builder = new StringBuilder().append("[")
-            .append(super.toString())
+            .append(CachedOutputStream.class.getName())
             .append(" Content: ");
-        
-        if (inmem) {
-            builder.append(currentStream.toString());
-        } else {
-            try {
-                Reader fin = new FileReader(tempFile);
-                char buf[] = new char[1024];
-                int x = fin.read(buf);
-                while (x > -1) {
-                    builder.append(buf, 0, x);
-                    x = fin.read(buf);
-                }
-                fin.close();
-            } catch (IOException e) {
-                //ignore
-            }
+        try {
+            writeCacheTo(builder);
+        } catch (IOException e) {
+            //ignore
         }
         return builder.append("]").toString();
     }
@@ -303,15 +357,15 @@
     }
 
     private void createFileOutputStream() throws IOException {
-        byte[] bytes = ((ByteArrayOutputStream) currentStream).toByteArray();
+        ByteArrayOutputStream bout = (ByteArrayOutputStream)currentStream;
         if (outputDir == null) {
-            tempFile = File.createTempFile("att", "tmp");
+            tempFile = FileUtils.createTempFile("cos", "tmp");
         } else {
-            tempFile = File.createTempFile("att", "tmp", outputDir);
+            tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false);
         }
-        tempFile.deleteOnExit();
+        
         currentStream = new BufferedOutputStream(new FileOutputStream(tempFile));
-        currentStream.write(bytes);
+        bout.writeTo(currentStream);
         inmem = false;
     }
 
@@ -322,7 +376,9 @@
     public InputStream getInputStream() throws IOException {
         flush();
         if (inmem) {
-            if (currentStream instanceof ByteArrayOutputStream) {
+            if (currentStream instanceof LoadingByteArrayOutputStream) {
+                return ((LoadingByteArrayOutputStream) currentStream).createInputStream();
+            } else if (currentStream instanceof ByteArrayOutputStream) {
                 return new ByteArrayInputStream(((ByteArrayOutputStream) currentStream).toByteArray());
             } else if (currentStream instanceof PipedOutputStream) {
                 return new PipedInputStream((PipedOutputStream) currentStream);

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/FileUtils.java Wed Oct 10 11:57:20 2007
@@ -20,18 +20,47 @@
 package org.apache.cxf.helpers;
 
 import java.io.File;
-import java.text.DecimalFormat;
+import java.io.IOException;
 import java.util.Locale;
-import java.util.Random;
 
 public final class FileUtils {
     private static final int RETRY_SLEEP_MILLIS = 10;
-    private static Random rand = new Random(System.currentTimeMillis()
-                                            + Runtime.getRuntime().freeMemory());
-
+    private static File defaultTempDir;
+    
+    
     private FileUtils() {
         
     }
+    
+    private static synchronized File getDefaultTempDir() {
+        if (defaultTempDir != null) {
+            return defaultTempDir;
+        }
+        String s = System.getProperty(FileUtils.class.getName() + ".TempDirectory");
+        if (s == null) {
+            int x = (int)(Math.random() * 1000000);
+            s = System.getProperty("java.io.tmpdir");
+            File f = new File(s, "cxf-tmp-" + x);
+            while (!f.mkdir()) {
+                x = (int)(Math.random() * 1000000);
+                f = new File(s, "cxf-tmp-" + x);
+            }
+            defaultTempDir = f;
+            Thread hook = new Thread() {
+                @Override
+                public void run() {
+                    removeDir(defaultTempDir);
+                }
+            };
+            Runtime.getRuntime().addShutdownHook(hook);            
+        } else {
+            //assume someone outside of us will manage the directory
+            File f = new File(s);
+            f.mkdirs();
+            defaultTempDir = f;
+        }
+        return defaultTempDir;
+    }
 
     public static void mkDir(File dir) {
         if (dir == null) {
@@ -108,26 +137,31 @@
         return osName.indexOf("windows") > -1;
     }
 
-    public static File createTempFile(String prefix, String suffix) {
-        return createTempFile(prefix, suffix, null, true);
+    public static File createTempFile(String prefix, String suffix) throws IOException {
+        return createTempFile(prefix, suffix, null, false);
     }
-
+    
     public static File createTempFile(String prefix, String suffix, File parentDir,
-                               boolean deleteOnExit) {
+                               boolean deleteOnExit) throws IOException {
         File result = null;
-        String parent = (parentDir == null)
-            ? System.getProperty("java.io.tmpdir")
-            : parentDir.getPath();
-
-        DecimalFormat fmt = new DecimalFormat("#####");
-        synchronized (rand) {
-            do {
-                result = new File(parent,
-                                  prefix + fmt.format(Math.abs(rand.nextInt()))
-                                  + suffix);
-            } while (result.exists());
-        }
-        if (deleteOnExit) {
+        File parent = (parentDir == null)
+            ? getDefaultTempDir()
+            : parentDir;
+            
+        if (suffix == null) {
+            suffix = ".tmp";
+        }
+        if (prefix == null) {
+            prefix = "cxf";
+        } else if (prefix.length() < 3) {
+            prefix = prefix + "cxf";
+        }
+        result = File.createTempFile(prefix, suffix, parent);
+
+        //if parentDir is null, we're in our default dir
+        //which will get completely wiped on exit from our exit
+        //hook.  No need to set deleteOnExit() which leaks memory.
+        if (deleteOnExit && parentDir != null) {
             result.deleteOnExit();
         }
         return result;

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java Wed Oct 10 11:57:20 2007
@@ -164,19 +164,4 @@
         in.close();
         return bos.toByteArray();
     }
-    
-    //class to create a BAIS from a BAOS but without the copies of the byte[] into
-    //one of the exact size.
-    static class LoadingByteArrayOutputStream extends ByteArrayOutputStream {
-        public LoadingByteArrayOutputStream() {
-            super(1024);
-        }
-        public LoadingByteArrayOutputStream(int i) {
-            super(i);
-        }
-        
-        public ByteArrayInputStream createInputStream() {
-            return new ByteArrayInputStream(buf, 0, count);
-        }
-    }
 }

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java?rev=583575&view=auto
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java Wed Oct 10 11:57:20 2007
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.helpers;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * Subclass of ByteArrayOutputStream that allows creation of a
+ * ByteArrayInputStream directly without creating a copy of the byte[].
+ * 
+ * Also, on "toByteArray()" it truncates it's buffer to the current size
+ * and returns the new buffer directly.  Multiple calls to toByteArray() 
+ * will return the exact same byte[] unless a write is called in between.
+ * 
+ * Note: once the InputStream is created, the output stream should
+ * no longer be used.  In particular, make sure not to call reset()
+ * and then write as that may overwrite the data that the InputStream
+ * is using.
+ */
+public class LoadingByteArrayOutputStream extends ByteArrayOutputStream {
+    public LoadingByteArrayOutputStream() {
+        super(1024);
+    }
+    public LoadingByteArrayOutputStream(int i) {
+        super(i);
+    }
+    
+    public ByteArrayInputStream createInputStream() {
+        return new ByteArrayInputStream(buf, 0, count);
+    }
+    
+    public byte[] toByteArray() {
+        if (count != buf.length) {
+            buf = super.toByteArray();
+        }
+        return buf;
+    }
+}
\ No newline at end of file

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/LoadingByteArrayOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/LoggingFeature.java Wed Oct 10 11:57:20 2007
@@ -24,15 +24,34 @@
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 
 public class LoggingFeature extends AbstractFeature {
-    private static final LoggingInInterceptor IN = new LoggingInInterceptor();
-    private static final LoggingOutInterceptor OUT = new LoggingOutInterceptor();
+    private static final int DEFAULT_LIMIT = 100 * 1024;
+    private static final LoggingInInterceptor IN = new LoggingInInterceptor(DEFAULT_LIMIT);
+    private static final LoggingOutInterceptor OUT = new LoggingOutInterceptor(DEFAULT_LIMIT);
+    
+    int limit = DEFAULT_LIMIT;
     
     @Override
     protected void initializeProvider(InterceptorProvider provider, Bus bus) {
-        provider.getInInterceptors().add(IN);
-        provider.getInFaultInterceptors().add(IN);
-        provider.getOutInterceptors().add(OUT);
-        provider.getOutFaultInterceptors().add(OUT);
+        if (limit == DEFAULT_LIMIT) {
+            provider.getInInterceptors().add(IN);
+            provider.getInFaultInterceptors().add(IN);
+            provider.getOutInterceptors().add(OUT);
+            provider.getOutFaultInterceptors().add(OUT);
+        } else {
+            LoggingInInterceptor in = new LoggingInInterceptor(limit);
+            LoggingOutInterceptor out = new LoggingOutInterceptor(limit);
+            provider.getInInterceptors().add(in);
+            provider.getInFaultInterceptors().add(in);
+            provider.getOutInterceptors().add(out);
+            provider.getOutFaultInterceptors().add(out);
+        }
     }
 
+    public void setLoggingLimit(int lim) {
+        limit = lim;
+    }
+    
+    public int getLoggingLimit() {
+        return limit;
+    }    
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java Wed Oct 10 11:57:20 2007
@@ -38,9 +38,22 @@
 
     private static final Logger LOG = LogUtils.getL7dLogger(LoggingInInterceptor.class);
 
+    private int limit = 100 * 1024;
+    
     public LoggingInInterceptor() {
         super(Phase.RECEIVE);
     }
+    public LoggingInInterceptor(int lim) {
+        super(Phase.RECEIVE);
+        limit = lim;
+    }
+    public void setLoggingLimit(int lim) {
+        limit = lim;
+    }
+    
+    public int getLoggingLimit() {
+        return limit;
+    }    
 
     public void handleMessage(Message message) throws Fault {
 
@@ -76,7 +89,11 @@
                     } else {            
                         buffer.append("\nMessage:\n");
                     }
-                    bos.writeCacheTo(buffer);
+                    if (bos.size() > limit) {
+                        buffer.append("(message truncated to " + limit + " bytes)\n");
+                    }
+                    bos.writeCacheTo(buffer, limit);
+                    
                     bos.close();
                 } catch (IOException e) {
                     throw new Fault(e);

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java Wed Oct 10 11:57:20 2007
@@ -38,10 +38,26 @@
    
     private static final Logger LOG = LogUtils.getL7dLogger(LoggingOutInterceptor.class); 
 
+    private int limit = 100 * 1024;
+    
     public LoggingOutInterceptor() {
         super(Phase.PRE_STREAM);
         addBefore(StaxOutInterceptor.class.getName());
     }
+    public LoggingOutInterceptor(int lim) {
+        super(Phase.PRE_STREAM);
+        addBefore(StaxOutInterceptor.class.getName());
+        limit = lim;
+    }
+    
+    public void setLoggingLimit(int lim) {
+        limit = lim;
+    }
+    
+    public int getLoggingLimit() {
+        return limit;
+    }    
+
     
     public void handleMessage(Message message) throws Fault {
         final OutputStream os = message.getContent(OutputStream.class);
@@ -70,14 +86,20 @@
             
             if (cos.getTempFile() == null) {
                 buffer.append("Outbound Message:\n");
+                if (cos.size() > limit) {
+                    buffer.append("(message truncated to " + limit + " bytes)\n");
+                }
                 buffer.append("--------------------------------------\n");
             } else {
                 buffer.append("Outbound Message (saved to tmp file):\n");
                 buffer.append("Filename: " + cos.getTempFile().getAbsolutePath() + "\n");
+                if (cos.size() > limit) {
+                    buffer.append("(message truncated to " + limit + " bytes)\n");
+                }
                 buffer.append("--------------------------------------\n");
             }
             try {
-                cos.writeCacheTo(buffer);
+                cos.writeCacheTo(buffer, limit);
             } catch (Exception ex) {
                 //ignore
             }

Modified: incubator/cxf/trunk/rt/core/src/main/resources/schemas/core.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/schemas/core.xsd?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/schemas/core.xsd (original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/schemas/core.xsd Wed Oct 10 11:57:20 2007
@@ -45,6 +45,7 @@
     </xsd:annotation>
     <xsd:complexType>
       <xsd:sequence />
+      <xs:attribute name="limit" type="xsd:int" use="optional" default="102400"/>
     </xsd:complexType>
   </xsd:element>
   

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java Wed Oct 10 11:57:20 2007
@@ -85,6 +85,7 @@
 
                         obj = new StreamSource(cos.getInputStream());
                         message.setContent(Source.class, new StreamSource(cos.getInputStream()));
+                        cos.close();
                     } catch (Exception e) {
                         throw new Fault(e);
                     }
@@ -98,8 +99,11 @@
                         Transformer transformer = XMLUtils.newTransformer();
 
                         transformer.transform(obj, new StreamResult(cos));
-                        SOAPMessage msg = initSOAPMessage(cos.getInputStream());
+                        InputStream in = cos.getInputStream();
+                        SOAPMessage msg = initSOAPMessage(in);
                         source = new DOMSource(((SOAPMessage)msg).getSOAPBody().getFirstChild());
+                        in.close();
+                        cos.close();
                     } catch (Exception e) {
                         throw new Fault(e);
                     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java Wed Oct 10 11:57:20 2007
@@ -230,7 +230,10 @@
                         CachedOutputStream cos = new CachedOutputStream();
                         Transformer transformer = XMLUtils.newTransformer();
                         transformer.transform(source, new StreamResult(cos));
-                        obj = newSOAPMessage(cos.getInputStream(), ((SoapMessage)message).getVersion());
+                        InputStream in = cos.getInputStream();
+                        obj = newSOAPMessage(in, ((SoapMessage)message).getVersion());
+                        in.close();
+                        cos.close();
                     } catch (Exception e) {
                         throw new Fault(e);
                     } 
@@ -286,6 +289,8 @@
         dataReader.setProperty(JAXBDataBinding.UNWRAP_JAXB_ELEMENT, Boolean.FALSE);
 
         Object obj = dataReader.read(null, reader, null);
+        reader.close();
+        cos.close();
         
         return obj;
         

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutDatabindingInterceptor.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutDatabindingInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutDatabindingInterceptor.java Wed Oct 10 11:57:20 2007
@@ -237,7 +237,10 @@
                         CachedOutputStream cos = new CachedOutputStream();
                         Transformer transformer = XMLUtils.newTransformer();
                         transformer.transform(source, new StreamResult(cos));
-                        obj = newSOAPMessage(cos.getInputStream(), ((SoapMessage)message).getVersion());
+                        InputStream in = cos.getInputStream();
+                        obj = newSOAPMessage(in, ((SoapMessage)message).getVersion());
+                        in.close();
+                        cos.close();
                     } catch (Exception e) {
                         throw new Fault(e);
                     }
@@ -278,7 +281,7 @@
         }
         if (obj instanceof DataSource) {
             InputStream is = ((DataSource)obj).getInputStream();
-            IOUtils.copy(((DataSource)obj).getInputStream(), os);
+            IOUtils.copy(is, os);
             is.close();
         }
     }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java Wed Oct 10 11:57:20 2007
@@ -100,7 +100,7 @@
                 Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                 if (outboundProperty.booleanValue()) {
                     try {
-                        smc.setMessage(preparemSOAPMessage("resources/greetMeRpcLitRespChanged.xml"));
+                        smc.setMessage(prepareSOAPMessage("resources/greetMeRpcLitRespChanged.xml"));
                     } catch (Exception e) {
                         throw new Fault(e);
                     }
@@ -232,7 +232,7 @@
         message.setExchange(exchange);
         XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
         message.setContent(XMLStreamReader.class, reader);
-        Object[] headerInfo = preparemSOAPHeader();
+        Object[] headerInfo = prepareSOAPHeader();
         
         message.setContent(Node.class, headerInfo[0]);
         
@@ -343,7 +343,7 @@
                                           soapVersion.getNamespace());
                     writer.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
                     
-                    Object[] headerInfo = preparemSOAPHeader();
+                    Object[] headerInfo = prepareSOAPHeader();
                     StaxUtils.writeElement((Element) headerInfo[1], writer, true, false);
                     
                     writer.writeEndElement();
@@ -372,6 +372,7 @@
         SOAPHeaderElement headerElementNew = (SOAPHeaderElement)itNew.next();
         SoapVersion soapVersion = Soap11.getInstance();
         assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
+        originalEmptyOs.close();
     }
 
     @Test
@@ -512,7 +513,7 @@
         return xmlReader;
     }
 
-    private Object[] preparemSOAPHeader() throws Exception {
+    private Object[] prepareSOAPHeader() throws Exception {
         Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
         SoapVersion soapVersion = Soap11.getInstance();
         Element envElement = doc.createElementNS(soapVersion.getEnvelope().getNamespaceURI(),
@@ -536,7 +537,7 @@
         return new Object[] {doc, headerElement};
     }
 
-    private SOAPMessage preparemSOAPMessage(String resouceName) throws Exception {
+    private SOAPMessage prepareSOAPMessage(String resouceName) throws Exception {
         InputStream is = this.getClass().getResourceAsStream(resouceName);
         SOAPMessage soapMessage = null;
         MessageFactory factory = MessageFactory.newInstance();
@@ -546,7 +547,7 @@
     }
 
     private CachedStream prepareOutputStreamFromResource(String resouceName) throws Exception {
-        SOAPMessage soapMessage = preparemSOAPMessage(resouceName);
+        SOAPMessage soapMessage = prepareSOAPMessage(resouceName);
         CachedStream os = new CachedStream();
         soapMessage.writeTo(os);
         return os;

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Wed Oct 10 11:57:20 2007
@@ -334,7 +334,7 @@
      * causes an injection of the Spring configuration properties
      * of this Conduit.
      */
-    void finalizeConfig() {
+    protected void finalizeConfig() {
         // See if not set by configuration, if there are defaults
         // in order from the Endpoint, Service, or Bus.
         

Modified: incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMMessageConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMMessageConstants.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMMessageConstants.java (original)
+++ incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMMessageConstants.java Wed Oct 10 11:57:20 2007
@@ -39,8 +39,8 @@
     public static final String ORIGINAL_REQUESTOR_ROLE =
         "org.apache.cxf.client.original";
     
-    public static final String SAVED_OUTPUT_STREAM =
-        "org.apache.cxf.ws.rm.outputstream";
+    public static final String SAVED_CONTENT =
+        "org.apache.cxf.ws.rm.content";
     
     /**
      * Prevents instantiation. 

Modified: incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RetransmissionCallback.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RetransmissionCallback.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RetransmissionCallback.java (original)
+++ incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RetransmissionCallback.java Wed Oct 10 11:57:20 2007
@@ -48,7 +48,7 @@
     }
     public void onClose(CachedOutputStream cos) {
    
-        message.put(RMMessageConstants.SAVED_OUTPUT_STREAM, cos.getOut());
+        //REVISIT - would be nice to keep the cache on disk intead of in-memory 
         byte bytes[] = null;
         try {
             bytes = cos.getBytes();
@@ -57,6 +57,8 @@
                                                                    LOG, 
                                                                    cos.getOut().getClass()));
         }
+        
+        message.put(RMMessageConstants.SAVED_CONTENT, bytes);            
         manager.getRetransmissionQueue().addUnacknowledged(message);
         
         RMStore store = manager.getStore();

Modified: incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RetransmissionQueueImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RetransmissionQueueImpl.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RetransmissionQueueImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RetransmissionQueueImpl.java Wed Oct 10 11:57:20 2007
@@ -20,7 +20,6 @@
 package org.apache.cxf.ws.rm.soap;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.math.BigInteger;
@@ -328,15 +327,17 @@
                     }
                 }
             }
-            ByteArrayOutputStream savedOutputStream = (ByteArrayOutputStream)message
-                .get(RMMessageConstants.SAVED_OUTPUT_STREAM);
-            byte[] content = null;
-            if (null == savedOutputStream) {                
+            byte[] content = (byte[])message
+                .get(RMMessageConstants.SAVED_CONTENT);
+            if (null == content) {                
                 content = message.getContent(byte[].class); 
-                LOG.fine("Using saved byte array: " + content);
+                if (LOG.isLoggable(Level.FINE)) {
+                    LOG.fine("Using saved byte array: " + content);
+                }
             } else {
-                content = savedOutputStream.toByteArray();
-                LOG.fine("Using saved output stream: " + savedOutputStream);
+                if (LOG.isLoggable(Level.FINE)) {
+                    LOG.fine("Using saved output stream: " + new String(content));
+                }
             }
             ByteArrayInputStream bis = new ByteArrayInputStream(content);
 

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java Wed Oct 10 11:57:20 2007
@@ -111,7 +111,7 @@
         htmlFile.close();
         html.close();
         
-        assertEquals("Can't get the right test html", html.getOut().toString(), response.getOut().toString());
+        assertEquals("Can't get the right test html", html.toString(), response.toString());
         
         
         

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/InMessageRecorder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/InMessageRecorder.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/InMessageRecorder.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/InMessageRecorder.java Wed Oct 10 11:57:20 2007
@@ -19,7 +19,6 @@
 package org.apache.cxf.systest.ws.util;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -28,6 +27,7 @@
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -50,7 +50,7 @@
             return;
         }
 
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        LoadingByteArrayOutputStream bos = new LoadingByteArrayOutputStream();
         try {
             IOUtils.copy(is, bos);
             is.close();
@@ -59,7 +59,7 @@
             if (LOG.isLoggable(Level.FINE)) {
                 LOG.fine("inbound: " + bos.toString());
             }
-            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+            ByteArrayInputStream bis = bos.createInputStream();
             message.setContent(InputStream.class, bis);
         } catch (Exception ex) {
             ex.printStackTrace();

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/Compiler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/Compiler.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/Compiler.java (original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/Compiler.java Wed Oct 10 11:57:20 2007
@@ -27,6 +27,8 @@
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.cxf.helpers.FileUtils;
+
 public class Compiler {
     public boolean compileFiles(String[] files, File outputDir) {
         List<String> list = new ArrayList<String>();
@@ -56,12 +58,11 @@
     public boolean internalCompile(String[] args, int sourceFileIndex) {
         Process p = null;
         String cmdArray[] = null;
-      
+        File tmpFile = null;
         try {
             if (isLongCommandLines(args) && sourceFileIndex >= 0) {
                 PrintWriter out = null;
-                File tmpFile = File.createTempFile("cxf-compiler", null);
-                tmpFile.deleteOnExit();
+                tmpFile = FileUtils.createTempFile("cxf-compiler", null);
                 out = new PrintWriter(new FileWriter(tmpFile));
                 for (int i = sourceFileIndex; i < args.length; i++) {
                     if (args[i].indexOf(" ") > -1) {
@@ -122,6 +123,11 @@
         } catch (IOException e) {
             System.err.print("[ERROR] IOException during exec() of compiler \"" + args[0] + "\"");
             System.err.println(". Check your path environment variable.");
+        } finally {
+            if (tmpFile != null
+                && tmpFile.exists()) {
+                FileUtils.delete(tmpFile);
+            }
         }
 
         return false;

Modified: incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java (original)
+++ incubator/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java Wed Oct 10 11:57:20 2007
@@ -163,9 +163,12 @@
         Map<String, String> nsPkgMap = context.getNamespacePackageMap();
         for (String ns : nsPkgMap.keySet()) {
             File file = JAXBUtils.getPackageMappingSchemaBindingFile(ns, context.mapPackageName(ns));
-            InputSource ins = new InputSource(file.toURI().toString());
-            schemaCompiler.parseSchema(ins);
-            FileUtils.delete(file);
+            try {
+                InputSource ins = new InputSource(file.toURI().toString());
+                schemaCompiler.parseSchema(ins);
+            } finally {
+                FileUtils.delete(file);                
+            }
         }
         
         if (context.getPackageName() != null) {

Modified: incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java?rev=583575&r1=583574&r2=583575&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java (original)
+++ incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/wsdl11/JAXWSDefinitionBuilder.java Wed Oct 10 11:57:20 2007
@@ -176,7 +176,7 @@
     }
 
     private Definition buildCustomizedDefinition() throws Exception {
-        File tmpFile = File.createTempFile("customzied", ".wsdl");
+        File tmpFile = FileUtils.createTempFile("customzied", ".wsdl");
         OutputStream outs = new FileOutputStream(tmpFile);
         DOMUtils.writeXml(getCustomizationParser().getCustomizedWSDLElement(), outs);
         InputStream ins = new FileInputStream(new File(tmpFile.toURI()));