public class HapiService extends Object
Constructor and Description |
---|
HapiService(String url)
Constructor with default content coding.
|
HapiService(String url,
java.util.function.Supplier<ContentCoding> codingSupplier)
Constructor with configurable content coding.
|
Modifier and Type | Method and Description |
---|---|
URL |
createQuery(HapiEndpoint endpoint,
Map<String,String> requestParams)
Returns a URL representing a query to a given endpoint of this service
with specified parameters.
|
boolean |
equals(Object o) |
static Map<String,String> |
getRequestParameters(URL hapiUrl)
Parses a HAPI request URL to return a name-value map giving the
request parameters.
|
int |
hashCode() |
InputStream |
openChunkedStream(URL url,
int chunkLimit,
IOConsumer<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.
|
InputStream |
openStream(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,
Map<String,String> requestParams)
Reads a JSON object from an endpoint of this service with
supplied additional request parameters.
|
public HapiService(String url) throws MalformedURLException
url
- service base URL, with or without trailing slashMalformedURLException
- if it's not an HTTP or HTTPS URLpublic HapiService(String url, java.util.function.Supplier<ContentCoding> codingSupplier) throws MalformedURLException
url
- service base URL, with or without trailing slashcodingSupplier
- supplier for content coding,
or null for defaultMalformedURLException
- if it's not an HTTP or HTTPS URLpublic URL createQuery(HapiEndpoint endpoint, Map<String,String> requestParams)
endpoint
- endpointrequestParams
- map of key-value pairs giving additional
request parameterspublic InputStream openStream(URL url) throws IOException
URL.openStream()
,
but handles a few extras like service-sensitive logging,
HTTP-level compression and 3xx indirection.url
- URLIOException
public InputStream openChunkedStream(URL url, int chunkLimit, IOConsumer<String> limitCallback) throws 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 nullIOException
public org.json.JSONObject readJson(HapiEndpoint endpoint) throws IOException
endpoint
- endpointIOException
public org.json.JSONObject readJson(HapiEndpoint endpoint, Map<String,String> requestParams) throws IOException
endpoint
- endpointrequestParams
- map of key-value pairs giving additional
request parametersIOException
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.