org.openid4java.util
Class HttpCache

java.lang.Object
  extended by org.openid4java.util.AbstractHttpFetcher
      extended by org.openid4java.util.HttpCache
All Implemented Interfaces:
HttpFetcher

public class HttpCache
extends AbstractHttpFetcher

Wrapper cache around HttpClient providing caching for HTTP requests. Intended to be used to optimize the number of HTTP requests performed during OpenID discovery.

Author:
Marius Scurtescu, Johnny Bufu

Nested Class Summary
private static class HttpCache.DefaultHttpResponse
           
private static class HttpCache.ResponseBody
           
 
Field Summary
private  org.apache.http.client.HttpClient _client
          HttpClient used to place the HTTP requests.
private  java.util.Map _getCache
          Cache for GET requests.
private  java.util.Map _headCache
          Cache for HEAD requests.
private static org.apache.commons.logging.Log _log
           
private static boolean DEBUG
           
 
Constructor Summary
HttpCache()
           
HttpCache(javax.net.ssl.SSLContext sslContext)
           
HttpCache(javax.net.ssl.SSLContext sslContext, org.apache.http.conn.ssl.X509HostnameVerifier hostnameVerifier)
          Constructs a new HttpCache object, that will be initialized with the default set of HttpRequestOptions.
 
Method Summary
 HttpResponse get(java.lang.String url, HttpRequestOptions requestOptions)
          GETs a HTTP URL.
private  HttpCache.ResponseBody getResponseBody(org.apache.http.HttpEntity response, int maxBodySize)
          Returns content of an HTTP response entitity, but no more than maxBytes.
 HttpResponse head(java.lang.String url, HttpRequestOptions requestOptions)
           
private  boolean match(HttpCache.DefaultHttpResponse resp, HttpRequestOptions requestOptions)
           
 HttpResponse post(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> parameters, HttpRequestOptions requestOptions)
           
private  void removeGet(java.lang.String url)
          Removes a cached GET response.
private  java.util.List<org.apache.http.NameValuePair> toList(java.util.Map<java.lang.String,java.lang.String> parameters)
           
 
Methods inherited from class org.openid4java.util.AbstractHttpFetcher
get, getDefaultRequestOptions, getRequestOptions, head, post, setDefaultRequestOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

private static org.apache.commons.logging.Log _log

DEBUG

private static final boolean DEBUG

_client

private org.apache.http.client.HttpClient _client
HttpClient used to place the HTTP requests.


_getCache

private java.util.Map _getCache
Cache for GET requests. Map of URL -> HttpResponse.


_headCache

private java.util.Map _headCache
Cache for HEAD requests. Map of URL -> HttpResponse.

Constructor Detail

HttpCache

public HttpCache()

HttpCache

public HttpCache(javax.net.ssl.SSLContext sslContext)

HttpCache

public HttpCache(javax.net.ssl.SSLContext sslContext,
                 org.apache.http.conn.ssl.X509HostnameVerifier hostnameVerifier)
Constructs a new HttpCache object, that will be initialized with the default set of HttpRequestOptions.

See Also:
HttpRequestOptions
Method Detail

removeGet

private void removeGet(java.lang.String url)
Removes a cached GET response.

Parameters:
url - The URL for which to remove the cached response.

get

public HttpResponse get(java.lang.String url,
                        HttpRequestOptions requestOptions)
                 throws java.io.IOException
Description copied from interface: HttpFetcher
GETs a HTTP URL. A cached copy will be returned if one exists and the supplied options match it.

Specified by:
get in interface HttpFetcher
Specified by:
get in class AbstractHttpFetcher
Parameters:
url - The HTTP URL to GET.
Returns:
A HttpResponse object containing the fetched data.
Throws:
java.io.IOException
See Also:
HttpRequestOptions, HttpResponse

toList

private java.util.List<org.apache.http.NameValuePair> toList(java.util.Map<java.lang.String,java.lang.String> parameters)

post

public HttpResponse post(java.lang.String url,
                         java.util.Map<java.lang.String,java.lang.String> parameters,
                         HttpRequestOptions requestOptions)
                  throws java.io.IOException
Specified by:
post in interface HttpFetcher
Specified by:
post in class AbstractHttpFetcher
Throws:
java.io.IOException

getResponseBody

private HttpCache.ResponseBody getResponseBody(org.apache.http.HttpEntity response,
                                               int maxBodySize)
                                        throws java.io.IOException
Returns content of an HTTP response entitity, but no more than maxBytes.

Throws:
java.io.IOException

match

private boolean match(HttpCache.DefaultHttpResponse resp,
                      HttpRequestOptions requestOptions)

head

public HttpResponse head(java.lang.String url,
                         HttpRequestOptions requestOptions)
                  throws java.io.IOException
Specified by:
head in interface HttpFetcher
Specified by:
head in class AbstractHttpFetcher
Throws:
java.io.IOException


Copyright 2006-2008 Sxip Identity Corporation