Author: julien(a)jboss.com
Date: 2007-03-07 13:16:51 -0500 (Wed, 07 Mar 2007)
New Revision: 6582
Modified:
trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java
Log:
improve a bit timeout stuff
Modified: trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-03-07 17:54:30
UTC (rev 6581)
+++ trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-03-07 18:16:51
UTC (rev 6582)
@@ -60,7 +60,9 @@
/**
* Fetches content from an HTTP server performing a GET operation. If the status code
is 200
- * then it will return a byte array of the body otherwise returns null.
+ * then it will return a byte array of the body otherwise returns null. The timeout
values
+ * must not be negative integers, when it is equals to zero it means that it does not
setup
+ * a timeout and use the default values.
*
* @param url the URL the URL of the resource
* @param soTimeoutMillis the socket connection timeout in millis
@@ -73,13 +75,27 @@
{
throw new IllegalArgumentException();
}
+ if (soTimeoutMillis < 0)
+ {
+ throw new IllegalArgumentException("No negative socket timeout");
+ }
+ if (connTimeoutMillis < 0)
+ {
+ throw new IllegalArgumentException("No negative connection timeout");
+ }
if ("http".equals(url.getProtocol()) ||
"https".equals(url.getProtocol()))
{
HttpClient client = new HttpClient();
// Yes deprecated but advocated way to do will not for with 2.0.2 which is what
today JBoss AS ships
- client.setConnectionTimeout(connTimeoutMillis);
- client.setTimeout(soTimeoutMillis);
+ if (connTimeoutMillis > 0)
+ {
+ client.setConnectionTimeout(connTimeoutMillis);
+ }
+ if (soTimeoutMillis > 0)
+ {
+ client.setTimeout(soTimeoutMillis);
+ }
//
HttpMethod method = null;
Modified: trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java 2007-03-07
17:54:30 UTC (rev 6581)
+++ trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java 2007-03-07
18:16:51 UTC (rev 6582)
@@ -24,7 +24,10 @@
import junit.framework.TestCase;
import org.jboss.portal.common.util.URLTools;
+import org.apache.log4j.net.SocketServer;
+import java.net.URL;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$