Class RestClient


  • public class RestClient
    extends Object
    • Field Detail

      • logger

        protected com.applitools.eyes.Logger logger
      • restClient

        protected com.applitools.connectivity.api.HttpClient restClient
      • serverUrl

        protected URI serverUrl
      • agentId

        protected String agentId
      • jsonMapper

        protected com.fasterxml.jackson.databind.ObjectMapper jsonMapper
    • 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)
      • 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.EyesException
        Generic 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)