Class TransportResponse

java.lang.Object
codes.grow.packages.skywalking.core.TransportResponse

public final class TransportResponse extends Object
A response returned by HttpTransport (2xx or an accepted status).
  • Constructor Details

    • TransportResponse

      public TransportResponse(int status, Map<String,List<String>> headers, byte[] body, int attempts, Duration duration, String operation)
      Creates a response (used by the transport and by tests).
      Parameters:
      status - HTTP status
      headers - response headers
      body - response body
      attempts - number of attempts made
      duration - total call duration
      operation - operation name for error messages
  • Method Details

    • status

      public int status()
      Returns the HTTP status.
      Returns:
      the status
    • headers

      public Map<String,List<String>> headers()
      Returns the response headers (case-insensitive keys).
      Returns:
      the headers
    • header

      public Optional<String> header(String name)
      Returns the first value of a header.
      Parameters:
      name - header name, case-insensitive
      Returns:
      the value, or empty
    • requestId

      public Optional<String> requestId()
      Returns the vendor request id header.
      Returns:
      the request id, or empty
    • body

      public byte[] body()
      Returns a copy of the body.
      Returns:
      the body bytes
    • text

      public String text()
      Returns the body decoded as UTF-8.
      Returns:
      the text
    • json

      public <T> T json(Class<T> type)
      Decodes the JSON body.
      Type Parameters:
      T - target type
      Parameters:
      type - target class
      Returns:
      the value
      Throws:
      ValidationException - when the body is not valid JSON for the type
    • json

      public <T> T json(com.fasterxml.jackson.core.type.TypeReference<T> type)
      Decodes the JSON body into a generic type.
      Type Parameters:
      T - target type
      Parameters:
      type - target type reference
      Returns:
      the value
      Throws:
      ValidationException - when the body is not valid JSON for the type
    • jsonNode

      public com.fasterxml.jackson.databind.JsonNode jsonNode()
      Parses the JSON body into a tree.
      Returns:
      the tree
      Throws:
      ValidationException - when the body is not valid JSON
    • attempts

      public int attempts()
      Returns the number of attempts the call needed.
      Returns:
      attempts, starting at 1
    • duration

      public Duration duration()
      Returns the call duration including retries.
      Returns:
      the duration
    • toString

      public String toString()
      Overrides:
      toString in class Object