Class FileBackedHTTPResource
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.spring.httpclient.resource.HTTPResource
net.shibboleth.shared.spring.httpclient.resource.FileBackedHTTPResource
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiedComponent,InitializableComponent,Resource,Aware,BeanNameAware,InitializingBean,InputStreamSource,Resource
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
FieldsModifier and TypeFieldDescriptionprivate final ResourceBacking resource file.private final org.slf4j.LoggerLogger. -
Constructor Summary
ConstructorsConstructorDescriptionFileBackedHTTPResource(String backingFile, org.apache.hc.client5.http.classic.HttpClient client, String url) Constructor.FileBackedHTTPResource(String backingFile, org.apache.hc.client5.http.classic.HttpClient client, URL url) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionlongDetermine the content length for this resource.createRelative(String relativePath) Based onUrlResource.booleanexists()Return whether this resource actually exists in physical form.Return a description for this resource, to be used for error output when working with the resource.Return anInputStream.longDetermine the last-modified timestamp for this resource.protected InputStreamsaveAndClone(InputStream input) saveAndClone.Methods inherited from class net.shibboleth.shared.spring.httpclient.resource.HTTPResource
afterPropertiesSet, buildHttpClientContext, closeResponse, createRelative, createRelativeResource, getFile, getFilename, getResourceHeaders, getResponseHeader, getURI, getURL, isFile, isOpen, isReadable, reportCachingStatus, setBeanName, setHttpClientContextHandlerMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
doInitialize, ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, setIdMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.io.Resource
getContentAsByteArray, getContentAsString, readableChannel
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logLogger. -
backingResource
Backing resource file.
-
-
Constructor Details
-
FileBackedHTTPResource
public FileBackedHTTPResource(@Nonnull @ParameterName(name="backingFile") String backingFile, @Nonnull @ParameterName(name="client") org.apache.hc.client5.http.classic.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.hc.client5.http.classic.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 Details
-
saveAndClone
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
Return anInputStream.It is expected that each call creates a fresh stream.
This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each
getInputStream()call returns a fresh stream.- Specified by:
getInputStreamin interfaceInputStreamSource- Specified by:
getInputStreamin interfaceResource- Overrides:
getInputStreamin classHTTPResource- Returns:
- the input stream for the underlying resource (must not be
null) - Throws:
IOException- if the stream could not be opened
-
exists
public boolean exists()Return whether this resource actually exists in physical form.This method performs a definitive existence check, whereas the existence of a
Resourcehandle only guarantees a valid descriptor handle. -
contentLength
Determine the content length for this resource.- Specified by:
contentLengthin interfaceResource- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classHTTPResource- Returns:
- the content length for this resource.
- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
-
lastModified
Determine the last-modified timestamp for this resource.- Specified by:
lastModifiedin interfaceResource- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classHTTPResource- Returns:
- the last-modified timestamp for this resource.
- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
-
createRelative
Based onUrlResource.- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classHTTPResource- Throws:
IOException
-
getDescription
Return a description for this resource, to be used for error output when working with the resource.Implementations are also encouraged to return this value from their
toStringmethod.- Specified by:
getDescriptionin interfaceResource- Specified by:
getDescriptionin interfaceResource- Overrides:
getDescriptionin classHTTPResource- Returns:
- a description for this resource.
- See Also:
-