public class HttpRequester extends Object
| Constructor and Description |
|---|
HttpRequester()
Constructor that uses an UTF-8 charset, and a Gson
implementation that can parse Geometry objects.
|
HttpRequester(com.google.gson.Gson gson,
Charset httpCharset)
Constructor that allows to customize the behavior.
|
HttpRequester(HttpRequester other)
Constructor that copies the settings from another HttpRequester.
|
| Modifier and Type | Method and Description |
|---|---|
File |
getCacheFolder() |
org.jsoup.nodes.Document |
getHtmlFromUrl(String url)
Sends a GET request to a specified URL and tries to retrieve the HTML
response.
|
<T> T |
getObjectFromUrl(String url,
Class<T> targetClass)
Sends a GET request to a specified URL and tries to retrieve the JSON
response, mapping it to a Java object.
|
<T> T |
getObjectFromUrl(String url,
Type targetType)
Sends a GET request to a specified URL and tries to retrieve the JSON
response, mapping it to a Java object.
|
Map<String,List<String>> |
getRestHeader(RestRequestType method,
String url,
String body)
Sends a REST request with a plain-text body and returns the header
fields.
|
Map<String,List<String>> |
getRestHeader(RestRequestType method,
String url,
String body,
String authorization,
String contentType)
Sends an authorized REST request with a specified body and returns the
header fields.
|
String |
getRestResponse(RestRequestType method,
String url,
String body)
Sends an REST request with a plain-text body.
|
String |
getRestResponse(RestRequestType method,
String url,
String body,
String authorization,
String contentType)
Sends an authorized REST request with a specified body and returns the
response as a string.
|
boolean |
isReadingFromDisk()
Returns true if HTTP responses are read from a cache on disk.
|
boolean |
isWritingToDisk()
Returns true if HTTP responses are written to a cache on disk.
|
void |
setCacheFolder(File cacheFolder) |
void |
setCharset(Charset httpCharset)
Changes the charset that is used for reading and writing responses.
|
void |
setTimeout(int timeout)
Changes the request timeout for web requests.
|
public HttpRequester()
public HttpRequester(com.google.gson.Gson gson,
Charset httpCharset)
gson - the GSON (de-)serializer for reading and writing JSON objectshttpCharset - the encoding charsetpublic HttpRequester(HttpRequester other)
other - the HttpRequester from which the settings are copiedpublic org.jsoup.nodes.Document getHtmlFromUrl(String url)
url - a URL that returns a JSON objectpublic <T> T getObjectFromUrl(String url, Class<T> targetClass)
T - the type of the returned objecturl - a URL that returns a JSON objecttargetClass - the class of the returned objectpublic <T> T getObjectFromUrl(String url, Type targetType)
T - the type of the returned objecturl - a URL that returns a JSON objecttargetType - the type of the returned objectpublic String getRestResponse(RestRequestType method, String url, String body) throws HTTPException, IOException
method - the request method that is being senturl - the URL to which the request is being sentbody - the plain-text body of the requestHTTPException - thrown if the response code is not 2xxIOException - thrown if the response output stream could not be createdpublic String getRestResponse(RestRequestType method, String url, String body, String authorization, String contentType) throws HTTPException, IOException
method - the request method that is being senturl - the URL to which the request is being sentbody - the body of the requestauthorization - the base-64-encoded username and password, or null if no
authorization is requiredcontentType - the contentType of the bodyHTTPException - thrown if the response code is not 2xxIOException - thrown if the response output stream could not be createdpublic Map<String,List<String>> getRestHeader(RestRequestType method, String url, String body) throws HTTPException, IOException
method - the request method that is being senturl - the URL to which the request is being sentbody - the plain-text body of the requestHTTPException - thrown if the response code is not 2xxIOException - thrown if the response output stream could not be createdpublic Map<String,List<String>> getRestHeader(RestRequestType method, String url, String body, String authorization, String contentType) throws HTTPException, IOException
method - the request method that is being senturl - the URL to which the request is being sentbody - the body of the requestauthorization - the base-64-encoded username and password, or null if no
authorization is requiredcontentType - the contentType of the bodyHTTPException - thrown if the response code is not 2xxIOException - thrown if the response output stream could not be createdpublic void setTimeout(int timeout)
timeout - the request timeout in millisecondspublic boolean isReadingFromDisk()
public boolean isWritingToDisk()
public void setCharset(Charset httpCharset)
httpCharset - the charset that is used for reading and writing responsespublic File getCacheFolder()
public void setCacheFolder(File cacheFolder)
Copyright © 2017–2019. All rights reserved.