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

java.lang.Object
  extended by net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent
      extended by net.shibboleth.utilities.java.support.resource.AbstractResource
          extended by net.shibboleth.utilities.java.support.httpclient.HttpResource
All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, ValidatableComponent, Resource

@NotThreadSafe
public class HttpResource
extends AbstractResource

A resource that fetches data from a remote source via HTTP.


Nested Class Summary
static interface HttpResource.HttpGetCustomizationStrategy
          Strategy that can be used to customize an HttpGet object before it is used.
static interface HttpResource.HttpResponseCustomizationStrategy
          Strategy used to perform any HttpResponse processing prior to returning the InputStream for its content.
 
Field Summary
static String ETAG_PROP
          Property name under which the ETag data is stored.
private  HttpClient httpClient
          Client used to make HTTP requests.
private  HttpResource.HttpGetCustomizationStrategy httpGetCustomizationStrategy
          Strategy used to customize an HttpGet before using it.
private  HttpResource.HttpResponseCustomizationStrategy httpResponseCustomizationStrategy
          Strategy used to customize an HttpResponse before get its content.
static String LAST_MODIFIED_PROP
          Property name under which the Last-Modified data is stored.
private  Logger log
          Class logger.
 
Constructor Summary
HttpResource(HttpClient client, String url)
          Constructor.
 
Method Summary
private  HttpGet buildGetMethod()
          Gets the, potentially customized, HttpGet method.
protected  void doDestroy()
          Performs component specific destruction logic.
protected  boolean doExists()
          Checks whether the resource exists.
protected  InputStream doGetInputStream()
          Gets the input stream to the resource's data.
protected  long doGetLastModifiedTime()
          Gets the time, in milliseconds since the epoch, when the resource was last modified.
 HttpResource.HttpGetCustomizationStrategy getHttpGetCustomizationStrategy()
          Gets the strategy used customize the HttpGet used to fetch the resource.
 HttpResource.HttpResponseCustomizationStrategy getHttpResponseCustomizationStrategy()
          Gets the strategy used to customize the HttpResponse before its content is returned.
private  org.apache.http.HttpResponse getResourceHeaders()
          Attempts to fetch only the headers for a given resource.
 void setHttpGetCustomizationStrategy(HttpResource.HttpGetCustomizationStrategy strategy)
          Sets the strategy used customize the HttpGet used to fetch the resource.
 void setHttpResponseCustomizationStrategy(HttpResource.HttpResponseCustomizationStrategy strategy)
          Sets the strategy used to customize the HttpResponse before its content is returned.
 
Methods inherited from class net.shibboleth.utilities.java.support.resource.AbstractResource
doValidate, equals, exists, getInputStream, getLastModifiedTime, getLocation, hashCode, setLocation, toString, validate
 
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent
destroy, doInitialize, initialize, isDestroyed, isInitialized
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.DestructableComponent
destroy, isDestroyed
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent
initialize, isInitialized
 

Field Detail

ETAG_PROP

public static final String ETAG_PROP
Property name under which the ETag data is stored.

See Also:
Constant Field Values

LAST_MODIFIED_PROP

public static final String LAST_MODIFIED_PROP
Property name under which the Last-Modified data is stored.

See Also:
Constant Field Values

log

private final Logger log
Class logger.


httpClient

private HttpClient httpClient
Client used to make HTTP requests.


httpGetCustomizationStrategy

private HttpResource.HttpGetCustomizationStrategy httpGetCustomizationStrategy
Strategy used to customize an HttpGet before using it.


httpResponseCustomizationStrategy

private HttpResource.HttpResponseCustomizationStrategy httpResponseCustomizationStrategy
Strategy used to customize an HttpResponse before get its content.

Constructor Detail

HttpResource

public HttpResource(@Nonnull
                    HttpClient client,
                    @Nonnull@NotEmpty
                    String url)
Constructor.

Parameters:
client - client used to fetch the remote resource data
url - URL of the remote resource data
Method Detail

getHttpGetCustomizationStrategy

@Nullable
public HttpResource.HttpGetCustomizationStrategy getHttpGetCustomizationStrategy()
Gets the strategy used customize the HttpGet used to fetch the resource.

Returns:
strategy used customize the HttpGet used to fetch the resource

setHttpGetCustomizationStrategy

public void setHttpGetCustomizationStrategy(@Nullable
                                            HttpResource.HttpGetCustomizationStrategy strategy)
Sets the strategy used customize the HttpGet used to fetch the resource.

Parameters:
strategy - strategy used customize the HttpGet used to fetch the resource

getHttpResponseCustomizationStrategy

@Nullable
public HttpResource.HttpResponseCustomizationStrategy getHttpResponseCustomizationStrategy()
Gets the strategy used to customize the HttpResponse before its content is returned.

Returns:
strategy used to customize the HttpResponse before its content is returned

setHttpResponseCustomizationStrategy

public void setHttpResponseCustomizationStrategy(@Nullable
                                                 HttpResource.HttpResponseCustomizationStrategy strategy)
Sets the strategy used to customize the HttpResponse before its content is returned.

Parameters:
strategy - strategy used to customize the HttpResponse before its content is returned

doGetLastModifiedTime

protected long doGetLastModifiedTime()
                              throws ResourceException
Gets the time, in milliseconds since the epoch, when the resource was last modified.

Specified by:
doGetLastModifiedTime in class AbstractResource
Returns:
time, in milliseconds since the epoch, when the resource was last modified
Throws:
ResourceException - thrown if the last modified time can not be determined

doExists

protected boolean doExists()
                    throws ResourceException
Checks whether the resource exists.

Specified by:
doExists in class AbstractResource
Returns:
true if the resource exists, false if not
Throws:
ResourceException - thrown if there is a problem determining if the resource exists

doGetInputStream

@Nonnull
protected InputStream doGetInputStream()
                                throws ResourceException
Gets the input stream to the resource's data.

Specified by:
doGetInputStream in class AbstractResource
Returns:
input stream to the resource's data
Throws:
ResourceException - thrown if an input stream can not be created for the resource

doDestroy

protected void doDestroy()
Performs component specific destruction logic. Default implementation of this method is a no-op.

Overrides:
doDestroy in class AbstractDestructableInitializableComponent

getResourceHeaders

private org.apache.http.HttpResponse getResourceHeaders()
                                                 throws ResourceException
Attempts to fetch only the headers for a given resource. If HEAD requests are unsupported than a more costly GET request is performed.

Returns:
the response from the request
Throws:
ResourceException - thrown if there is a problem contacting the resource

buildGetMethod

private HttpGet buildGetMethod()
Gets the, potentially customized, HttpGet method.

Returns:
the HttpGet method


Copyright © 1999-2012. All Rights Reserved.