Module net.shibboleth.ext.spring
Class FileBackedHTTPResource
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
-
- net.shibboleth.ext.spring.resource.HTTPResource
-
- net.shibboleth.ext.spring.resource.FileBackedHTTPResource
-
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiedComponent,InitializableComponent,Resource,Aware,BeanNameAware,InitializingBean,InputStreamSource,Resource
public class FileBackedHTTPResource extends HTTPResource
A resource representing a file read from an HTTP(S) location. Every time the file is successfully read from the URL location it is written to a backing file. If the file can not be read from the URL it is read from this backing file, if available.
-
-
Field Summary
Fields Modifier and Type Field Description private ResourcebackingResourceBacking resource file.private org.slf4j.LoggerlogLogger.
-
Constructor Summary
Constructors Constructor Description FileBackedHTTPResource(String backingFile, org.apache.http.client.HttpClient client, String url)Constructor.FileBackedHTTPResource(String backingFile, org.apache.http.client.HttpClient client, URL url)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcontentLength()HTTPResourcecreateRelative(String relativePath)Based onUrlResource.booleanexists()StringgetDescription()InputStreamgetInputStream()longlastModified()protected InputStreamsaveAndClone(InputStream input)saveAndClone.-
Methods inherited from class net.shibboleth.ext.spring.resource.HTTPResource
afterPropertiesSet, buildHttpClientContext, closeResponse, createRelativeResource, getFile, getFilename, getResourceHeaders, getResponseHeader, getURI, getURL, isOpen, isReadable, reportCachingStatus, setBeanName, setHttpClientContextHandler
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
doInitialize, getId, setId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.core.io.Resource
isFile, readableChannel
-
-
-
-
Field Detail
-
log
@Nonnull private final org.slf4j.Logger log
Logger.
-
backingResource
@Nonnull private final Resource backingResource
Backing resource file.
-
-
Constructor Detail
-
FileBackedHTTPResource
public FileBackedHTTPResource(@Nonnull @ParameterName(name="backingFile") String backingFile, @Nonnull @ParameterName(name="client") org.apache.http.client.HttpClient client, @NotEmpty @Nonnull @ParameterName(name="url") String url) throws IOException
Constructor.- Parameters:
backingFile- the file to use as backing storeclient- the client we use to connect with.url- URL to the remote data- Throws:
IOException- if the URL was badly formed
-
FileBackedHTTPResource
public FileBackedHTTPResource(@Nonnull @ParameterName(name="backingFile") String backingFile, @Nonnull @ParameterName(name="client") org.apache.http.client.HttpClient client, @Nonnull @ParameterName(name="url") URL url) throws IOException
Constructor.- Parameters:
backingFile- the file to use as backing storeclient- the client we use to connect with.url- URL to the remote data- Throws:
IOException- if the URL was badly formed
-
-
Method Detail
-
saveAndClone
protected InputStream saveAndClone(InputStream input) throws IOException
saveAndClone. Read the contents into memory and then write out to the backing file. Finally- Parameters:
input- the input stream- Returns:
- the cloned stream.
- Throws:
IOException- if an error happens. If the backing file might have been corrupted we delete it.
-
getInputStream
@Nonnull public InputStream getInputStream() throws IOException
- Specified by:
getInputStreamin interfaceInputStreamSource- Specified by:
getInputStreamin interfaceResource- Overrides:
getInputStreamin classHTTPResource- Throws:
IOException
-
exists
public boolean exists()
-
contentLength
public long contentLength() throws IOException- Specified by:
contentLengthin interfaceResource- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classHTTPResource- Throws:
IOException
-
lastModified
public long lastModified() throws IOException- Specified by:
lastModifiedin interfaceResource- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classHTTPResource- Throws:
IOException
-
createRelative
public HTTPResource createRelative(String relativePath) throws IOException
Based onUrlResource.- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classHTTPResource- Throws:
IOException
-
getDescription
public String getDescription()
- Specified by:
getDescriptionin interfaceResource- Specified by:
getDescriptionin interfaceResource- Overrides:
getDescriptionin classHTTPResource
-
-