Class UpgradeRejection

java.lang.Object
com.ultikits.ultitools.utils.UpgradeRejection

final class UpgradeRejection extends Object
What the gateway said when it refused the agent socket's upgrade request (as of 6.3.1).

The refused responses (HTTP 426, 401, 429 and the plan-limit 402) carry {error:{code, message, requestId, details}}. Every field ends up on the server console, so every field is untrusted and is kept only when it passes its own check: code, reason and requestId keep [0-9A-Za-z._:-]{1,64}; minFramework keeps [0-9A-Za-z.+-]{1,32}; message loses control and format characters and colour codes and is cut to 200 characters; graceEndedAt keeps an ISO-8601 timestamp of at most 40 characters; manageUrl keeps an https:// URL on ultikits.com or one of its subdomains, at most 200 characters, without whitespace, control characters or user information. Anything else becomes null.

parse(int, java.util.Map<java.lang.String, java.lang.String>, java.lang.String) never throws: a missing, partial, malformed or oversized body yields a value that carries only the status (and the header-derived fields), and the status alone then decides what the connection does. As in the frozen contract 2.0.0 (PROTOCOL.md section 10, plan 22-20, S-63), every field is read from inside error only: a body without that wrapper is status-only, and the plan-limit fields of a 402 (reason, graceEndedAt, manageUrl) are read from error.details only, like the 426 details.

  • Field Details

    • MAX_BODY_CHARS

      static final int MAX_BODY_CHARS
      Largest body that is parsed; the draft never hands over a larger one.
      See Also:
    • TOKEN

      private static final Pattern TOKEN
    • VERSION

      private static final Pattern VERSION
    • TIMESTAMP

      private static final Pattern TIMESTAMP
    • DIGITS

      private static final Pattern DIGITS
    • ANSI_SEQUENCE

      private static final Pattern ANSI_SEQUENCE
    • MAX_TIMESTAMP_CHARS

      private static final int MAX_TIMESTAMP_CHARS
      See Also:
    • MAX_MESSAGE_CHARS

      private static final int MAX_MESSAGE_CHARS
      See Also:
    • MAX_URL_CHARS

      private static final int MAX_URL_CHARS
      See Also:
    • MAX_PROTOCOLS

      private static final int MAX_PROTOCOLS
      See Also:
    • MAX_PROTOCOL_VALUE

      private static final int MAX_PROTOCOL_VALUE
      See Also:
    • MANAGE_DOMAIN

      private static final String MANAGE_DOMAIN
      See Also:
    • HEADER_RETRY_AFTER

      private static final String HEADER_RETRY_AFTER
      See Also:
    • HEADER_PROTOCOL_SUPPORTED

      private static final String HEADER_PROTOCOL_SUPPORTED
      See Also:
    • status

      private final int status
    • code

      private final String code
    • message

      private final String message
    • requestId

      private final String requestId
    • minFramework

      private final String minFramework
    • supportedProtocols

      private final List<Integer> supportedProtocols
    • retryAfterSeconds

      private final long retryAfterSeconds
    • planReason

      private final String planReason
    • graceEndedAt

      private final String graceEndedAt
    • manageUrl

      private final String manageUrl
  • Constructor Details

  • Method Details

    • statusOnly

      static UpgradeRejection statusOnly(int status)
      A value carrying only the status.
      Parameters:
      status - the HTTP status of the upgrade response
      Returns:
      the value
    • parse

      static UpgradeRejection parse(int status, Map<String,String> headersLowerCase, String bodyOrNull)
      Parses a refused upgrade response. Never throws.
      Parameters:
      status - the HTTP status
      headersLowerCase - the response headers, names lower-cased; may be null
      bodyOrNull - the complete body, or null when it was absent, incomplete or too large
      Returns:
      the sanitised value
    • readBody

      private static void readBody(UpgradeRejection.Builder b, String body)
    • readHeaders

      private static void readHeaders(UpgradeRejection.Builder b, Map<String,String> headers)
    • retryAfter

      private static long retryAfter(String raw)
    • object

      private static com.google.gson.JsonObject object(com.google.gson.JsonObject parent, String name)
    • string

      private static String string(com.google.gson.JsonObject parent, String name)
    • protocols

      private static List<Integer> protocols(com.google.gson.JsonElement e)
    • protocolValue

      private static Integer protocolValue(String raw)
    • token

      private static String token(String raw)
    • version

      private static String version(String raw)
    • timestamp

      private static String timestamp(String raw)
    • message

      private static String message(String raw)
    • manageUrl

      private static String manageUrl(String raw)
    • status

      int status()
      Returns:
      the HTTP status of the refused upgrade
    • code

      String code()
      Returns:
      the error code, or null
    • message

      String message()
      Returns:
      the sanitised message, or null
    • requestId

      String requestId()
      Returns:
      the request id, or null
    • minFramework

      String minFramework()
      Returns:
      the minimum framework version the gateway accepts, or null
    • supportedProtocols

      List<Integer> supportedProtocols()
      Returns:
      the protocol versions the gateway supports; empty when absent
    • retryAfterSeconds

      long retryAfterSeconds()
      Returns:
      the Retry-After delta in seconds, clamped, or -1 when absent or not delta-seconds
    • planReason

      String planReason()
      Returns:
      the plan-limit reason, or null
    • graceEndedAt

      String graceEndedAt()
      Returns:
      when the plan-limit grace period ended, or null
    • manageUrl

      String manageUrl()
      Returns:
      the panel page where the owner manages the plan, or null
    • toString

      public String toString()
      Overrides:
      toString in class Object