cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r582922 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/ common/common/src/main/java/org/apache/cxf/resource/ rt/core/src/main/java/org/apache/cxf/catalog/ rt/core/src/main/java/org/apache/cxf...
Date Mon, 08 Oct 2007 18:15:52 GMT
Author: dkulp
Date: Mon Oct  8 11:15:51 2007
New Revision: 582922

URL: http://svn.apache.org/viewvc?rev=582922&view=rev
Log:
Merged revisions 581385 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r581385 | dkulp | 2007-10-02 17:10:58 -0400 (Tue, 02 Oct 2007) | 2 lines
  
  Fix a bunch of issues with InputStreams not being closed from wsdl/schema processing.
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogWSDLLocator.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java

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

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=582922&r1=582921&r2=582922&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
Mon Oct  8 11:15:51 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.helpers;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -115,17 +116,48 @@
 
         return sb.toString();
     }
+    
+    /**
+     * Load the InputStream into memory and return a ByteArrayInputStream that 
+     * represents it.  Closes the in stream.
+     * @param in
+     * @return
+     * @throws IOException
+     */
+    public static ByteArrayInputStream loadIntoBAIS(InputStream in) throws IOException {
+        int i = in.available();
+        if (i < DEFAULT_BUFFER_SIZE) {
+            i = DEFAULT_BUFFER_SIZE;
+        }
+        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(i);
+        copy(in, bout);
+        in.close();
+        return bout.createInputStream();
+    }
 
     public static byte[] readBytesFromStream(InputStream in) throws IOException {
-
-        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
-
-        for (int i = in.read(); i != -1; i = in.read()) {
-            bos.write(i);
+        int i = in.available();
+        if (i < DEFAULT_BUFFER_SIZE) {
+            i = DEFAULT_BUFFER_SIZE;
         }
-
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(i);
+        copy(in, bos);
         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);
+        }
     }
 }

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java?rev=582922&r1=582921&r2=582922&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
Mon Oct  8 11:15:51 2007
@@ -66,13 +66,13 @@
     }
     
     public void close() {
-        try {
-            while (!resourceOpened.isEmpty()) {
+        while (!resourceOpened.isEmpty()) {
+            try {
                 InputStream in = resourceOpened.pop();
                 in.close();
+            } catch (IOException ioe) {
+                // move on...
             }
-        } catch (IOException ioe) {
-            // move on...
         }
     }
     

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogWSDLLocator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogWSDLLocator.java?rev=582922&r1=582921&r2=582922&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogWSDLLocator.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogWSDLLocator.java
Mon Oct  8 11:15:51 2007
@@ -39,14 +39,13 @@
     private String baseUri;
     
     public CatalogWSDLLocator(String wsdlUrl, OASISCatalogManager catalogManager) {
-        this.wsdlUrl = wsdlUrl;
-        this.baseUri = this.wsdlUrl;
+        this.baseUri = wsdlUrl;
         this.catalogResolver = catalogManager.getCatalog();
         this.resolver = new ExtendedURIResolver();
     }
 
     public InputSource getBaseInputSource() {
-        InputSource result =  resolver.resolve(baseUri, null);
+        InputSource result = resolver.resolve(baseUri, null);
         if (result == null) {
             try {
                 String s = catalogResolver.resolveSystem(baseUri);
@@ -59,12 +58,26 @@
                 //ignore
             }
         }
+        if (wsdlUrl == null
+            && result != null) {
+            wsdlUrl = result.getSystemId();
+        }
         baseUri = resolver.getURI();
         return result;
     }
 
     public String getBaseURI() {
-        return getBaseInputSource().getSystemId();
+        if (wsdlUrl == null) {
+            InputSource is = getBaseInputSource();
+            if (is.getByteStream() != null) {
+                try {
+                    is.getByteStream().close();
+                } catch (IOException e) {
+                    //ignore
+                }
+            }
+        }
+        return wsdlUrl;
     }
 
     public String getLatestImportURI() {
@@ -92,7 +105,7 @@
         if (resolvedImportLocation == null) {
             in = this.resolver.resolve(importLocation, this.baseUri);
         } else {
-            in =  this.resolver.resolve(resolvedImportLocation, null);
+            in = this.resolver.resolve(resolvedImportLocation, null);
         }
 
         // XXX: If we return null (as per javadoc), a NPE is raised in WSDL4J code.

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java?rev=582922&r1=582921&r2=582922&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java
Mon Oct  8 11:15:51 2007
@@ -19,9 +19,11 @@
 package org.apache.cxf.catalog;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.resource.ExtendedURIResolver;
 import org.apache.ws.commons.schema.XmlSchemaException;
 import org.apache.ws.commons.schema.resolver.URIResolver;
@@ -71,6 +73,22 @@
                                          + (baseUri == null
                                             ? "."
                                             : ", relative to '" + baseUri + "'."));
+        } else if (in.getByteStream() != null) {
+            //workaround bug in XmlSchema - XmlSchema is not closing the InputStreams
+            //that are returned for imports.  Thus, with a lot of services starting up 
+            //or a lot of schemas imported or similar, it's easy to run out of
+            //file handles.  We'll just load the file into a byte[] and return that.
+            try {
+                InputStream ins = IOUtils.loadIntoBAIS(in.getByteStream());
+                in.setByteStream(ins);
+            } catch (IOException e) {
+                throw new XmlSchemaException("Unable to load imported document "
+                                             + "at '" + schemaLocation + "'"
+                                             + (baseUri == null
+                                                ? "."
+                                                : ", relative to '" + baseUri + "'."),
+                                                e);
+            }
         }
 
         return in;

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java?rev=582922&r1=582921&r2=582922&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/ResourceManagerWSDLLocator.java
Mon Oct  8 11:15:51 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.wsdl11;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 
@@ -35,6 +36,8 @@
     Bus bus;
     String wsdlUrl;
     InputSource last;
+    String baseUri;
+    boolean fromParent;
     
     public ResourceManagerWSDLLocator(String wsdlUrl,
                                       WSDLLocator parent,
@@ -53,13 +56,21 @@
 
 
     public void close() {
-        if (last != null) {
-            parent.close();
+        if (!fromParent) {
+            try {
+                if (last.getByteStream() != null) {
+                    last.getByteStream().close();
+                }
+            } catch (IOException e) {
+                //ignore
+            }
         }
+        parent.close();
     }
 
     public InputSource getBaseInputSource() {
         InputSource is = parent.getBaseInputSource();
+        fromParent = true;
         if (is == null) {
             InputStream ins = bus.getExtension(ResourceManager.class).getResourceAsStream(wsdlUrl);
             is = new InputSource(ins);
@@ -71,29 +82,35 @@
                 is.setSystemId(url.toString());
                 is.setPublicId(url.toString());
             }
-            last = is;
+            fromParent = false;
+            baseUri = is.getPublicId();
         } else {
-            last = null;
+            baseUri = is.getSystemId();
         }
+        last = is;
         
         return is;
     }
 
     public String getBaseURI() {
-        getBaseInputSource();
         if (last == null) {
-            return parent.getBaseURI();
+            getBaseInputSource();
+            try {
+                if (last.getByteStream() != null) {
+                    last.getByteStream().close();
+                }
+            } catch (IOException e) {
+                //ignore
+            }
         }
-        return last.getPublicId();
+        return baseUri;
     }
 
     public InputSource getImportInputSource(String parentLocation, String importLocation)
{
-        // TODO Auto-generated method stub
         return parent.getImportInputSource(parentLocation, importLocation);
     }
 
     public String getLatestImportURI() {
-        // TODO Auto-generated method stub
         return parent.getLatestImportURI();
     }
 

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java?rev=582922&r1=582921&r2=582922&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLLocatorImpl.java
Mon Oct  8 11:15:51 2007
@@ -70,7 +70,7 @@
     }
 
     public InputSource getBaseInputSource() {
-        InputSource result =  resolve(baseUri, null);
+        InputSource result = resolve(baseUri, null);
         baseUri = resolver.getURI();
         return result;
     }



Mime
View raw message