r9987 - helma/helma/trunk/src/helma/scripting/rhino
[email protected] Tue, 10 Nov 2009 09:47:01 +0100 (CET)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20091110084701.C56CB3D0E2@mia> |
Author: hannes
Date: 2009-11-10 09:47:01 +0100 (Tue, 10 Nov 2009)
New Revision: 9987
Modified:
helma/helma/trunk/src/helma/scripting/rhino/GlobalObject.java
Log:
Patch from J?\195?\188rg Lehni to add timeout argument to global getURL() function.
Fixes bug #692 - http://dev.helma.org/bugs/show_bug.cgi?id=692
Details at http://dev.helma.org/trac/helma/changeset/9987
Modified: helma/helma/trunk/src/helma/scripting/rhino/GlobalObject.java
===================================================================
--- helma/helma/trunk/src/helma/scripting/rhino/GlobalObject.java 2009-11-05 10:15:53 UTC (rev 9986)
+++ helma/helma/trunk/src/helma/scripting/rhino/GlobalObject.java 2009-11-10 08:47:01 UTC (rev 9987)
@@ -240,11 +240,13 @@
* Retrieve a Document from the specified URL.
*
* @param location the URL to retrieve
- * @param opt either a LastModified date or an ETag string for conditional GETs
+ * @param condition either a LastModified date or an ETag string for conditional GETs
+ * @param timeout the optional timeout value in milliseconds used for
+ * connecting to and reading from the given URL.
*
* @return a wrapped MIME object
*/
- public Object getURL(String location, Object opt) {
+ public Object getURL(String location, Object condition, Object timeout) {
if (location == null) {
return null;
}
@@ -254,9 +256,9 @@
URLConnection con = url.openConnection();
// do we have if-modified-since or etag headers to set?
- if (opt != null && opt != Undefined.instance) {
- if (opt instanceof Scriptable) {
- Scriptable scr = (Scriptable) opt;
+ if (condition != null && condition != Undefined.instance) {
+ if (condition instanceof Scriptable) {
+ Scriptable scr = (Scriptable) condition;
if ("Date".equals(scr.getClassName())) {
Date date = new Date((long) ScriptRuntime.toNumber(scr));
@@ -271,7 +273,7 @@
con.setRequestProperty("If-None-Match", scr.toString());
}
} else {
- con.setRequestProperty("If-None-Match", opt.toString());
+ con.setRequestProperty("If-None-Match", condition.toString());
}
}
@@ -281,6 +283,12 @@
con.setRequestProperty("User-Agent", httpUserAgent);
}
+ if (timeout != null && timeout != Undefined.instance) {
+ int time = ScriptRuntime.toInt32(timeout);
+ con.setConnectTimeout(time);
+ con.setReadTimeout(time);
+ }
+
con.setAllowUserInteraction(false);
String filename = url.getFile();