Class JavaClient

  • All Implemented Interfaces:
    Client

    public class JavaClient
    extends java.lang.Object
    implements Client
    • Field Detail

      • config

        private final Config config
      • client

        private final java.net.http.HttpClient client
    • Constructor Detail

      • JavaClient

        public JavaClient​(Config config)
      • JavaClient

        public JavaClient​(Config config,
                          java.net.http.HttpClient client)
    • Method Detail

      • getClient

        public java.net.http.HttpClient getClient()
        Specified by:
        getClient in interface Client
        Returns:
        the underlying client if this instance is wrapping another library.
      • request

        public <T> HttpResponse<T> request​(HttpRequest request,
                                           java.util.function.Function<RawResponse,​HttpResponse<T>> transformer,
                                           java.lang.Class<?> resultType)
        Description copied from interface: Client
        Make a request
        Specified by:
        request in interface Client
        Type Parameters:
        T - The type of the body
        Parameters:
        request - the prepared request object
        transformer - the function to transform the response
        resultType - the final body result type. This is a hint to downstream systems to make up for type erasure.
        Returns:
        a HttpResponse with a transformed body
      • getRequest

        private java.net.http.HttpRequest getRequest​(HttpRequest<?> request)
      • setHeaders

        private void setHeaders​(HttpRequest<?> request,
                                java.net.http.HttpRequest.Builder jreq)
      • request

        public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> request​(HttpRequest request,
                                                                                   java.util.function.Function<RawResponse,​HttpResponse<T>> transformer,
                                                                                   java.util.concurrent.CompletableFuture<HttpResponse<T>> callback,
                                                                                   java.lang.Class<?> resultType)
        Description copied from interface: Client
        Make a Async request
        Specified by:
        request in interface Client
        Type Parameters:
        T - The type of the body
        Parameters:
        request - the prepared request object
        transformer - the function to transform the response
        callback - the CompletableFuture that will handle the eventual response
        resultType - the final body result type. This is a hint to downstream systems to make up for type erasure.
        Returns:
        a CompletableFuture of a response
      • websocket

        public WebSocketResponse websocket​(WebSocketRequest request,
                                           java.net.http.WebSocket.Listener listener)
        Description copied from interface: Client
        Create a websocket connection
        Specified by:
        websocket in interface Client
        Parameters:
        request - the connection
        listener - (in the voice of Cicero) the listener
        Returns:
        a WebSocketResponse
      • recoverBody

        private java.lang.String recoverBody​(RawResponse rr)