Class HttpTransport
java.lang.Object
codes.grow.packages.skywalking.core.HttpTransport
- All Implemented Interfaces:
AutoCloseable
The HTTP engine shared by every client of the SDK (SPEC section 2.3), built on
HttpClient.
Responsibilities: base URL join, query encoding, default headers and User-Agent, full
jitter retries with Retry-After, connect / per-attempt / total timeouts, cancellation,
hooks, logging and status-to-error mapping with redacted messages. Environment proxies are never
used; only TransportConfig.proxy().
send(codes.grow.packages.skywalking.core.TransportRequest) blocks; an interrupt of the calling thread aborts the call with CancelledException. sendAsync(codes.grow.packages.skywalking.core.TransportRequest) returns a future; cancelling it aborts the in-flight
attempt and any pending retry.
-
Field Summary
FieldsModifier and TypeFieldDescriptionResponse headers that carry a vendor request id, in lookup order. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SkyWalkingExceptionasSdkException(Throwable t, String operation) Converts any throwable from a future into the matching SDK exception.static <T> Tawait(CompletableFuture<T> future, String operation) Waits for a future of this SDK: an interrupt cancels the future and raisesCancelledException.voidclose()Cancels pending calls and releases the client.config()Returns the configuration.static StringerrorMessage(String operation, int status, Map<String, List<String>> headers, byte[] body, Collection<String> knownSecrets) Builds an error message"<operation>: <reason> (HTTP <status>)"with redacted, truncated vendor text.booleanisClosed()Returns whetherclose()was called.Resolves a request path and query against the base URL.send(TransportRequest request) Executes a request with retries and returns a 2xx (or accepted) response.sendAsync(TransportRequest request) Executes a request with retries asynchronously.com.fasterxml.jackson.databind.JsonNodesendJson(TransportRequest request) Convenience: sends a request and decodes the JSON body.
-
Field Details
-
REQUEST_ID_HEADERS
Response headers that carry a vendor request id, in lookup order.
-
-
Constructor Details
-
HttpTransport
Creates a transport.- Parameters:
config- transport settings- Throws:
ConfigException- when the base URL, proxy or TLS settings are invalid
-
-
Method Details
-
config
Returns the configuration.- Returns:
- the transport settings
-
isClosed
public boolean isClosed()Returns whetherclose()was called.- Returns:
- true once closed
-
resolve
Resolves a request path and query against the base URL.- Parameters:
path- path (leading slash optional) or absolute URLquery- query parameters- Returns:
- the full URL
-
send
Executes a request with retries and returns a 2xx (or accepted) response.An interrupt of the calling thread raises
CancelledException.- Parameters:
request- the request- Returns:
- the response
- Throws:
SkyWalkingException- mapped per SPEC section 2.1
-
await
Waits for a future of this SDK: an interrupt cancels the future and raisesCancelledException.Failures are unwrapped into
SkyWalkingException.- Type Parameters:
T- result type- Parameters:
future- the futureoperation- operation name for messages- Returns:
- the result
-
sendAsync
Executes a request with retries asynchronously. Cancelling the future aborts the call.- Parameters:
request- the request- Returns:
- a future with the response, failed with a mapped
SkyWalkingException
-
sendJson
Convenience: sends a request and decodes the JSON body.- Parameters:
request- the request- Returns:
- the JSON tree
-
asSdkException
Converts any throwable from a future into the matching SDK exception.- Parameters:
t- throwable (may be wrapped inCompletionException)operation- operation name for the message- Returns:
- the SDK exception
-
errorMessage
public static String errorMessage(String operation, int status, Map<String, List<String>> headers, byte[] body, Collection<String> knownSecrets) Builds an error message"<operation>: <reason> (HTTP <status>)"with redacted, truncated vendor text.- Parameters:
operation- operation namestatus- HTTP statusheaders- response headersbody- response body, may be nullknownSecrets- secret values to remove- Returns:
- the message
-
close
public void close()Cancels pending calls and releases the client. Idempotent; later calls raiseCancelledException.- Specified by:
closein interfaceAutoCloseable
-