Package pl.gsmservice.gateway.utils
Class SpeakeasyHTTPClient
- java.lang.Object
-
- pl.gsmservice.gateway.utils.SpeakeasyHTTPClient
-
- All Implemented Interfaces:
HTTPClient
public class SpeakeasyHTTPClient extends java.lang.Object implements HTTPClient
-
-
Constructor Summary
Constructors Constructor Description SpeakeasyHTTPClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidenableDebugLogging(boolean enabled)Controls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses.static booleangetDebugLoggingEnabled()booleanisDebugLoggingEnabled()Returns whether debug logging is enabled.java.net.http.HttpResponse<java.io.InputStream>send(java.net.http.HttpRequest request)Sends an HTTP request and returns the response.java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>>sendAsync(java.net.http.HttpRequest request)Sends an HTTP request asynchronously and returns a response whose body is exposed as aBlob.static voidsetDebugLogging(boolean enabled)Experimental, may be changed anytime.static voidsetLogger(java.util.function.Consumer<? super java.lang.String> logger)static voidsetRedactedHeaders(java.util.Collection<java.lang.String> headerNames)Experimental, may be changed anytime.
-
-
-
Method Detail
-
setDebugLogging
public static void setDebugLogging(boolean enabled)
Experimental, may be changed anytime. Sets debug logging on or off for requests and responses including bodies for JSON content. WARNING: this setting may expose sensitive information in logs (like Authorization headers), and should only be enabled temporarily for local debugging purposes. By default, Authorization headers are redacted in the logs ( printed with a value of[*******]). Header suppression is controlled with thesetRedactedHeaders(Collection)method.- Parameters:
enabled- true to enable debug logging, false to disable it
-
getDebugLoggingEnabled
public static boolean getDebugLoggingEnabled()
-
isDebugLoggingEnabled
public boolean isDebugLoggingEnabled()
Description copied from interface:HTTPClientReturns whether debug logging is enabled.- Specified by:
isDebugLoggingEnabledin interfaceHTTPClient- Returns:
- Whether debug logging is enabled
-
enableDebugLogging
public void enableDebugLogging(boolean enabled)
Description copied from interface:HTTPClientControls the debug flag that can be used by clients to perform conditional debugging actions like logging HTTP requests and responses. This is currently implemented in SpeakeasyHTTPClient but custom client implementations are free to use this method similarly if they wish.- Specified by:
enableDebugLoggingin interfaceHTTPClient- Parameters:
enabled- Whether to enable debug flag
-
setRedactedHeaders
public static void setRedactedHeaders(java.util.Collection<java.lang.String> headerNames)
Experimental, may be changed anytime. When debug logging is enabled this method controls the suppression of header values in the logs. By default, Authorization headers are redacted in the logs (printed with a value of[*******]). Header suppression is controlled with thesetRedactedHeaders(Collection)method.- Parameters:
headerNames- the names (case-insensitive) of the headers whose values will be redacted in the logs
-
setLogger
public static void setLogger(java.util.function.Consumer<? super java.lang.String> logger)
-
send
public java.net.http.HttpResponse<java.io.InputStream> send(java.net.http.HttpRequest request) throws java.io.IOException, java.lang.InterruptedException, java.net.URISyntaxExceptionDescription copied from interface:HTTPClientSends an HTTP request and returns the response.Note that
HttpRequestis immutable. To modify the request you can useHttpRequest#newBuilder(HttpRequest, BiPredicate<String, String>)with JDK 16 and later (which will copy the request for modification in a builder). If that method is not available then useHelpers.copy(java.net.http.HttpRequest)(which also returns a builder).- Specified by:
sendin interfaceHTTPClient- Parameters:
request- HTTP request- Returns:
- HTTP response
- Throws:
java.io.IOExceptionjava.lang.InterruptedExceptionjava.net.URISyntaxException
-
sendAsync
public java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> sendAsync(java.net.http.HttpRequest request)
Description copied from interface:HTTPClientSends an HTTP request asynchronously and returns a response whose body is exposed as aBlob.This method uses the
HttpResponse.BodyHandlers.ofPublisher()to obtain the response body as aFlow.Publisher<List<ByteBuffer>>, which is then wrapped in aBlobfor non-blocking, reactive consumption of the response data.The returned
CompletableFuturecompletes when the response is received, or completes exceptionally if an error occurs during the request or response processing.- Specified by:
sendAsyncin interfaceHTTPClient- Parameters:
request- the HTTP request to send- Returns:
- a
CompletableFuturecontaining the HTTP response with aBlobbody
-
-