[java-opensaml COMMIT] in /trunk/opensaml-util/src/main/java/org/opensaml/util: net/HttpResource.java resource/Cachin...

noreply at shibboleth.net noreply at shibboleth.net
Fri Sep 23 11:51:14 BST 2011


Author: lajoie
Date: Fri Sep 23 11:51:13 2011
New Revision: 2906

URL: http://svn.shibboleth.net/view/java-opensaml?rev=2906&view=rev
Log:
Add new method that allows for indicating you want the cache copy returned even if it hasn't been changed

Modified:
    trunk/opensaml-util/src/main/java/org/opensaml/util/net/HttpResource.java
    trunk/opensaml-util/src/main/java/org/opensaml/util/resource/CachingResource.java

Modified: trunk/opensaml-util/src/main/java/org/opensaml/util/net/HttpResource.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-util/src/main/java/org/opensaml/util/net/HttpResource.java?rev=2906&r1=2905&r2=2906&view=diff
==============================================================================
--- trunk/opensaml-util/src/main/java/org/opensaml/util/net/HttpResource.java (original)
+++ trunk/opensaml-util/src/main/java/org/opensaml/util/net/HttpResource.java Fri Sep 23 11:51:13 2011
@@ -52,13 +52,17 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+//TODO add fewer-arg convenience constructor(s)
+//TODO authentication
+//TODO deal with case where cache file(s) are removed unexpectedly
+//TODO consider if we want to allow a mode of operation that doesn't cache files 
+
 /**
  * A resource that fetches data from a remote source via HTTP. A backup/cache of the data is maintained in a local file.
  * The backup file is used if a conditional get, based on the ETag and last modified time, indicates that the data has
  * not been modified or if there is a problem fetching the data from the remote source (e.g. if the remote server is
  * down).
  */
-// TODO authentication
 @NotThreadSafe
 public class HttpResource implements CachingResource, FilebackedRemoteResource {
 
@@ -97,7 +101,7 @@
 
     /** Last modified time associated with cached metadata. */
     private String cachedResourceLastModified;
-
+    
     /**
      * Constructor.
      * 
@@ -268,7 +272,7 @@
     /** {@inheritDoc} */
     public InputStream getInputStreamFromBackupFile() throws ResourceException {
         log.debug("Reading HTTP resource from backup file {}", backupFile.getAbsolutePath());
-        
+
         if (!backupFile.exists()) {
             log.debug("Backup file {} does not exist, unable to read data from it", backupFile.getAbsolutePath());
             return null;
@@ -279,6 +283,17 @@
         } catch (IOException e) {
             throw new ResourceException("Unable to read backup file " + getBackupFilePath(), e);
         }
+    }
+
+    /** {@inheritDoc} */
+    public InputStream getInputStream(boolean returnCache) throws ResourceException {
+        InputStream ins = getInputStream();
+
+        if (ins == null && returnCache) {
+            ins = getInputStreamFromBackupFile();
+        }
+
+        return ins;
     }
 
     /**
@@ -415,7 +430,7 @@
         }
         if (!tmpDataFile.renameTo(backupFile)) {
             tmpDataFile.delete();
-            if(tmpPropFile.exists()){
+            if (tmpPropFile.exists()) {
                 tmpPropFile.delete();
             }
             log.debug("Unable to copy temporary data file to {}", backupFile.getAbsolutePath());

Modified: trunk/opensaml-util/src/main/java/org/opensaml/util/resource/CachingResource.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-util/src/main/java/org/opensaml/util/resource/CachingResource.java?rev=2906&r1=2905&r2=2906&view=diff
==============================================================================
--- trunk/opensaml-util/src/main/java/org/opensaml/util/resource/CachingResource.java (original)
+++ trunk/opensaml-util/src/main/java/org/opensaml/util/resource/CachingResource.java Fri Sep 23 11:51:13 2011
@@ -16,6 +16,8 @@
  */
 
 package org.opensaml.util.resource;
+
+import java.io.InputStream;
 
 /**
  * A {@link Resource} which may cache the fetched data. This is useful when fetching data from a remote source that may
@@ -37,4 +39,15 @@
 
     /** Expires any cached resource data. */
     public void expireCache();
+    
+    /**
+     * Gets the input stream to the resource's data.
+     * 
+     * @param returnCache whether to return the cached copy {@link #getInputStream()} returns null
+     * 
+     * @return the resource data, never null
+     * 
+     * @throws ResourceException thrown if there is a problem getting the resource data
+     */
+    public InputStream getInputStream(boolean returnCache) throws ResourceException;
 }



More information about the commits mailing list