Package com.applitools.connectivity
Class RestClient
- java.lang.Object
-
- com.applitools.connectivity.RestClient
-
public class RestClient extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceRestClient.HttpMethodCallAn interface used as base for anonymous classes wrapping Http Method calls.protected static interfaceRestClient.HttpRequestBuilder
-
Field Summary
Fields Modifier and Type Field Description protected StringagentIdprotected com.fasterxml.jackson.databind.ObjectMapperjsonMapperprotected com.applitools.eyes.Loggerloggerprotected com.applitools.connectivity.api.HttpClientrestClientprotected URIserverUrl
-
Constructor Summary
Constructors Constructor Description RestClient(com.applitools.eyes.Logger logger, URI serverUrl, int timeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]downloadFile(com.applitools.connectivity.api.Response response)StringgetAgentId()com.applitools.eyes.LoggergetLogger()com.applitools.eyes.AbstractProxySettingsgetProxy()protected StringgetReadResponseError(String errMsg, int statusCode, String statusPhrase, String responseBody)Builds an error message which includes the response model.protected URIgetServerUrlBase()intgetTimeout()protected voidinitClient()protected com.applitools.connectivity.api.AsyncRequestmakeEyesRequest(RestClient.HttpRequestBuilder builder)protected <T> TparseResponseWithJsonData(com.applitools.connectivity.api.Response response, List<Integer> validHttpStatusCodes, com.fasterxml.jackson.core.type.TypeReference<T> resultType)Generic handling of response with model.voidsendAsyncRequest(com.applitools.connectivity.api.AsyncRequestCallback callback, String url, String method, String... accept)voidsendAsyncRequest(com.applitools.connectivity.api.AsyncRequestCallback callback, String url, String method, Map<String,String> queryParams, String... accept)voidsendAsyncRequest(com.applitools.connectivity.api.AsyncRequest request, String method, com.applitools.connectivity.api.AsyncRequestCallback callback)voidsendAsyncRequest(com.applitools.connectivity.api.AsyncRequest request, String method, com.applitools.connectivity.api.AsyncRequestCallback callback, Object data, String contentType)com.applitools.connectivity.api.ResponsesendHttpRequest(String url, String method, Object data, String contentType, String... accept)com.applitools.connectivity.api.ResponsesendHttpRequest(String url, String method, String... accept)Send a synchronous request to the servercom.applitools.connectivity.api.ResponsesendHttpRequest(String url, String method, Map<String,String> queryParams, String... accept)protected voidsendLongRequest(com.applitools.connectivity.api.AsyncRequest request, String method, com.applitools.connectivity.api.AsyncRequestCallback callback, String data, String mediaType)voidsetAgentId(String agentId)voidsetLogger(com.applitools.eyes.Logger logger)voidsetProxy(com.applitools.eyes.AbstractProxySettings proxySettings)protected voidsetServerUrlBase(URI serverUrl)voidsetTimeout(int timeout)
-
-
-
Constructor Detail
-
RestClient
public RestClient(com.applitools.eyes.Logger logger, URI serverUrl, int timeout)- Parameters:
logger- Logger instance.serverUrl- The URI of the rest server.
-
-
Method Detail
-
setLogger
public void setLogger(com.applitools.eyes.Logger logger)
-
getLogger
public com.applitools.eyes.Logger getLogger()
-
setProxy
public void setProxy(com.applitools.eyes.AbstractProxySettings proxySettings)
-
getProxy
public com.applitools.eyes.AbstractProxySettings getProxy()
-
setTimeout
public void setTimeout(int timeout)
-
getTimeout
public int getTimeout()
-
setServerUrlBase
protected void setServerUrlBase(URI serverUrl)
-
getServerUrlBase
protected URI getServerUrlBase()
-
setAgentId
public void setAgentId(String agentId)
-
getAgentId
public String getAgentId()
-
initClient
protected void initClient()
-
sendAsyncRequest
public void sendAsyncRequest(com.applitools.connectivity.api.AsyncRequestCallback callback, String url, String method, String... accept)
-
sendAsyncRequest
public void sendAsyncRequest(com.applitools.connectivity.api.AsyncRequestCallback callback, String url, String method, Map<String,String> queryParams, String... accept)
-
sendAsyncRequest
public void sendAsyncRequest(com.applitools.connectivity.api.AsyncRequest request, String method, com.applitools.connectivity.api.AsyncRequestCallback callback)
-
sendAsyncRequest
public void sendAsyncRequest(com.applitools.connectivity.api.AsyncRequest request, String method, com.applitools.connectivity.api.AsyncRequestCallback callback, Object data, String contentType)
-
makeEyesRequest
protected com.applitools.connectivity.api.AsyncRequest makeEyesRequest(RestClient.HttpRequestBuilder builder)
-
sendHttpRequest
public com.applitools.connectivity.api.Response sendHttpRequest(String url, String method, String... accept)
Send a synchronous request to the server
-
sendHttpRequest
public com.applitools.connectivity.api.Response sendHttpRequest(String url, String method, Map<String,String> queryParams, String... accept)
-
sendHttpRequest
public com.applitools.connectivity.api.Response sendHttpRequest(String url, String method, Object data, String contentType, String... accept)
-
sendLongRequest
protected void sendLongRequest(com.applitools.connectivity.api.AsyncRequest request, String method, com.applitools.connectivity.api.AsyncRequestCallback callback, String data, String mediaType) throws com.applitools.eyes.EyesException- Throws:
com.applitools.eyes.EyesException
-
getReadResponseError
protected String getReadResponseError(String errMsg, int statusCode, String statusPhrase, String responseBody)
Builds an error message which includes the response model.- Parameters:
errMsg- The error message.statusCode- The response status code.statusPhrase- The response status phrase.responseBody- The response body.- Returns:
- An error message which includes the response model.
-
parseResponseWithJsonData
protected <T> T parseResponseWithJsonData(com.applitools.connectivity.api.Response response, List<Integer> validHttpStatusCodes, com.fasterxml.jackson.core.type.TypeReference<T> resultType) throws com.applitools.eyes.EyesExceptionGeneric handling of response with model. Response Handling includes the following: 1. Verify that we are able to read response model. 2. verify that the status code is valid 3. Parse the response model from JSON to the relevant type.- Type Parameters:
T- The return value type.- Parameters:
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.- Returns:
- The parse response of the type given in
resultType. - Throws:
com.applitools.eyes.EyesException- For invalid status codes or if the response parsing failed.
-
downloadFile
protected byte[] downloadFile(com.applitools.connectivity.api.Response response)
-
-