Class HttpTransport

java.lang.Object
codes.grow.packages.skywalking.core.HttpTransport
All Implemented Interfaces:
AutoCloseable

public final class HttpTransport extends Object implements 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 Details

    • REQUEST_ID_HEADERS

      public static final List<String> REQUEST_ID_HEADERS
      Response headers that carry a vendor request id, in lookup order.
  • Constructor Details

    • HttpTransport

      public HttpTransport(TransportConfig config)
      Creates a transport.
      Parameters:
      config - transport settings
      Throws:
      ConfigException - when the base URL, proxy or TLS settings are invalid
  • Method Details

    • config

      public TransportConfig config()
      Returns the configuration.
      Returns:
      the transport settings
    • isClosed

      public boolean isClosed()
      Returns whether close() was called.
      Returns:
      true once closed
    • resolve

      public String resolve(String path, Map<String,List<String>> query)
      Resolves a request path and query against the base URL.
      Parameters:
      path - path (leading slash optional) or absolute URL
      query - query parameters
      Returns:
      the full URL
    • send

      public TransportResponse send(TransportRequest request)
      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

      public static <T> T await(CompletableFuture<T> future, String operation)
      Waits for a future of this SDK: an interrupt cancels the future and raises CancelledException.

      Failures are unwrapped into SkyWalkingException.

      Type Parameters:
      T - result type
      Parameters:
      future - the future
      operation - 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

      public com.fasterxml.jackson.databind.JsonNode sendJson(TransportRequest request)
      Convenience: sends a request and decodes the JSON body.
      Parameters:
      request - the request
      Returns:
      the JSON tree
    • asSdkException

      public static SkyWalkingException asSdkException(Throwable t, String operation)
      Converts any throwable from a future into the matching SDK exception.
      Parameters:
      t - throwable (may be wrapped in CompletionException)
      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 name
      status - HTTP status
      headers - response headers
      body - response body, may be null
      knownSecrets - secret values to remove
      Returns:
      the message
    • close

      public void close()
      Cancels pending calls and releases the client. Idempotent; later calls raise CancelledException.
      Specified by:
      close in interface AutoCloseable