/** {@inheritDoc} */ public boolean exists() throws ResourceException { boolean httpExists; try { httpExists = super.exists(); } catch (ResourceException e) { log.warn("HTTP resource '{}' was inaccessible for exists(), trying backing file '{}'", getLocation(), resourceFile.getAbsolutePath()); return resourceFile.exists(); } if (httpExists) { return true; } else { log.warn("HTTP resource '{}' did not exist, trying backing file '{}'", getLocation(), resourceFile.getAbsolutePath()); return resourceFile.exists(); } }
/** {@inheritDoc} */ public InputStream getInputStream() throws ResourceException { InputStream ins = null; try { GetMethod getMethod = super.getResource(); byte[] response = getMethod.getResponseBody(); saveToResourceFile(response); ins = getMethod.getResponseBodyAsStream(); } catch (Exception e) { try { log.warn("HTTP resource '{}' was inaccessible for getInputStream(), trying backing file '{}'", getLocation(), resourceFile.getAbsolutePath()); ins = new FileInputStream(resourceFile); } catch (IOException ioe) { throw new ResourceException("Unable to read resource URL or backing file " + resourceFile.getAbsolutePath(), ioe); } } return applyFilter(ins); }
/** {@inheritDoc} */ public DateTime getLastModifiedTime() throws ResourceException { try { return super.getLastModifiedTime(); } catch (ResourceException e) { log.warn("HTTP resource '{}' was inaccessible for getLastModifiedTime(), trying backing file '{}'", getLocation(), resourceFile.getAbsolutePath()); long lastModifiedTime = resourceFile.lastModified(); if (lastModifiedTime == 0) { throw new ResourceException("URL resource is not reachable and backing file is not readable"); } return new DateTime(lastModifiedTime, ISOChronology.getInstanceUTC()); } }