Class Warning.Builder

java.lang.Object
org.apache.juneau.http.header.Warning.Builder
Enclosing class:
Warning

public static class Warning.Builder extends Object
Fluent builder for assembling an HTTP Warning header value.

Composes one or more warning-values defined by RFC 7234 ยง5.5 into the warn-code SP warn-agent SP warn-text [SP warn-date] form, with multiple warnings ,-separated. The 3-digit warn-code is zero-padded, the warn-text and optional warn-date are rendered as quoted-strings, and add(String) is a generic escape hatch for a fully pre-rendered warning-value.

Example:

String value = Warning.create() .warning(110, "anderson/1.3.37", "Response is stale") .build(); // => "110 anderson/1.3.37 \"Response is stale\""

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • warning

      public Warning.Builder warning(int code, String agent, String text)
      Adds a warning-value (without a warn-date).
      Parameters:
      code - The 3-digit warn-code. Must be in the range 0-999.
      agent - The warn-agent (host:port or pseudonym, e.g. "-"). Must not be null or blank.
      text - The human-readable warn-text. Must not be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If code is out of range or agent is null or blank.
    • warning

      public Warning.Builder warning(int code, String agent, String text, String date)
      Adds a warning-value with a warn-date.
      Parameters:
      code - The 3-digit warn-code. Must be in the range 0-999.
      agent - The warn-agent (host:port or pseudonym, e.g. "-"). Must not be null or blank.
      text - The human-readable warn-text. Must not be null.
      date - The warn-date (an HTTP-date). Must not be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If code is out of range or agent/date is invalid.
    • add

      public Warning.Builder add(String value)
      Generic escape hatch for adding a fully pre-rendered warning-value verbatim.
      Parameters:
      value - The pre-rendered warning-value. Must not be null or blank.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If value is null or blank.
    • build

      public String build()
      Builds the rendered Warning header value.

      Returns an empty string when no warnings have been registered.

      Returns:
      The header value. Never null.
    • toHeader

      public Warning toHeader()
      Builds a Warning header bean directly from this builder.
      Returns:
      A Warning carrying build(). Never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object