public class HTTPResource extends AbstractIdentifiedInitializableComponent implements org.springframework.core.io.Resource, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, Resource
HttpClient. Code
based on OpenSAML HTTPMetadataResolver and UrlResource.| Modifier and Type | Class and Description |
|---|---|
private static class |
HTTPResource.ConnectionClosingInputStream
A wrapper around the entity content
InputStream represented by an HttpResponse
that closes the stream and the HttpResponse when HTTPResource.ConnectionClosingInputStream.close() is invoked. |
| Modifier and Type | Field and Description |
|---|---|
private HttpClient |
httpClient
HTTP Client used to pull the resource.
|
private HttpClientContextHandler |
httpClientContextHandler
Optional handler to pre- and post-process context.
|
private org.slf4j.Logger |
log
Class logger.
|
private URL |
resourceURL
URL to the Resource.
|
| Constructor and Description |
|---|
HTTPResource(HttpClient client,
String url)
Constructor.
|
HTTPResource(HttpClient client,
URL url)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected HttpCacheContext |
buildHttpClientContext()
Build the
HttpCacheContext instance which will be used to invoke the HttpClient request. |
protected void |
closeResponse(org.apache.http.HttpResponse response)
Close the HTTP response.
|
long |
contentLength() |
HTTPResource |
createRelative(String relativePath)
Based on
UrlResource. |
Resource |
createRelativeResource(String relativePath) |
boolean |
exists() |
String |
getDescription() |
File |
getFile()
Based on
UrlResource. |
String |
getFilename()
This implementation returns the name of the file that this URL refers to.
|
InputStream |
getInputStream() |
protected org.apache.http.HttpResponse |
getResourceHeaders()
Attempts to fetch only the headers for a given resource.
|
protected String |
getResponseHeader(String what)
Send a Head to the client and interrogate the response for a particular response header.
|
URI |
getURI() |
URL |
getURL() |
boolean |
isOpen() |
boolean |
isReadable() |
long |
lastModified() |
protected void |
reportCachingStatus(HttpCacheContext context)
Print out to the log whether we hit the apache cache or not.
|
void |
setBeanName(String name) |
void |
setHttpClientContextHandler(HttpClientContextHandler handler)
Set a handler to manipulate the
HttpClientContext. |
doInitialize, getId, setIddestroy, doDestroy, initialize, isDestroyed, isInitialized@Nonnull private final org.slf4j.Logger log
@Nonnull private final HttpClient httpClient
@Nullable private HttpClientContextHandler httpClientContextHandler
public HTTPResource(@Nonnull @ParameterName(name="client") HttpClient client, @Nonnull @NotEmpty @ParameterName(name="url") String url) throws IOException
client - the client we use to connect with.url - URL to the remote dataIOException - if the URL was badly formedpublic HTTPResource(@Nonnull @ParameterName(name="") HttpClient client, @Nonnull @ParameterName(name="url") URL url) throws IOException
client - the client we use to connect with.url - URL to the remote dataIOException - if the URL was badly formedpublic void setHttpClientContextHandler(@Nonnull HttpClientContextHandler handler)
HttpClientContext.handler - the handler to installprotected HttpCacheContext buildHttpClientContext()
HttpCacheContext instance which will be used to invoke the HttpClient request.HttpCacheContextprotected void reportCachingStatus(HttpCacheContext context)
context - the context of the requestpublic InputStream getInputStream() throws IOException
getInputStream in interface ResourcegetInputStream in interface org.springframework.core.io.InputStreamSourceIOExceptionpublic void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic void setBeanName(String name)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic boolean isReadable()
isReadable in interface Resourcepublic URL getURL() throws IOException
getURL in interface ResourceIOExceptionpublic URI getURI() throws IOException
getURI in interface ResourceIOExceptionpublic File getFile() throws IOException
UrlResource.getFile in interface ResourceIOExceptionprotected org.apache.http.HttpResponse getResourceHeaders()
throws IOException
IOException - thrown if there is a problem contacting the resource@Nullable protected String getResponseHeader(String what) throws IOException
what - the repsonse header to look atIOException - from lower levels.public long contentLength()
throws IOException
contentLength in interface ResourceIOExceptionpublic long lastModified()
throws IOException
lastModified in interface ResourceIOExceptionpublic HTTPResource createRelative(String relativePath) throws IOException
UrlResource.IOExceptionpublic Resource createRelativeResource(String relativePath) throws IOException
createRelativeResource in interface ResourceIOExceptionpublic String getFilename()
getFilename in interface ResourceURL.getFile(),
File.getName()public String getDescription()
getDescription in interface Resourceprotected void closeResponse(@Nullable org.apache.http.HttpResponse response)
response - the HTTP responseCopyright © 1999–2019 Shibboleth Consortium. All rights reserved.