Revision: 3288 http://archive-access.svn.sourceforge.net/archive-access/?rev=3288&view=rev Author: bradtofel Date: 2010-10-21 00:37:52 +0000 (Thu, 21 Oct 2010) Log Message: ----------- FEATURE: added 'retries' property which determines the number of attempts to grab a document when receiving HTTP 502 errors. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/SimpleResourceStore.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/SimpleResourceStore.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/SimpleResourceStore.java 2010-10-18 22:24:46 UTC (rev 3287) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourcestore/SimpleResourceStore.java 2010-10-21 00:37:52 UTC (rev 3288) @@ -43,7 +43,10 @@ private final static Logger LOGGER = Logger.getLogger( SimpleResourceStore.class.getName()); + private static String HTTP_ERROR = "HTTP"; + private static String HTTP_502 = "502"; private String prefix = null; + private int retries = 2; public Resource retrieveResource(CaptureSearchResult result) throws ResourceNotAvailableException { @@ -65,9 +68,26 @@ String fileUrl = prefix + fileName; Resource r = null; try { + int attempts = retries; + while(attempts-- > 0) { + try { + r = ResourceFactory.getResource(fileUrl, offset); + break; + } catch (IOException e) { + String message = e.getMessage(); + if(attempts > 0 + && message.contains(HTTP_ERROR) + && message.contains(HTTP_502)) { + + LOGGER.warning(String.format( + "Failed attempt for (%s) retrying with" + + " (%d) attempts left",fileUrl,attempts)); + } else { + throw e; + } + } + } - r = ResourceFactory.getResource(fileUrl, offset); - } catch (IOException e) { LOGGER.warning("Unable to retrieve:" + fileUrl + ":" + offset); e.printStackTrace(); @@ -94,4 +114,20 @@ public void shutdown() throws IOException { // no-op } + + /** + * @return the number of attempts to fetch resources with an HTTP 502 + * failure. + */ + public int getRetries() { + return retries; + } + + /** + * @param retries the number of attempts to fetch resources with an HTTP 502 + * failure. + */ + public void setRetries(int retries) { + this.retries = retries; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |