Class HTTPResource
java.lang.Object
net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
net.shibboleth.ext.spring.resource.HTTPResource
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiedComponent,InitializableComponent,Resource,Aware,BeanNameAware,InitializingBean,InputStreamSource,Resource
- Direct Known Subclasses:
FileBackedHTTPResource
public class HTTPResource
extends AbstractIdentifiedInitializableComponent
implements Resource, BeanNameAware, InitializingBean, Resource
Resource for looking up HTTP URLs. Allows injection and therefore configuration of an Apache
HttpClient. Code
based on OpenSAML HTTPMetadataResolver and UrlResource.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA wrapper around the entity contentInputStreamrepresented by anHttpResponsethat closes the stream and the HttpResponse whenHTTPResource.ConnectionClosingInputStream.close()is invoked. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.http.client.HttpClientHTTP Client used to pull the resource.private HttpClientContextHandlerOptional handler to pre- and post-process context.private final org.slf4j.LoggerClass logger.private final URLURL to the Resource. -
Constructor Summary
ConstructorsConstructorDescriptionHTTPResource(org.apache.http.client.HttpClient client, String url) Constructor.HTTPResource(org.apache.http.client.HttpClient client, URL url) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected org.apache.http.client.cache.HttpCacheContextBuild theHttpCacheContextinstance which will be used to invoke theHttpClientrequest.protected voidcloseResponse(org.apache.http.HttpResponse response) Close the HTTP response.longcreateRelative(String relativePath) Based onUrlResource.createRelativeResource(String relativePath) booleanexists()getFile()Based onUrlResource.This implementation returns the name of the file that this URL refers to.protected org.apache.http.HttpResponseAttempts to fetch only the headers for a given resource.protected StringgetResponseHeader(String what) Send a Head to the client and interrogate the response for a particular response header.getURI()getURL()booleanisOpen()booleanlongprotected voidreportCachingStatus(org.apache.http.client.cache.HttpCacheContext context) Print out to the log whether we hit the apache cache or not.voidsetBeanName(String name) voidSet a handler to manipulate theHttpClientContext.Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
doInitialize, getId, setIdMethods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.io.Resource
isFile, readableChannel
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
httpClient
@Nonnull private final org.apache.http.client.HttpClient httpClientHTTP Client used to pull the resource. -
resourceURL
URL to the Resource. -
httpClientContextHandler
Optional handler to pre- and post-process context.
-
-
Constructor Details
-
HTTPResource
public HTTPResource(@Nonnull @ParameterName(name="client") org.apache.http.client.HttpClient client, @Nonnull @NotEmpty @ParameterName(name="url") String url) throws IOException Constructor.- Parameters:
client- the client we use to connect with.url- URL to the remote data- Throws:
IOException- if the URL was badly formed
-
HTTPResource
public HTTPResource(@Nonnull @ParameterName(name="") org.apache.http.client.HttpClient client, @Nonnull @ParameterName(name="url") URL url) throws IOException Constructor.- Parameters:
client- the client we use to connect with.url- URL to the remote data- Throws:
IOException- if the URL was badly formed
-
-
Method Details
-
setHttpClientContextHandler
Set a handler to manipulate theHttpClientContext.- Parameters:
handler- the handler to install- Since:
- 5.4.0
-
buildHttpClientContext
@Nonnull protected org.apache.http.client.cache.HttpCacheContext buildHttpClientContext()Build theHttpCacheContextinstance which will be used to invoke theHttpClientrequest.- Returns:
- a new instance of
HttpCacheContext
-
reportCachingStatus
protected void reportCachingStatus(org.apache.http.client.cache.HttpCacheContext context) Print out to the log whether we hit the apache cache or not. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html- Parameters:
context- the context of the request
-
getInputStream
- Specified by:
getInputStreamin interfaceInputStreamSource- Specified by:
getInputStreamin interfaceResource- Throws:
IOException
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception
-
setBeanName
- Specified by:
setBeanNamein interfaceBeanNameAware
-
exists
public boolean exists() -
isReadable
public boolean isReadable()- Specified by:
isReadablein interfaceResource- Specified by:
isReadablein interfaceResource
-
isOpen
public boolean isOpen() -
getURL
- Specified by:
getURLin interfaceResource- Specified by:
getURLin interfaceResource- Throws:
IOException
-
getURI
- Specified by:
getURIin interfaceResource- Specified by:
getURIin interfaceResource- Throws:
IOException
-
getFile
Based onUrlResource.- Specified by:
getFilein interfaceResource- Specified by:
getFilein interfaceResource- Throws:
IOException
-
getResourceHeaders
Attempts to fetch only the headers for a given resource. If HEAD requests are unsupported then a more costly GET request is performed.- Returns:
- the response from the request
- Throws:
IOException- thrown if there is a problem contacting the resource
-
getResponseHeader
Send a Head to the client and interrogate the response for a particular response header.- Parameters:
what- the repsonse header to look at- Returns:
- the value of that response, or null if things failed
- Throws:
IOException- from lower levels.
-
contentLength
- Specified by:
contentLengthin interfaceResource- Specified by:
contentLengthin interfaceResource- Throws:
IOException
-
lastModified
- Specified by:
lastModifiedin interfaceResource- Specified by:
lastModifiedin interfaceResource- Throws:
IOException
-
createRelative
Based onUrlResource.- Specified by:
createRelativein interfaceResource- Throws:
IOException
-
createRelativeResource
- Specified by:
createRelativeResourcein interfaceResource- Throws:
IOException
-
getFilename
This implementation returns the name of the file that this URL refers to.- Specified by:
getFilenamein interfaceResource- Specified by:
getFilenamein interfaceResource- See Also:
-
getDescription
- Specified by:
getDescriptionin interfaceResource- Specified by:
getDescriptionin interfaceResource
-
closeResponse
protected void closeResponse(@Nullable org.apache.http.HttpResponse response) Close the HTTP response.- Parameters:
response- the HTTP response
-