Package net.sf.basedb.util.uri.http
Class HttpConnectionManager
java.lang.Object
net.sf.basedb.util.uri.http.HttpConnectionManager
- All Implemented Interfaces:
ConnectionManager
,ResumableConnectionManager
Connection manager implementation that support HTTP and HTTPS URI:s.
It supports Basic and Digest authentication schemes. When HTTPS
is used it provides support for validation of both server- and
client-side certificates.
- Since:
- 3.0
- Author:
- Nicklas
- Last modified
- $Date: 2017-10-13 13:40:38 +0200 (fr, 13 okt 2017) $
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
-
Field Summary
Modifier and TypeFieldDescriptionprivate UriMetadata
private final ConnectionParameters
private Filter<org.apache.http.HttpResponse>
private int
private final URI
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.http.impl.client.CloseableHttpClient
createCloseableHttpClient
(URI uri, ConnectionParameters parameters) Get a HttpClient object that has been configured to access the given URI.createMetadata
(URI uri, org.apache.http.HttpResponse response) Read metadata from the given http response and put the information in a UriMetadata object.Get an InputStream for reading the contents of the resource.getInputStream
(long offset) Get an InputStream for reading the contents of the resource.Get metadata about the resource.getURI()
Get the URI of the resource we are interested in.void
setResponseFilter
(Filter<org.apache.http.HttpResponse> filter) Set a filter that will inspect the response before an input stream is returned to the calling code.void
setTimeout
(int timeoutInSeconds) Set a timeout in seconds to allocate for the request to return (not including downloading of data).
-
Field Details
-
uri
-
parameters
-
metadata
-
responseFilter
-
timeout
private int timeout
-
-
Constructor Details
-
HttpConnectionManager
-
-
Method Details
-
getURI
Description copied from interface:ConnectionManager
Get the URI of the resource we are interested in.- Specified by:
getURI
in interfaceConnectionManager
- Returns:
- An URI
-
getInputStream
Description copied from interface:ConnectionManager
Get an InputStream for reading the contents of the resource.- Specified by:
getInputStream
in interfaceConnectionManager
- Returns:
- An InputStream object, or null if the no data is available
- Throws:
IOException
- If there is an error creating the stream
-
getInputStream
Description copied from interface:ResumableConnectionManager
Get an InputStream for reading the contents of the resource.- Specified by:
getInputStream
in interfaceResumableConnectionManager
- Parameters:
offset
- The offset to start reading from- Returns:
- An InputStream object, or null if the no data is available
- Throws:
IOException
- If there is an error creating the stream
-
getMetadata
Description copied from interface:ConnectionManager
Get metadata about the resource. If no metadata can be obtained the handler should still create an empty UriMetadata object.- Specified by:
getMetadata
in interfaceConnectionManager
- Returns:
- A metadata object
- Throws:
IOException
- If there is an error getting the metadata
-
setResponseFilter
Set a filter that will inspect the response before an input stream is returned to the calling code. The filter must return true to allow the processing to proceed. A false value aborts the processing. The filter may also throw an exception.- Since:
- 3.12
-
setTimeout
public void setTimeout(int timeoutInSeconds) Set a timeout in seconds to allocate for the request to return (not including downloading of data).- Parameters:
timeoutInSeconds
- Timeout in seconds- Since:
- 3.12
-
createCloseableHttpClient
public org.apache.http.impl.client.CloseableHttpClient createCloseableHttpClient(URI uri, ConnectionParameters parameters) throws IOException Get a HttpClient object that has been configured to access the given URI.- Throws:
IOException
-
createMetadata
Read metadata from the given http response and put the information in a UriMetadata object. This method uses whatever information that is in the response headers:- Content-Length: The length of the resource
- Last-Modified: The last modified date
- Content-Type: The MIME type and character set
-