myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r549615 - in /myfaces/trinidad/trunk/trinidad: trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/a...
Date Thu, 21 Jun 2007 21:20:39 GMT
Author: awiner
Date: Thu Jun 21 14:20:38 2007
New Revision: 549615

URL: http://svn.apache.org/viewvc?view=rev&rev=549615
Log:
TRINIDAD-73: trinidad-impl.jar file is left open during execution
- It seems that the culprit was URLConnection.getLastModified().  If that's all you do with
an URLConnection, it ends up leaving an open stream.  Force it closed in all such code paths.

Added:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/URLUtils.java
Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/CachingResourceLoader.java
    myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/ViewHandlerImpl.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/io/URLInputStreamProvider.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java

Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/CachingResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/CachingResourceLoader.java?view=diff&rev=549615&r1=549614&r2=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/CachingResourceLoader.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/CachingResourceLoader.java
Thu Jun 21 14:20:38 2007
@@ -20,11 +20,13 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 
 import java.io.InputStream;
 import java.net.URL;
 
+import java.net.UnknownServiceException;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.util.Map;
@@ -107,7 +109,7 @@
     protected InputStream getInputStream(
       URLConnection conn) throws IOException
     {
-      long lastModified = conn.getLastModified();
+      long lastModified = _getLastModified(_delegate);
 
       if (_contents == null || _contentsModified < lastModified)
       {
@@ -198,5 +200,33 @@
 
     private final URLConnection        _conn;
     private final URLStreamHandlerImpl _handler;
+  }
+
+  static private long _getLastModified(URL url) throws IOException
+  {
+    if ("file".equals(url.getProtocol()))
+    {
+      String externalForm = url.toExternalForm();
+      // Remove the "file:"
+      File file = new File(externalForm.substring(5));
+
+      return file.lastModified();
+    }
+    else
+    {
+      URLConnection connection = url.openConnection();
+      long modified = connection.getLastModified();
+      try
+      {
+        InputStream is = connection.getInputStream();
+        if (is != null)
+          is.close();
+      }
+      catch (UnknownServiceException use)
+      {
+      }
+
+      return modified;
+    }
   }
 }

Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?view=diff&rev=549615&r1=549614&r2=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
Thu Jun 21 14:20:38 2007
@@ -245,7 +245,20 @@
       URLConnection connection = url.openConnection();
       connection.setDoInput(false);
       connection.setDoOutput(false);
-      return connection.getLastModified();
+
+      long lastModified = connection.getLastModified();
+      // Make sure the connection is closed
+      try
+      {
+        InputStream is = connection.getInputStream();
+        if (is != null)
+          is.close();
+      }
+      catch (UnknownServiceException use)
+      {
+      }
+
+      return lastModified;
     }
     catch (IOException e)
     {

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/ViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/ViewHandlerImpl.java?view=diff&rev=549615&r1=549614&r2=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/ViewHandlerImpl.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/ViewHandlerImpl.java
Thu Jun 21 14:20:38 2007
@@ -45,6 +45,7 @@
 import org.apache.myfaces.trinidad.util.Service;
 import org.apache.myfaces.trinidadinternal.context.RequestContextImpl;
 import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
+import org.apache.myfaces.trinidadinternal.util.URLUtils;
 
 /**
  * ViewHandler that adds modification detection to the existing ViewHandler,
@@ -383,19 +384,7 @@
     if (url == null)
       return _NOT_FOUND;
 
-    if ("file".equals(url.getProtocol()))
-    {
-      String externalForm = url.toExternalForm();
-      // Remove the "file:"
-      File file = new File(externalForm.substring(5));
-
-      return Long.valueOf(file.lastModified());
-    }
-    else
-    {
-      long modified = url.openConnection().getLastModified();
-      return Long.valueOf(modified);
-    }
+    return Long.valueOf(URLUtils.getLastModified(url));
   }
 
 

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/io/URLInputStreamProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/io/URLInputStreamProvider.java?view=diff&rev=549615&r1=549614&r2=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/io/URLInputStreamProvider.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/io/URLInputStreamProvider.java
Thu Jun 21 14:20:38 2007
@@ -25,6 +25,8 @@
 import java.net.URL;
 import java.net.URLConnection;
 
+import org.apache.myfaces.trinidadinternal.util.URLUtils;
+
 /**
  * An InputStreamProvider for opening URLs.
  * <p>
@@ -49,6 +51,7 @@
     // to URL.openConnection
     URLConnection connection = _url.openConnection();
     _lastModifiedTime = connection.getLastModified();
+    // In theory, should not need to close
     InputStream base = connection.getInputStream();
     
     if (base instanceof BufferedInputStream)
@@ -75,8 +78,7 @@
   {
     try
     {
-      URLConnection connection = _url.openConnection();
-      long currentModifiedTime = connection.getLastModified();
+      long currentModifiedTime = URLUtils.getLastModified(_url);
       return currentModifiedTime != _lastModifiedTime;
     }
     catch (IOException ioe)

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java?view=diff&rev=549615&r1=549614&r2=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinStyleSheetParserUtils.java
Thu Jun 21 14:20:38 2007
@@ -59,6 +59,7 @@
 import org.apache.myfaces.trinidadinternal.ui.laf.xml.parse.IconNode;
 import org.apache.myfaces.trinidadinternal.ui.laf.xml.parse.SkinPropertyNode;
 import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
+import org.apache.myfaces.trinidadinternal.util.URLUtils;
 
 /**
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/skin/SkinStyleSheetParserUtils.java#0
$) $Date: 10-nov-2005.18:59:00 $
@@ -739,8 +740,7 @@
       {
         try
         {
-          URLConnection connection = ((URL)identifier).openConnection();
-          timestamp = connection.getLastModified();
+          timestamp = URLUtils.getLastModified((URL) identifier);
         }
         catch (IOException io)
         {

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java?view=diff&rev=549615&r1=549614&r2=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java
(original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleSheetDocumentParser.java
Thu Jun 21 14:20:38 2007
@@ -45,6 +45,8 @@
 import org.apache.myfaces.trinidadinternal.style.StyleConstants;
 import org.apache.myfaces.trinidadinternal.style.xml.XMLConstants;
 
+import org.apache.myfaces.trinidadinternal.util.URLUtils;
+
 /**
  * NodeParser for style sheet document nodes
  *
@@ -294,8 +296,7 @@
       {
         try
         {
-          URLConnection connection = ((URL)identifier).openConnection();
-          timestamp = connection.getLastModified();
+          timestamp = URLUtils.getLastModified((URL)identifier);
         }
         catch (IOException io)
         {

Added: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/URLUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/URLUtils.java?view=auto&rev=549615
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/URLUtils.java
(added)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/URLUtils.java
Thu Jun 21 14:20:38 2007
@@ -0,0 +1,63 @@
+/*
+ *  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.myfaces.trinidadinternal.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+
+import java.net.UnknownServiceException;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class URLUtils
+{
+  private URLUtils()
+  {
+  }
+
+
+  static public long getLastModified(URL url) throws IOException
+  {
+    if ("file".equals(url.getProtocol()))
+    {
+      String externalForm = url.toExternalForm();
+      // Remove the "file:"
+      File file = new File(externalForm.substring(5));
+
+      return file.lastModified();
+    }
+    else
+    {
+      URLConnection connection = url.openConnection();
+      long modified = connection.getLastModified();
+      try
+      {
+        InputStream is = connection.getInputStream();
+        if (is != null)
+          is.close();
+      }
+      catch (UnknownServiceException use)
+      {
+      }
+
+      return modified;
+    }
+  }
+}



Mime
View raw message