public class HTTPResource extends net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent implements Resource, BeanNameAware, InitializingBean, net.shibboleth.utilities.java.support.resource.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 BasicCredentialsProvider |
credentialsProvider
HttpClient credentials provider.
|
private HttpClient |
httpClient
HTTP Client used to pull the resource.
|
private 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. |
net.shibboleth.utilities.java.support.resource.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) |
doInitialize, getId, setIdprivate final Logger log
@Nonnull private final HttpClient httpClient
private BasicCredentialsProvider credentialsProvider
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 formedprotected 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 net.shibboleth.utilities.java.support.resource.ResourcegetInputStream in interface InputStreamSourceIOExceptionpublic void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanExceptionpublic void setBeanName(String name)
setBeanName in interface BeanNameAwarepublic boolean exists()
exists in interface net.shibboleth.utilities.java.support.resource.Resourcepublic boolean isReadable()
isReadable in interface net.shibboleth.utilities.java.support.resource.Resourcepublic boolean isOpen()
isOpen in interface net.shibboleth.utilities.java.support.resource.Resourcepublic URL getURL() throws IOException
getURL in interface net.shibboleth.utilities.java.support.resource.ResourceIOExceptionpublic URI getURI() throws IOException
getURI in interface net.shibboleth.utilities.java.support.resource.ResourceIOExceptionpublic File getFile() throws IOException
UrlResource.getFile in interface net.shibboleth.utilities.java.support.resource.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 net.shibboleth.utilities.java.support.resource.ResourceIOExceptionpublic long lastModified()
throws IOException
lastModified in interface net.shibboleth.utilities.java.support.resource.ResourceIOExceptionpublic HTTPResource createRelative(String relativePath) throws IOException
UrlResource.IOExceptionpublic net.shibboleth.utilities.java.support.resource.Resource createRelativeResource(String relativePath) throws IOException
createRelativeResource in interface net.shibboleth.utilities.java.support.resource.ResourceIOExceptionpublic String getFilename()
getFilename in interface net.shibboleth.utilities.java.support.resource.ResourceURL.getFile(),
File.getName()public String getDescription()
getDescription in interface net.shibboleth.utilities.java.support.resource.Resourceprotected void closeResponse(@Nullable org.apache.http.HttpResponse response)
response - the HTTP responseCopyright © 1999–2016 Shibboleth Consortium. All rights reserved.