public class HapiService
extends java.lang.Object
Constructor and Description |
---|
HapiService(java.lang.String url)
Constructor with default content coding.
|
HapiService(java.lang.String url,
java.util.function.Supplier<ContentCoding> codingSupplier)
Constructor with configurable content coding.
|
Modifier and Type | Method and Description |
---|---|
java.net.URL |
createQuery(HapiEndpoint endpoint,
java.util.Map<java.lang.String,java.lang.String> requestParams)
Returns a URL representing a query to a given endpoint of this service
with specified parameters.
|
boolean |
equals(java.lang.Object o) |
static java.util.Map<java.lang.String,java.lang.String> |
getRequestParameters(java.net.URL hapiUrl)
Parses a HAPI request URL to return a name-value map giving the
request parameters.
|
int |
hashCode() |
java.io.InputStream |
openChunkedStream(java.net.URL url,
int chunkLimit,
IOConsumer<java.lang.String> limitCallback)
Opens an input stream from for a HAPI data request
that may be broken into several chunks if it encounters
a HAPI 1408 "Bad request - too much time or data requested" response.
|
java.io.InputStream |
openStream(java.net.URL url)
Reads an input stream for a URL pointing at this service.
|
org.json.JSONObject |
readJson(HapiEndpoint endpoint)
Reads a JSON object from an endpoint of this service with
no additional request parameters.
|
org.json.JSONObject |
readJson(HapiEndpoint endpoint,
java.util.Map<java.lang.String,java.lang.String> requestParams)
Reads a JSON object from an endpoint of this service with
supplied additional request parameters.
|
public HapiService(java.lang.String url) throws java.net.MalformedURLException
url
- service base URL, with or without trailing slashjava.net.MalformedURLException
- if it's not an HTTP or HTTPS URLpublic HapiService(java.lang.String url, java.util.function.Supplier<ContentCoding> codingSupplier) throws java.net.MalformedURLException
url
- service base URL, with or without trailing slashcodingSupplier
- supplier for content coding,
or null for defaultjava.net.MalformedURLException
- if it's not an HTTP or HTTPS URLpublic java.net.URL createQuery(HapiEndpoint endpoint, java.util.Map<java.lang.String,java.lang.String> requestParams)
endpoint
- endpointrequestParams
- map of key-value pairs giving additional
request parameterspublic java.io.InputStream openStream(java.net.URL url) throws java.io.IOException
URL.openStream()
,
but handles a few extras like service-sensitive logging,
HTTP-level compression and 3xx indirection.url
- URLjava.io.IOException
public java.io.InputStream openChunkedStream(java.net.URL url, int chunkLimit, IOConsumer<java.lang.String> limitCallback) throws java.io.IOException
A limit must be supplied for the maximum number of chunks that
will be retrieved for a given request.
If this limit is exceeded, behaviour depends on the supplied
failOnLimit
flag.
If true, then such a request fails with an IOException.
If false, the input stream includes all the data from the
maximum number of chunks, and a WARNING is issued through the
logging system to indicate that not the whole stream was included.
url
- HAPI request URLchunkLimit
- the maximum number of chunks permittedlimitCallback
- called with message if chunk limit is exceeded;
may be nulljava.io.IOException
public org.json.JSONObject readJson(HapiEndpoint endpoint) throws java.io.IOException
endpoint
- endpointjava.io.IOException
public org.json.JSONObject readJson(HapiEndpoint endpoint, java.util.Map<java.lang.String,java.lang.String> requestParams) throws java.io.IOException
endpoint
- endpointrequestParams
- map of key-value pairs giving additional
request parametersjava.io.IOException
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public static java.util.Map<java.lang.String,java.lang.String> getRequestParameters(java.net.URL hapiUrl)
hapiUrl
- URL