velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r687524 - /velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
Date Thu, 21 Aug 2008 00:33:34 GMT
Author: nbubna
Date: Wed Aug 20 17:33:34 2008
New Revision: 687524

URL: http://svn.apache.org/viewvc?rev=687524&view=rev
Log:
VELOCITY-585 allow a timeout to be set for URLResourceLoader

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java?rev=687524&r1=687523&r2=687524&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java
Wed Aug 20 17:33:34 2008
@@ -41,6 +41,7 @@
 {
     private String[] roots = null;
     protected HashMap templateRoots = null;
+    private int timeout = -1;
 
     /**
      * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
@@ -50,7 +51,6 @@
         log.trace("URLResourceLoader : initialization starting.");
 
         roots = configuration.getStringArray("root");
-
         if (log.isDebugEnabled())
         {
             for (int i=0; i < roots.length; i++)
@@ -59,6 +59,12 @@
             }
         }
 
+        timeout = configuration.getInt("timeout", -1);
+        if (timeout > 0)
+        {
+            log.debug("URLResourceLoader : timeout set to "+timeout);
+        }
+
         // init the template paths map
         templateRoots = new HashMap();
 
@@ -89,7 +95,13 @@
             try
             {
                 URL u = new URL(roots[i] + name);
-                inputStream = u.openStream();
+                URLConnection conn = u.openConnection();
+                if (timeout > 0)
+                {
+                    conn.setConnectTimeout(10000);
+                    conn.setReadTimeout(10000);
+                }
+                inputStream = conn.getInputStream();
 
                 if (inputStream != null)
                 {
@@ -166,6 +178,11 @@
             // get a connection to the URL
             URL u = new URL(root + name);
             URLConnection conn = u.openConnection();
+            if (timeout > 0)
+            {
+                conn.setConnectTimeout(timeout);
+                conn.setReadTimeout(timeout);
+            }
             return conn.getLastModified();
         }
         catch (IOException ioe)



Mime
View raw message