Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

FileBackedHTTPResource provides file backup for when the web server is unavailable, including across restarts. Note that this use case is orthogonal to the use of a file-backed HttpClient cache, which provides a local copy of valid cached data even when the web server can be contacted.

...

Examples

The first example is the simplest case, with a standard client and some timeout settings.

...

The second example demonstrates a resource which will be supplied from an on disk cache (suitable for multiple or large files) for as long as the file on the webserver does not change.  If the webserver becomes unavailable the last used contents of the file will be returned (even if that was in a previous IdP lifetime)backup if the source becomes unavailable.

Code Block
languagexml
<bean id="MyHTTPClient" parent="shibboleth.FileCachingHttpClientFactoryHttpClientFactory"
	p:connectionTimeout="PT30S"
	p:connectionRequestTimeout="PT30S"
	p:socketTimeout="PT30S" />

	p:cacheDirectory="%{idp.home}/configcache<bean id="fileResource" class="net.shibboleth.ext.spring.resource.FileBackedHTTPResource"
	c:client-ref="MyHTTPClient"
	c:url="http://example.org/path/to/file.xml" 
	c:backingFile="/var/shibboleth/cache/resourcecache/file.xml"/>

Finally, a more complex example illustrates how to integrate the security features documented in the HttpClientConfiguration topic with an HTTPResource. The example references a security object called "CustomHttpSecurity", which is not shown, but examples of creating an HttpClientSecurityParameters object are in that topic. The additional wiring is to inject the security object into the client at runtime from the resource object.

Code Block
languagexml
<bean id="MyHTTPClient" parent="shibboleth.HttpClientFactory"
	p:connectionTimeout="PT30S"
	p:connectionRequestTimeout="PT30S"
	p:socketTimeout="PT30S" />

<bean id="fileResource" class="net.shibboleth.ext.spring.resource.FileBackedHTTPResource"
	c:client-ref="MyHTTPClient"
	c:url="http://example.org/path/to/file.xml" 
	c:backingFile="/var/shibboleth/cachescache/resourcecache/file.xml">

	<property name="httpClientContextHandler">
		<bean class="org.opensaml.security.httpclient.HttpClientSecurityContextHandler"
			p:httpClientSecurityParameters-ref="CustomHttpSecurity"/>
	</property>

</bean>