[utilities COMMIT] in /spring-extensions/trunk/src: main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResour...

noreply at shibboleth.net noreply at shibboleth.net
Thu Aug 13 09:37:45 EDT 2015


Author: rdw
Date: Thu Aug 13 09:37:44 2015
New Revision: 812

URL: http://svn.shibboleth.net/view/utilities?rev=812&view=rev
Log:
JSE-15 Add constructors to FileBackedHTTPResource

https://issues.shibboleth.net/jira/browse/JSE-15

Add two new constructors to FileBackedHTTPResource that take a String rather than a Resource.  This avoids all sorts of ResourceLoader issues and allows the file name to specified without the garnish of file:://.

The parameter order is changed to maximise backwards compatibility.

Also add tests and change the (commented) example in the IdP distribution

Added:
    spring-extensions/trunk/src/test/resources/data/newStyle.xml   (with props)
Modified:
    spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java
    spring-extensions/trunk/src/test/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResourceTest.java

Modified: spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java
URL: http://svn.shibboleth.net/view/utilities/spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java?rev=812&r1=811&r2=812&view=diff
==============================================================================
--- spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java	(original)
+++ spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/FileBackedHTTPResource.java	Thu Aug 13 09:37:44 2015
@@ -17,6 +17,7 @@
 
 package net.shibboleth.ext.spring.resource;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -33,6 +34,7 @@
 import org.apache.http.client.HttpClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.core.io.FileSystemResource;
 import org.springframework.core.io.Resource;
 
 import com.google.common.io.ByteStreams;
@@ -58,14 +60,16 @@
      * @param url URL to the remote data
      * @param resource the file to use as backing store
      * @throws IOException if the URL was badly formed
-     */
-    public FileBackedHTTPResource(@Nonnull HttpClient client, @NotEmpty @Nonnull String url, @Nonnull Resource resource)
-            throws IOException {
+     * @deprecated use {@link #FileBackedHTTPResource(String, HttpClient, String)     */
+    @Deprecated public FileBackedHTTPResource(@Nonnull HttpClient client, @NotEmpty @Nonnull String url,
+            @Nonnull Resource resource) throws IOException {
         super(client, url);
         backingResource = Constraint.isNotNull(resource, "Backing resource must not be null");
         if (null == resource.getFile()) {
             throw new IOException("Backing resource has to be file backed");
         }
+        log.warn("This constructor is deprecrated, use backingFile=\"/path/to/file\" instead "
+                + "of resource=\"file:///path/to/file\"");
     }
 
     /**
@@ -75,14 +79,46 @@
      * @param url URL to the remote data
      * @param resource the file to use as backing store
      * @throws IOException if the URL was badly formed
-     */
-    public FileBackedHTTPResource(@Nonnull HttpClient client, @Nonnull URL url, @Nonnull Resource resource)
+     * @deprecated use {@link #FileBackedHTTPResource(String, HttpClient, URL)     */
+    @Deprecated public FileBackedHTTPResource(@Nonnull HttpClient client, @Nonnull URL url, @Nonnull Resource resource)
             throws IOException {
         super(client, url);
         backingResource = Constraint.isNotNull(resource, "Backing resource must not be null");
         if (null == resource.getFile()) {
             throw new IOException("Backing resource has to be file backed");
         }
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param backingFile the file to use as backing store
+     * @param client the client we use to connect with.
+     * @param url URL to the remote data
+     * @throws IOException if the URL was badly formed
+     */
+    public FileBackedHTTPResource(@Nonnull String backingFile, @Nonnull HttpClient client, 
+            @NotEmpty @Nonnull String url) throws IOException {
+        super(client, url);
+        Constraint.isNotNull(backingFile, "File Name must not be null");
+        final File file = new File(backingFile);
+        backingResource = new FileSystemResource(file);
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param backingFile the file to use as backing store
+     * @param client the client we use to connect with.
+     * @param url URL to the remote data
+     * @throws IOException if the URL was badly formed
+     */
+    public FileBackedHTTPResource(@Nonnull String backingFile, @Nonnull HttpClient client, @Nonnull URL url)
+            throws IOException {
+        super(client, url);
+        Constraint.isNotNull(backingFile, "File Name must not be null");
+        final File file = new File(backingFile);
+        backingResource = new FileSystemResource(file);
     }
 
     /**
@@ -118,8 +154,7 @@

[... 91 lines stripped ...]


More information about the commits mailing list