public class WebDataRetriever extends Object implements IDataRetriever
| Constructor and Description |
|---|
WebDataRetriever(com.google.gson.Gson gson,
Charset charset)
Constructor that sets the GSON (de-)serializer for reading and
writing JSON objects, as well as the charset.
|
WebDataRetriever(com.google.gson.Gson gson,
Charset charset,
int timeout)
Constructor that sets the GSON (de-)serializer for reading and
writing JSON objects, as well as the charset and timeout.
|
WebDataRetriever(WebDataRetriever other)
Constructor that copies settings from another WebDataRetriever.
|
| Modifier and Type | Method and Description |
|---|---|
org.jsoup.nodes.Document |
getHtml(String url)
Tries to parse the content from a specified path as a
HTML document.
|
InputStream |
getInputStream(HttpURLConnection connection)
Returns the correct InputStream based on the Content-Encoding header of
a connection.
|
<T> T |
getObject(String url,
Class<T> targetClass)
Tries to parse the content from a specified path as a
JSON object.
|
<T> T |
getObject(String url,
Type targetType)
Tries to parse the content from a specified path as a
JSON object.
|
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,
String authorization,
String contentType)
Sends an authorized REST request with a specified body and returns the
response as a string.
|
String |
getString(String url)
Tries to parse the content from a specified path as a string.
|
HttpURLConnection |
sendWebRequest(RestRequestType method,
String urlString,
String body,
String authorization,
String contentType,
int retries)
Sends a REST request with a specified body and returns the connection.
|
void |
setCharset(Charset charset)
Changes the charset used for (de-)serializing requests.
|
void |
setTimeout(int timeout) |
public WebDataRetriever(com.google.gson.Gson gson,
Charset charset,
int timeout)
gson - the GSON (de-)serializer for reading and writing JSON objectscharset - the charset of the files to be read and writtentimeout - the web request timeout in millisecondspublic WebDataRetriever(com.google.gson.Gson gson,
Charset charset)
gson - the GSON (de-)serializer for reading and writing JSON objectscharset - the charset of the files to be read and writtenpublic WebDataRetriever(WebDataRetriever other)
other - the WebDataRetriever of which the settings are copiedpublic String getString(String url)
IDataRetrievergetString in interface IDataRetrieverurl - the path to a HTML filepublic <T> T getObject(String url, Class<T> targetClass)
IDataRetrievergetObject in interface IDataRetrieverT - the type of the object that is to be readurl - the path to a JSON filetargetClass - the class of the object that is read from discpublic <T> T getObject(String url, Type targetType)
IDataRetrievergetObject in interface IDataRetrieverT - the type of the object that is to be readurl - the path to a JSON filetargetType - the type of the object that is read from discpublic org.jsoup.nodes.Document getHtml(String url)
IDataRetrievergetHtml in interface IDataRetrieverurl - the path to a HTML filepublic 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 request, or null if no body is to be sentauthorization - 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, 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 request, or null if no body is to be sentauthorization - 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 HttpURLConnection sendWebRequest(RestRequestType method, String urlString, String body, String authorization, String contentType, int retries) throws IOException, HTTPException
method - the request method that is being senturlString - the URL to which the request is being sentbody - the body of the request, or null if no body is to be sentauthorization - the base-64-encoded username and password, or null if no
authorization is requiredcontentType - the contentType of the bodyretries - the number of retries if the request fails with a response code 5xxHTTPException - thrown if the response code is not 2xxIOException - thrown if the response output stream could not be createdpublic InputStream getInputStream(HttpURLConnection connection) throws IOException
connection - the connection to be checkedIOException - thrown if InputStream is corruptedpublic void setTimeout(int timeout)
public void setCharset(Charset charset)
IDataRetrieversetCharset in interface IDataRetrievercharset - the new charsetCopyright © 2017–2019. All rights reserved.