public class FileBackedHTTPMetadataResolver extends HTTPMetadataResolver
If the backup file does not already exist, it will be created by saving the byte[] retrieved in the HTTP fetch.
If isInitializeFromBackupFile()
is true, then initialization will attempt to load metadata first
from the backup file on disk, if it exists. If successful then the next refresh after initialization, which
will attempt the full HTTP fetch, will be scheduled for the interval indicated by
getBackupFileInitNextRefreshDelay()
. This can help prevent large metadata batches from slowing down
the synchronous resolver start up process, deferring the more expensive HTTP fetch operation to the asynchronous
background refresh thread.
AbstractBatchMetadataResolver.BatchEntityBackingStore
AbstractMetadataResolver.EntityBackingStore
Modifier and Type | Field and Description |
---|---|
private long |
backupFileInitNextRefreshDelay
Duration in milliseconds after which to schedule next refresh, when initialized from backup file.
|
private boolean |
initializedFromBackupFile
Flag indicating whether metadata load during init was from backup file.
|
private boolean |
initializeFromBackupFile
Flag indicating whether initialization should first attempt to load metadata from backup file.
|
private boolean |
initializing
Flag used to track state of whether currently initializing or not.
|
private org.slf4j.Logger |
log
Class logger.
|
private File |
metadataBackupFile
File containing the backup of the metadata.
|
Constructor and Description |
---|
FileBackedHTTPMetadataResolver(org.apache.http.client.HttpClient client,
String metadataURL,
String backupFilePath)
Constructor.
|
FileBackedHTTPMetadataResolver(Timer backgroundTaskTimer,
org.apache.http.client.HttpClient client,
String metadataURL,
String backupFilePath)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected long |
computeNextRefreshDelay(org.joda.time.DateTime expectedExpiration)
Computes the delay until the next refresh time based on the current metadata's expiration time and the refresh
interval floor.
|
protected void |
doDestroy() |
protected byte[] |
fetchMetadata()
Gets the metadata document from the remote server.
|
long |
getBackupFileInitNextRefreshDelay()
Get the duration in milliseconds after which to schedule next refresh, when initialized from backup file.
|
protected void |
initMetadataResolver()
Subclasses should override this method to perform any initialization logic necessary.
|
boolean |
isInitializedFromBackupFile()
Get the flag indicating whether metadata load during initialization was from backup file.
|
boolean |
isInitializeFromBackupFile()
Get the flag indicating whether initialization should first attempt to load metadata from backup file,
if it exists.
|
protected void |
postProcessMetadata(byte[] metadataBytes,
Document metadataDom,
org.opensaml.core.xml.XMLObject originalMetadata,
org.opensaml.core.xml.XMLObject filteredMetadata)
Post-processing hook called after new metadata has been unmarshalled, filtered, and the DOM released (from the
XMLObject ) but before the metadata is saved off. |
protected void |
setBackupFile(String backupFilePath)
Sets the file used to backup metadata.
|
void |
setBackupFileInitNextRefreshDelay(long delay)
Set the duration in milliseconds after which to schedule next refresh, when initialized from backup file.
|
void |
setInitializeFromBackupFile(boolean flag)
Set the flag indicating whether initialization should first attempt to load metadata from backup file,
if it exists.
|
protected void |
validateBackupFile(File backupFile)
Validate the basic properties of the specified metadata backup file, for example that it
exists and/or can be created; that it is not a directory; and that it is readable and writable.
|
buildHttpClientContext, buildHttpClientContext, buildHttpGet, checkTLSCredentialTrusted, getHttpClientSecurityParameters, getMetadataBytesFromResponse, getMetadataIdentifier, getMetadataURI, processConditionalRetrievalHeaders, setBasicCredentials, setBasicCredentialsWithScope, setHttpClientSecurityParameters, setTLSTrustEngine
getExpirationTime, getLastRefresh, getLastUpdate, getMaxRefreshDelay, getMinRefreshDelay, getNextRefresh, getRefreshDelayFactor, inputstreamToByteArray, processCachedMetadata, processNewMetadata, processNonExpiredMetadata, processPreExpiredMetadata, refresh, setCacheSourceMetadata, setMaxRefreshDelay, setMinRefreshDelay, setRefreshDelayFactor, unmarshallMetadata
createNewBackingStore, getBackingStore, getCachedFilteredMetadata, getCachedOriginalMetadata, getIndexes, indexEntityDescriptor, isCacheSourceMetadata, isResolveViaPredicatesOnly, iterator, lookupByIndexes, preProcessNewMetadata, resolve, setIndexes, setResolveViaPredicatesOnly
doInitialize, filterMetadata, getCriterionPredicateRegistry, getLogPrefix, getMetadataFilter, getParserPool, getUnmarshallerFactory, isFailFastInitialization, isRequireValidMetadata, isSatisfyAnyPredicates, isUseDefaultPredicateRegistry, isValid, lookupEntityID, lookupIndexedEntityID, predicateFilterCandidates, preProcessEntitiesDescriptor, preProcessEntityDescriptor, releaseMetadataDOM, removeByEntityID, resolveSingle, setBackingStore, setCriterionPredicateRegistry, setFailFastInitialization, setMetadataFilter, setParserPool, setRequireValidMetadata, setSatisfyAnyPredicates, setUseDefaultPredicateRegistry, unmarshallMetadata
setId
getId
destroy, initialize, isDestroyed, isInitialized
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMetadataFilter, isRequireValidMetadata, setMetadataFilter, setRequireValidMetadata
resolve, resolveSingle
getId
forEach, spliterator
@Nonnull private final org.slf4j.Logger log
@Nullable private File metadataBackupFile
private boolean initializing
private boolean initializeFromBackupFile
private boolean initializedFromBackupFile
@Duration @Positive private long backupFileInitNextRefreshDelay
public FileBackedHTTPMetadataResolver(org.apache.http.client.HttpClient client, String metadataURL, String backupFilePath) throws net.shibboleth.utilities.java.support.resolver.ResolverException
client
- HTTP client used to fetch remote metadatametadataURL
- the URL to fetch the metadatabackupFilePath
- the file that will keep a backup copy of the metadata,net.shibboleth.utilities.java.support.resolver.ResolverException
- thrown if the URL is not a valid URL, the metadata can not be retrieved from
the URLpublic FileBackedHTTPMetadataResolver(Timer backgroundTaskTimer, org.apache.http.client.HttpClient client, String metadataURL, String backupFilePath) throws net.shibboleth.utilities.java.support.resolver.ResolverException
client
- HTTP client used to fetch remote metadatabackgroundTaskTimer
- timer used to schedule background metadata refresh tasksmetadataURL
- the URL to fetch the metadatabackupFilePath
- the file that will keep a backup copy of the metadata,net.shibboleth.utilities.java.support.resolver.ResolverException
- thrown if the URL is not a valid URL, the metadata can not be retrieved from
the URLpublic boolean isInitializedFromBackupFile()
public boolean isInitializeFromBackupFile()
Defaults to: true.
public void setInitializeFromBackupFile(boolean flag)
Defaults to: true.
flag
- true if should initialize from backup file, false otherwisepublic long getBackupFileInitNextRefreshDelay()
Defaults to 5000ms.
public void setBackupFileInitNextRefreshDelay(long delay)
Defaults to 5000ms.
delay
- the next refresh delay, in millisecondsprotected void doDestroy()
doDestroy
in class HTTPMetadataResolver
protected void initMetadataResolver() throws net.shibboleth.utilities.java.support.component.ComponentInitializationException
initMetadataResolver
in class AbstractReloadingMetadataResolver
net.shibboleth.utilities.java.support.component.ComponentInitializationException
- thrown if there is a problem initializing the providerprotected void setBackupFile(String backupFilePath) throws net.shibboleth.utilities.java.support.resolver.ResolverException
backupFilePath
- path to the backup filenet.shibboleth.utilities.java.support.resolver.ResolverException
- thrown if the backup file is not read/writable or creatableprotected void validateBackupFile(File backupFile) throws net.shibboleth.utilities.java.support.resolver.ResolverException
backupFile
- the file to evaluatenet.shibboleth.utilities.java.support.resolver.ResolverException
- if file does not pass basic properties required of a metadata backup fileprotected byte[] fetchMetadata() throws net.shibboleth.utilities.java.support.resolver.ResolverException
fetchMetadata
in class HTTPMetadataResolver
net.shibboleth.utilities.java.support.resolver.ResolverException
- thrown if there is a problem retrieving the metadata from the remote serverprotected long computeNextRefreshDelay(org.joda.time.DateTime expectedExpiration)
computeNextRefreshDelay
in class AbstractReloadingMetadataResolver
expectedExpiration
- the time when the metadata is expected to expire and need refreshingprotected void postProcessMetadata(byte[] metadataBytes, Document metadataDom, org.opensaml.core.xml.XMLObject originalMetadata, org.opensaml.core.xml.XMLObject filteredMetadata) throws net.shibboleth.utilities.java.support.resolver.ResolverException
XMLObject
) but before the metadata is saved off. Any exception thrown by this hook will cause the
retrieved metadata to be discarded.
The default implementation of this method is a no-oppostProcessMetadata
in class AbstractReloadingMetadataResolver
metadataBytes
- original raw metadata bytes retrieved via AbstractReloadingMetadataResolver.fetchMetadata()
metadataDom
- original metadata after it has been parsed in to a DOM documentoriginalMetadata
- original metadata prior to being filtered, with its DOM releasedfilteredMetadata
- metadata after it has been run through all registered filters and its DOM releasednet.shibboleth.utilities.java.support.resolver.ResolverException
- thrown if there is a problem with the provided dataCopyright © 1999–2020 Shibboleth Consortium. All rights reserved.