Revision: 3405 http://archive-access.svn.sourceforge.net/archive-access/?rev=3405&view=rev Author: bradtofel Date: 2011-02-06 14:49:24 +0000 (Sun, 06 Feb 2011) Log Message: ----------- FEATURE: Exposed connect and socket timeouts, which are now caught, capturing IllegalArugmentException on GetMethod.. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java 2011-02-06 14:48:05 UTC (rev 3404) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java 2011-02-06 14:49:24 UTC (rev 3405) @@ -22,9 +22,12 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.ConnectException; +import java.net.SocketTimeoutException; import java.net.URL; +import java.util.logging.Logger; import java.util.zip.GZIPInputStream; +import org.apache.commons.httpclient.ConnectTimeoutException; import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; @@ -43,10 +46,13 @@ * */ public class RemoteLiveWebCache implements LiveWebCache { + private static final Logger LOGGER = Logger.getLogger( + RemoteLiveWebCache.class.getName()); private MultiThreadedHttpConnectionManager connectionManager = null; private HostConfiguration hostConfiguration = null; private HttpClient http = null; + /** * */ @@ -57,14 +63,21 @@ http.setHostConfiguration(hostConfiguration); } - /* (non-Javadoc) + /* (non-Javadoc) * @see org.archive.wayback.liveweb.LiveWebCache#getCachedResource(java.net.URL, long, boolean) */ public Resource getCachedResource(URL url, long maxCacheMS, boolean bUseOlder) throws LiveDocumentNotAvailableException, LiveWebCacheUnavailableException, IOException { String urlString = url.toExternalForm(); - HttpMethod method = new GetMethod(urlString); + HttpMethod method = null; + try { + method = new GetMethod(urlString); + } catch(IllegalArgumentException e) { + LOGGER.warning("Bad URL for live web fetch:" + urlString); + throw new LiveDocumentNotAvailableException("Url:" + urlString + + "does not look like an URL?"); + } try { int status = http.executeMethod(method); if(status == 200) { @@ -84,9 +97,16 @@ } } catch (ResourceNotAvailableException e) { throw new LiveDocumentNotAvailableException(urlString); + } catch (ConnectException e) { throw new LiveWebCacheUnavailableException(e.getLocalizedMessage() + " : " + urlString); + } catch (SocketTimeoutException e) { + throw new LiveWebCacheUnavailableException(e.getLocalizedMessage() + + " : " + urlString); + } catch(ConnectTimeoutException e) { + throw new LiveWebCacheUnavailableException(e.getLocalizedMessage() + + " : " + urlString); } finally { method.releaseConnection(); } @@ -127,4 +147,31 @@ connectionManager.getParams(). setMaxConnectionsPerHost(hostConfiguration, maxHostConnections); } + /** + * @return the connectionTimeoutMS + */ + public int getConnectionTimeoutMS() { + return connectionManager.getParams().getConnectionTimeout(); + } + + /** + * @param connectionTimeoutMS the connectionTimeoutMS to set + */ + public void setConnectionTimeoutMS(int connectionTimeoutMS) { + connectionManager.getParams().setConnectionTimeout(connectionTimeoutMS); + } + + /** + * @return the socketTimeoutMS + */ + public int getSocketTimeoutMS() { + return connectionManager.getParams().getSoTimeout(); + } + + /** + * @param socketTimeoutMS the socketTimeoutMS to set + */ + public void setSocketTimeoutMS(int socketTimeoutMS) { + connectionManager.getParams().setSoTimeout(socketTimeoutMS); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
Revision: 3471 http://archive-access.svn.sourceforge.net/archive-access/?rev=3471&view=rev Author: bradtofel Date: 2011-06-16 17:03:23 +0000 (Thu, 16 Jun 2011) Log Message: ----------- BUGFIX: was reporting LiveWebCacheUnavailable when it should have been a timeout. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java 2011-06-16 17:01:54 UTC (rev 3470) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java 2011-06-16 17:03:23 UTC (rev 3471) @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.ConnectException; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URL; import java.util.logging.Logger; @@ -32,6 +33,7 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.NoHttpResponseException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpClientParams; import org.archive.io.arc.ARCRecord; @@ -99,17 +101,26 @@ } else { throw new LiveWebCacheUnavailableException(urlString); } + } catch (ResourceNotAvailableException e) { throw new LiveDocumentNotAvailableException(urlString); + } catch (NoHttpResponseException e) { + + throw new LiveWebCacheUnavailableException("No Http Response for " + + urlString); + } catch (ConnectException e) { throw new LiveWebCacheUnavailableException(e.getLocalizedMessage() + " : " + urlString); + } catch (SocketException e) { + throw new LiveWebCacheUnavailableException(e.getLocalizedMessage() + + " : " + urlString); } catch (SocketTimeoutException e) { throw new LiveWebTimeoutException(e.getLocalizedMessage() + " : " + urlString); } catch(ConnectTimeoutException e) { - throw new LiveWebCacheUnavailableException(e.getLocalizedMessage() + throw new LiveWebTimeoutException(e.getLocalizedMessage() + " : " + urlString); } finally { method.releaseConnection(); @@ -145,13 +156,29 @@ setMaxTotalConnections(maxTotalConnections); } /** + * @return the HttpConnectionManagerParams maxTotalConnections config + */ + public int getMaxTotalConnections() { + return connectionManager.getParams().getMaxTotalConnections(); + } + + /** * @param maxHostConnections the HttpConnectionManagerParams config */ public void setMaxHostConnections(int maxHostConnections) { connectionManager.getParams(). setMaxConnectionsPerHost(hostConfiguration, maxHostConnections); } - /** + + /** + * @return the HttpConnectionManagerParams maxHostConnections config + */ + public int getMaxHostConnections() { + return connectionManager.getParams(). + getMaxConnectionsPerHost(hostConfiguration); + } + + /** * @return the connectionTimeoutMS */ public int getConnectionTimeoutMS() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
Revision: 3544 http://archive-access.svn.sourceforge.net/archive-access/?rev=3544&view=rev Author: bradtofel Date: 2011-10-25 00:55:07 +0000 (Tue, 25 Oct 2011) Log Message: ----------- FEATURE: now checks for 504 responses, which cause a LiveWebTimeoutException Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java 2011-10-25 00:54:34 UTC (rev 3543) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/RemoteLiveWebCache.java 2011-10-25 00:55:07 UTC (rev 3544) @@ -87,6 +87,7 @@ try { int status = http.executeMethod(method); if(status == 200) { + ByteArrayInputStream bais = new ByteArrayInputStream(method.getResponseBody()); ARCRecord r = new ARCRecord( new GZIPInputStream(bais), @@ -95,6 +96,8 @@ ResourceFactory.ARCArchiveRecordToResource(r, null); if(ar.getStatusCode() == 502) { throw new LiveDocumentNotAvailableException(urlString); + } else if(ar.getStatusCode() == 504) { + throw new LiveWebTimeoutException("Timeout:" + urlString); } return ar; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |