[java-openws COMMIT] in /branches/REL_1: doc/RELEASE-NOTES.txt src/main/java/org/opensaml/util/resource/FileBackedHtt...

noreply at shibboleth.net noreply at shibboleth.net
Fri Aug 17 22:23:56 EDT 2012


Author: putmanb
Date: Fri Aug 17 22:23:56 2012
New Revision: 434

URL: http://svn.shibboleth.net/view/java-openws?rev=434&view=rev
Log:
JOWS-37: FileBackedHttpResource does not properly read backup file, during initialization, if remote file is unreachable.
Also add some logging for all cases where HTTP resource is inaccessible and fall back to backing file.

Modified:
    branches/REL_1/doc/RELEASE-NOTES.txt
    branches/REL_1/src/main/java/org/opensaml/util/resource/FileBackedHttpResource.java
    branches/REL_1/src/test/java/org/opensaml/util/resource/FilebackedHttpResourceTest.java

Modified: branches/REL_1/doc/RELEASE-NOTES.txt
URL: http://svn.shibboleth.net/view/java-openws/branches/REL_1/doc/RELEASE-NOTES.txt?rev=434&r1=433&r2=434&view=diff
==============================================================================
--- branches/REL_1/doc/RELEASE-NOTES.txt (original)
+++ branches/REL_1/doc/RELEASE-NOTES.txt Fri Aug 17 22:23:56 2012
@@ -1,6 +1,7 @@
 Changes in Release 1.4.5
 ==============================================
 [JOWS-36] - WS-Trust OnBehalfOf provider is misimplemented, should support a sequence of wildcard children rather than a single child.
+[JOWS-37] - FileBackedHttpResource does not properly read backup file, during initialization, if remote file is unreachable
 
 Changes in Release 1.4.4
 ==============================================

Modified: branches/REL_1/src/main/java/org/opensaml/util/resource/FileBackedHttpResource.java
URL: http://svn.shibboleth.net/view/java-openws/branches/REL_1/src/main/java/org/opensaml/util/resource/FileBackedHttpResource.java?rev=434&r1=433&r2=434&view=diff
==============================================================================
--- branches/REL_1/src/main/java/org/opensaml/util/resource/FileBackedHttpResource.java (original)
+++ branches/REL_1/src/main/java/org/opensaml/util/resource/FileBackedHttpResource.java Fri Aug 17 22:23:56 2012
@@ -28,6 +28,8 @@
 import org.joda.time.DateTime;
 import org.joda.time.chrono.ISOChronology;
 import org.opensaml.xml.util.DatatypeHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A resource representing a file read from an HTTP(S) location. Every time the file is successfully read from the URL
@@ -38,6 +40,9 @@
  * to disk and then returned.
  */
 public class FileBackedHttpResource extends HttpResource {
+    
+    /** Logger. */
+    private Logger log = LoggerFactory.getLogger(FileBackedHttpResource.class);
 
     /** Backing resource file. */
     private File resourceFile;
@@ -117,11 +122,23 @@
 
     /** {@inheritDoc} */
     public boolean exists() throws ResourceException {
-        if (!super.exists()) {
+        boolean httpExists;
+        try {
+            httpExists = super.exists();
+        } catch (ResourceException e) {
+            log.warn("HTTP resource '{}' was inaccesible for exists(), trying backing file '{}'", 
+                    getLocation(), resourceFile.getAbsolutePath());
             return resourceFile.exists();
         }
-
-        return true;
+        
+        if (httpExists) {
+            return true;
+        } else {
+            log.warn("HTTP resource '{}' did not exist, trying backing file '{}'",
+                    getLocation(), resourceFile.getAbsolutePath());
+            return resourceFile.exists();
+        }
+
     }
 
     /** {@inheritDoc} */
@@ -134,6 +151,8 @@
             ins = getMethod.getResponseBodyAsStream();
         } catch (Exception e) {
             try {
+                log.warn("HTTP resource '{}' was inaccesible 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 "
@@ -149,6 +168,8 @@
         try {
             return super.getLastModifiedTime();
         } catch (ResourceException e) {
+            log.warn("HTTP resource '{}' was inaccesible 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");

Modified: branches/REL_1/src/test/java/org/opensaml/util/resource/FilebackedHttpResourceTest.java
URL: http://svn.shibboleth.net/view/java-openws/branches/REL_1/src/test/java/org/opensaml/util/resource/FilebackedHttpResourceTest.java?rev=434&r1=433&r2=434&view=diff
==============================================================================
--- branches/REL_1/src/test/java/org/opensaml/util/resource/FilebackedHttpResourceTest.java (original)
+++ branches/REL_1/src/test/java/org/opensaml/util/resource/FilebackedHttpResourceTest.java Fri Aug 17 22:23:56 2012
@@ -27,6 +27,9 @@
 
     /** Path to a resource that exists. */
     private final String realResrc = "http://www.google.com";
+    

[... 47 lines stripped ...]


More information about the commits mailing list