net.shibboleth.utilities.java.support.httpclient
Class FileCachingHttpClientBuilder

java.lang.Object
  extended by net.shibboleth.utilities.java.support.httpclient.FileCachingHttpClientBuilder

public class FileCachingHttpClientBuilder
extends Object

An HttpClient builder that supports RFC 2616 caching.

Cached content is written to disk. Special care should be taken so that multiple clients do not share a single cache directory unintentionally. This could result senstive data being available in ways it should not be.


Field Summary
private  File cacheDir
          Directory in which cached content will be stored.
private  HttpClientBuilder clientBuilder
          Builder of clients used to fetch data from remote servers.
private  int maxCacheEntries
          The maximum number of cached responses.
private  int maxCacheEntrySize
          The maximum response body size, in bytes, that will be eligible for caching.
 
Constructor Summary
FileCachingHttpClientBuilder(HttpClientBuilder builder)
          Constructor.
 
Method Summary
 HttpClient buildClient()
          Builds an HTTP client that performs RFC2616 caching.
 File getCacheDirectory()
          Gets the directory in which cached content will be stored.
 int getMaxCacheEntries()
          Gets the maximum number of cached responses.
 int getMaxCacheEntrySize()
          Gets the maximum response body size, in bytes, that will be eligible for caching.
 void setCacheDirectory(File directory)
          Sets the directory in which cached content will be stored.
 void setCacheDirectory(String directoryPath)
          Sets the directory in which cached content will be stored.
 void setMaxCacheEntries(int maxEntries)
          Sets the maximum number of cached responses.
 void setMaxCacheEntrySize(int size)
          Sets the maximum response body size, in bytes, that will be eligible for caching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clientBuilder

private final HttpClientBuilder clientBuilder
Builder of clients used to fetch data from remote servers.


cacheDir

private File cacheDir
Directory in which cached content will be stored. Default: System.getProperty("java.io.tmpdir") + File.separator + "wwwcache"


maxCacheEntries

private int maxCacheEntries
The maximum number of cached responses. Default: 100


maxCacheEntrySize

private int maxCacheEntrySize
The maximum response body size, in bytes, that will be eligible for caching. Default: 10485760 (10 megabytes)

Constructor Detail

FileCachingHttpClientBuilder

public FileCachingHttpClientBuilder(@Nonnull
                                    HttpClientBuilder builder)
Constructor.

Parameters:
builder - builder of clients used to fetch data from remote servers
Method Detail

getCacheDirectory

public File getCacheDirectory()
Gets the directory in which cached content will be stored.

Returns:
directory in which cached content will be stored

setCacheDirectory

public void setCacheDirectory(@Nonnull@NotEmpty
                              String directoryPath)
Sets the directory in which cached content will be stored.

Parameters:
directoryPath - filesystem path to the directory

setCacheDirectory

public void setCacheDirectory(@Nonnull
                              File directory)
Sets the directory in which cached content will be stored.

Parameters:
directory - the directory

getMaxCacheEntries

public int getMaxCacheEntries()
Gets the maximum number of cached responses.

Returns:
maximum number of cached responses

setMaxCacheEntries

public void setMaxCacheEntries(int maxEntries)
Sets the maximum number of cached responses.

Parameters:
maxEntries - maximum number of cached responses, must be greater than zero

getMaxCacheEntrySize

public int getMaxCacheEntrySize()
Gets the maximum response body size, in bytes, that will be eligible for caching.

Returns:
maximum response body size that will be eligible for caching

setMaxCacheEntrySize

public void setMaxCacheEntrySize(int size)
Sets the maximum response body size, in bytes, that will be eligible for caching.

Parameters:
size - maximum response body size that will be eligible for caching, must be greater than zero

buildClient

public HttpClient buildClient()
                       throws IOException
Builds an HTTP client that performs RFC2616 caching.

Returns:
the constructed HTTP client
Throws:
IOException - if the cache directory does not exist and can not be created or if it can not be read from or written to


Copyright © 1999-2012. All Rights Reserved.