public abstract class AbstractRequester extends Object
Class which contains the logic for sending URL requests to a specified address.
Modifier and Type | Field and Description |
---|---|
protected Charset |
charset |
protected org.apache.http.client.HttpClient |
client |
protected Map<String,String> |
requestProperties |
Modifier | Constructor and Description |
---|---|
protected |
AbstractRequester()
Default constructor.
|
protected |
AbstractRequester(Charset charset)
Overloaded constructor.
|
Modifier and Type | Method and Description |
---|---|
protected String |
getBody(org.apache.http.HttpResponse response)
Extracts the response body from the
HttpResponse . |
abstract String |
getBodyAsString(String url)
Returns the response from the specified URL as a string.
|
String |
getBodyAsStringFromTable(String table)
Return the content from the specified table.
|
Charset |
getCharset()
Getter for charset.
|
protected org.apache.http.HttpResponse |
getResponse(org.apache.http.client.methods.HttpRequestBase request)
Performs a request with the specified
HttpRequest and retrieves the
response as a HttpResponse . |
void |
setCharset(Charset charset)
Setter for charset.
|
protected Charset charset
protected org.apache.http.client.HttpClient client
protected AbstractRequester()
Default constructor. Specifies the charset to be used for requests as UTF-8.
protected AbstractRequester(Charset charset)
Overloaded constructor. Loads the request properties and other data needed for the requesters.
charset
- the charset to use when doing a requestprotected org.apache.http.HttpResponse getResponse(org.apache.http.client.methods.HttpRequestBase request)
Performs a request with the specified HttpRequest
and retrieves the
response as a HttpResponse
.
request
- the requestprotected String getBody(org.apache.http.HttpResponse response)
Extracts the response body from the HttpResponse
.
response
- the response to extract the body frompublic String getBodyAsStringFromTable(String table)
Return the content from the specified table.
table
- the table to fetch the content frompublic abstract String getBodyAsString(String url)
Returns the response from the specified URL as a string.
url
- the URL to get the response frompublic Charset getCharset()
Getter for charset.
public void setCharset(Charset charset)
Setter for charset. Also updates the request properties with the new charset.
charset
- the charsetCopyright © 2016. All rights reserved.