Class ServiceClient

  • Direct Known Subclasses:
    Client

    public class ServiceClient
    extends Object
    This class is a client that talks to a server. It manages a client pool and does a get based on pairs of strings, which are assumed to be of the form {{key1,value1},{key2,value2},...}

    Created by Jeff Gaynor
    on 5/21/12 at 1:43 PM

    • Field Detail

      • clientPool

        protected Pool<org.apache.http.client.HttpClient> clientPool
      • ENCODING

        public static String ENCODING
      • ECHO_REQUEST

        public static boolean ECHO_REQUEST
      • ECHO_RESPONSE

        public static boolean ECHO_RESPONSE
    • Constructor Detail

      • ServiceClient

        public ServiceClient​(URI address)
        Basic default service client that uses the java keystore only.
        Parameters:
        address -
    • Method Detail

      • isVerbose

        public boolean isVerbose()
      • setVerbose

        public void setVerbose​(boolean verbose)
      • host

        public URI host​(URI... x)
      • convertToStringRequest

        public static String convertToStringRequest​(String host,
                                                    Map m)
      • doPost

        public String doPost​(Map m)
        Does a POST using only the map. This is useful if there are other authentication methods used that are encoded as parameters (e.g. RFC 7523).
        Parameters:
        m -
        Returns:
      • convertToStringRequest

        public static String convertToStringRequest​(String host,
                                                    String[][] args)
      • doPost

        public String doPost​(Map<String,​Object> parameters,
                             String id,
                             String secret)
        Do an HTTP POST to the endpoint sending along basic authorization and any parameters. This returns a string, so do process the result.
        Parameters:
        parameters -
        id -
        secret -
        Returns:
      • doPost

        public String doPost​(Map<String,​Object> parameters,
                             String bearerToken)
        Do post using a bearer token
        Parameters:
        bearerToken -
        Returns:
      • doRequest

        protected String doRequest​(org.apache.http.client.methods.HttpRequestBase httpRequestBase,
                                   String id,
                                   String secret)
        This will set the basic authorization in the headers for the request.
        Parameters:
        httpRequestBase -
        id -
        secret -
        Returns:
      • doBearerRequest

        protected String doBearerRequest​(org.apache.http.client.methods.HttpRequestBase httpRequestBase,
                                         String token,
                                         boolean base64Encode)
        If the token is not already base 64 or 32 encoded, option flag to do so.
        Parameters:
        httpRequestBase -
        token - -- the bearer token
        base64Encode -
        Returns:
      • doBearerRequest

        protected String doBearerRequest​(org.apache.http.client.methods.HttpRequestBase httpRequestBase,
                                         String token)
        Process the request, but use a bearer token (the access token which should eb suitably encoded)
        Parameters:
        httpRequestBase -
        token -
        Returns:
      • doRequest

        protected String doRequest​(org.apache.http.client.methods.HttpRequestBase httpRequestBase)
        Do the request. The response will be the response of the server if there was a success. Otherwise, the response will be (a) constructed if not JSON or (b) the JSON if the server response is a JSON payload. It is becoming de facto standard to return JSON as part of the error, so we should just send that along.
        Parameters:
        httpRequestBase -
        Returns: