Class SpeakeasyHTTPClient
- java.lang.Object
-
- com.stackone.stackone_client_java.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 static voidaddRedactedHeader(java.lang.String headerName)When debug logging is enabled, this method adds a single header to the list of headers whose values will be redacted in the logs.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)Sets debug logging on or off for requests and responses including bodies for JSON content.static voidsetLogger(java.util.function.Consumer<? super java.lang.String> logger)static voidsetRedactedHeaders(java.util.Collection<java.lang.String> headerNames)When debug logging is enabled, this method controls the suppression of header values in the logs.
-
-
-
Method Detail
-
setDebugLogging
public static void setDebugLogging(boolean enabled)
Sets debug logging on or off for requests and responses including bodies for JSON content.WARNING: This setting may expose sensitive information in logs (such as
Authorizationheaders) and should only be enabled temporarily for local debugging purposes.By default,
Authorizationheaders are redacted in the logs (printed with a value of[*******]). Header suppression can be controlled with thesetRedactedHeaders(Collection)method.- Parameters:
enabled-trueto enable debug logging,falseto disable it- See Also:
setRedactedHeaders(Collection),addRedactedHeader(String),getDebugLoggingEnabled()
-
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)
When debug logging is enabled, this method controls the suppression of header values in the logs.By default,
Authorizationheaders are redacted in the logs (printed with a value of[*******]).- Parameters:
headerNames- the names (case-insensitive) of the headers whose values will be redacted in the logs- See Also:
setDebugLogging(boolean)
-
addRedactedHeader
public static void addRedactedHeader(java.lang.String headerName)
When debug logging is enabled, this method adds a single header to the list of headers whose values will be redacted in the logs.By default,
Authorizationheaders are redacted in the logs (printed with a value of[*******]).- Parameters:
headerName- the name (case-insensitive) of the header whose value will be redacted in the logs- See Also:
setDebugLogging(boolean),setRedactedHeaders(Collection)
-
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
-
-