Class DefensicsApiClientConnect


  • public class DefensicsApiClientConnect
    extends Object
    Helper class for client requests.
    • Constructor Detail

      • DefensicsApiClientConnect

        public DefensicsApiClientConnect​(HttpClient httpClient,
                                         com.fasterxml.jackson.databind.ObjectMapper objectMapper,
                                         String token)
        Constructor.
        Parameters:
        httpClient - Java HTTP client.
        objectMapper - Object mapper.
        token - Token to use in request. Can be null.
    • Method Detail

      • setUserAgent

        public void setUserAgent​(String userAgentString)
      • getInputStream

        protected InputStream getInputStream​(HttpUrl url,
                                             String operationString)
        GET given URL and return response as a stream. Note: caller needs to close the stream.
        Parameters:
        url - URL to GET
        operationString - Operation tried
        Returns:
        Response as a stream
      • postNoResponse

        protected void postNoResponse​(HttpUrl url,
                                      RequestBody body,
                                      String operationString)
        Calls post(url, body, operationString, null).
        Parameters:
        url - the target url.
        body - Body to send.
        operationString - name of the operation.
      • delete

        protected void delete​(HttpUrl url,
                              String operation)
        Do a HTTP DELETE.
        Parameters:
        url - the target URL.
        operation - operation for logging.
      • post

        protected <T> T post​(HttpUrl url,
                             RequestBody body,
                             String operationString,
                             com.fasterxml.jackson.core.type.TypeReference<Item<T>> typeReference)
        Make HTTP POST request to given url with given RequestBody. Read response if typeReference is non-null, otherwise null is returned.
        Type Parameters:
        T - Expected result type. Note that Item unwrapping is defined already.
        Parameters:
        url - URL
        body - Request body
        operationString - String used in e.g. error conditions. In format "upload testplan"
        typeReference - Type reference where to de-serialize response. If null, response is not read and null is returned.
        Returns:
        De-serialized response or null
      • getArrayItem

        protected <T> List<T> getArrayItem​(HttpUrl url,
                                           String operationString,
                                           com.fasterxml.jackson.core.type.TypeReference<ItemArray<T>> typeReference)
        Getter for array item.
        Parameters:
        url - the target url.
        operationString - name of the operation for logging.
        typeReference - type of the response.
        Returns:
        List of objects.
      • getSingleItem

        protected <T> Optional<T> getSingleItem​(HttpUrl url,
                                                String operationString,
                                                com.fasterxml.jackson.core.type.TypeReference<Item<T>> typeReference)
        Get single JSON item.
        Parameters:
        url - the target url.
        operationString - name of the operation for logging.
        typeReference - type of the response.
        Returns:
        Item wrapped in Optional.