Class HttpClientService

    • Method Detail

      • executeJsonRequest

        public Optional<org.json.JSONObject> executeJsonRequest​(org.apache.http.client.methods.HttpRequestBase request)
        executes the provided HttpRequestBase returning the result as a JSONObject
        Specified by:
        executeJsonRequest in interface ClientService
        Parameters:
        request - the request to send/execute
        Returns:
        on success an Optional containing a JSONObject; otherwise, Optional.empty()
      • executeEntityRequest

        public Optional<org.apache.http.HttpEntity> executeEntityRequest​(org.apache.http.client.methods.HttpRequestBase request)
        executes the provided HttpRequestBase returning the result as a HttpEntity
        Parameters:
        request - the request to send/execute
        Returns:
        on success an Optional containing a HttpEntity; otherwise, Optional.empty()
      • buildGetRequestUsingFormUrlEncoding

        public Optional<org.apache.http.client.methods.HttpGet> buildGetRequestUsingFormUrlEncoding​(String endpoint,
                                                                                                    String authToken)
        Builds a HttpGet request object for the endpoint given by endpoint using authToken as basic authentication header
        Specified by:
        buildGetRequestUsingFormUrlEncoding in interface ClientService
        Parameters:
        endpoint - endpoint to perform get request on
        authToken - authorization token for basic authentication
        Returns:
        Optional of HttpGet containing the request object
        Throws:
        IllegalArgumentException - when either endpoint or authToken are null or empty
      • buildGetRequestUsingFormUrlEncoding

        public Optional<org.apache.http.client.methods.HttpGet> buildGetRequestUsingFormUrlEncoding​(String endpoint,
                                                                                                    String authToken,
                                                                                                    org.apache.http.NameValuePair... params)
        builds a HttpGet request object for the given endpoint using authToken as basic authentication header and params as additional URL key/value parameters
        Specified by:
        buildGetRequestUsingFormUrlEncoding in interface ClientService
        Parameters:
        endpoint - endpoint to perform get request on
        authToken - authorization token for basic authentication
        params - name/value pairs encoded and added to endpoint
        Returns:
        Optional of HttpGet containing the request object
        Throws:
        IllegalArgumentException - when either endpoint or authToken are null or empty
      • buildGetAcceptionApplicatonJson

        public Optional<org.apache.http.client.methods.HttpGet> buildGetAcceptionApplicatonJson​(String endpoint,
                                                                                                String authToken)
        builds a HttpGet request object for the given endpoint using authToken as basic authentication header. Request is sent using Content-Type and Accept as Application/json
        Specified by:
        buildGetAcceptionApplicatonJson in interface ClientService
        Parameters:
        endpoint - endpoint to perform get request on
        authToken - authorization token for basic authentication
        Returns:
        Optional of HttpGet containing the request object
        Throws:
        IllegalArgumentException - when either endpoint or authToken are null or empty
      • buildPostRequestUsingApplicationJson

        public Optional<org.apache.http.client.methods.HttpPost> buildPostRequestUsingApplicationJson​(String endpoint,
                                                                                                      org.apache.http.HttpEntity body)
        builds a HttpPost request object for the given endpoint containing the provided body content body will be posted using Content-Type of application/json
        Specified by:
        buildPostRequestUsingApplicationJson in interface ClientService
        Parameters:
        endpoint - endpoint to perform post request on
        body - JSON body to be sent with the request
        Returns:
        Optional of HttpPost containg the request object
      • buildPostRequestUsingFormUrlEncoding

        public Optional<org.apache.http.client.methods.HttpPost> buildPostRequestUsingFormUrlEncoding​(String endpoint,
                                                                                                      String authToken,
                                                                                                      org.apache.http.NameValuePair... params)
        builds a HttpPost request object for the given endpoint containing the provided body content body will be posted using Content-Type as application/x-www-form-urlencoded
        Specified by:
        buildPostRequestUsingFormUrlEncoding in interface ClientService
        Parameters:
        endpoint - endpoint to perform post request on
        authToken - authorization token for basic authentication
        params - name/value pairs sent as the entity of the request
        Returns:
        Optional of HttpPost containg the request object