From: <bra...@us...> - 2011-03-09 05:45:02
|
Revision: 3423 http://archive-access.svn.sourceforge.net/archive-access/?rev=3423&view=rev Author: bradtofel Date: 2011-03-09 05:44:56 +0000 (Wed, 09 Mar 2011) Log Message: ----------- BUGFIXES(unreported): Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/URLtoARCCacher.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/URLtoARCCacher.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/URLtoARCCacher.java 2011-03-09 05:41:43 UTC (rev 3422) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/URLtoARCCacher.java 2011-03-09 05:44:56 UTC (rev 3423) @@ -24,6 +24,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.ConnectException; +import java.net.NoRouteToHostException; +import java.net.SocketException; import java.net.UnknownHostException; import java.util.Date; import java.util.logging.Logger; @@ -34,10 +36,13 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpConnection; import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpMethodRetryHandler; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.SimpleHttpConnectionManager; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.cookie.CookiePolicy; +import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.io.IOUtils; import org.archive.httpclient.HttpRecorderGetMethod; import org.archive.io.RecordingInputStream; @@ -76,16 +81,18 @@ private int inBufferSize = 1024 * 100; // private int outBufferSize = 10; // private int inBufferSize = 100; + private final static HttpMethodRetryHandler noRetryHandler = + new NoRetryHandler(); private final ThreadLocal<HttpClient> tl = new ThreadLocal<HttpClient>() { protected synchronized HttpClient initialValue() { - HttpClient http = new HttpClient(); + HttpClientParams params = new HttpClientParams(); + params.setParameter(HttpClientParams.RETRY_HANDLER, noRetryHandler); IPHttpConnectionManager manager = new IPHttpConnectionManager(); manager.getParams().setConnectionTimeout(connectionTimeoutMS); manager.getParams().setSoTimeout(socketTimeoutMS); - http.setHttpConnectionManager(manager); - return http; + return new HttpClient(params, manager); } }; @@ -134,9 +141,11 @@ getMethod.setRequestHeader("User-Agent", userAgent); int code = client.executeMethod(getMethod); LOGGER.info("URL(" + url + ") HTTP:" + code); - InputStream responseIS = getMethod.getResponseBodyAsStream(); - ByteOp.discardStream(responseIS); - responseIS.close(); + InputStream responseIS = getMethod.getResponseBodyAsStream(); + if(responseIS != null) { + ByteOp.discardStream(responseIS); + responseIS.close(); + } gotUrl = true; } catch (URIException e) { @@ -148,7 +157,11 @@ // LOGGER.warning("Timeout out connecting to " + url); } catch (ConnectException e) { LOGGER.warning("ConnectionRefused to " + url); - + } catch (NoRouteToHostException e) { + LOGGER.warning("NoRouteToHost for " + url); + } catch (SocketException e) { + // should only be things like "Connection Reset", etc.. + LOGGER.warning("SocketException for " + url); } catch (HttpException e) { e.printStackTrace(); // we have to let IOExceptions out, problems caused by local disk This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |