public class RestClient extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
RestClient.HttpMethodCall
An interface used as base for anonymous classes wrapping Http Method
calls.
|
| Modifier and Type | Field and Description |
|---|---|
protected javax.ws.rs.client.WebTarget |
endPoint |
protected com.fasterxml.jackson.databind.ObjectMapper |
jsonMapper |
protected Logger |
logger |
protected javax.ws.rs.client.Client |
restClient |
protected URI |
serverUrl |
| Constructor and Description |
|---|
RestClient(Logger logger,
URI serverUrl)
Creates a rest client instance with timeout default of 5 minutes and
no proxy settings.
|
RestClient(Logger logger,
URI serverUrl,
int timeout) |
| Modifier and Type | Method and Description |
|---|---|
ProxySettings |
getProxyBase() |
protected String |
getReadResponseError(String errMsg,
int statusCode,
String statusPhrase,
String responseBody)
Builds an error message which includes the response data.
|
protected URI |
getServerUrlBase() |
int |
getTimeout() |
protected <T> T |
parseResponseWithJsonData(javax.ws.rs.core.Response response,
List<Integer> validHttpStatusCodes,
Class<T> resultType)
Generic handling of response with data.
|
protected javax.ws.rs.core.Response |
sendLongRequest(RestClient.HttpMethodCall method,
String name) |
void |
setProxyBase(ProxySettings proxySettings)
Sets the proxy settings to be used by the rest client.
|
protected void |
setServerUrlBase(URI serverUrl)
Sets the current server URL used by the rest client.
|
void |
setTimeout(int timeout)
Sets the connect and read timeouts for web requests.
|
protected final Logger logger
protected javax.ws.rs.client.Client restClient
protected URI serverUrl
protected javax.ws.rs.client.WebTarget endPoint
protected com.fasterxml.jackson.databind.ObjectMapper jsonMapper
public RestClient(Logger logger, URI serverUrl, int timeout)
logger - Logger instance.serverUrl - The URI of the rest server.timeout - Connect/Read timeout in milliseconds. 0 equals infinity.public void setProxyBase(ProxySettings proxySettings)
proxySettings - The proxy settings to be used by the rest client.
If null then no proxy is set.public ProxySettings getProxyBase()
null if no proxy is set.public void setTimeout(int timeout)
timeout - Connect/Read timeout in milliseconds. 0 equals infinity.public int getTimeout()
protected void setServerUrlBase(URI serverUrl)
serverUrl - The URI of the rest server.protected URI getServerUrlBase()
protected javax.ws.rs.core.Response sendLongRequest(RestClient.HttpMethodCall method, String name) throws EyesException
EyesExceptionprotected String getReadResponseError(String errMsg, int statusCode, String statusPhrase, String responseBody)
errMsg - The error message.statusCode - The response status code.statusPhrase - The response status phrase.responseBody - The response body.protected <T> T parseResponseWithJsonData(javax.ws.rs.core.Response response,
List<Integer> validHttpStatusCodes,
Class<T> resultType)
throws EyesException
T - The return value type.response - The response to parse.validHttpStatusCodes - The list of acceptable status codes.resultType - The class object of the type of result this response
should be parsed to.resultType.EyesException - For invalid status codes or if the response
parsing failed.Copyright © 2016. All rights reserved.