Class TerminalEndpoints

java.lang.Object
org.apache.juneau.terminal.region.TerminalEndpoints

public final class TerminalEndpoints extends Object
Static helpers that implement the terminal endpoints and serve the terminal runtime.

TerminalMixin delegates to these; an application that wants its own paths writes @RestGet methods that call them and gets the same validation, cap and headers.

Bytes headers:
  • Term-Next: the offset to ask for next.
  • Term-End: the source's current end.
  • Term-Done: true once the producer is finished and the reader is at the end.
  • Term-Cols, Term-Rows: the producer's terminal size.
  • Term-Truncated: true when the bytes start later than from.
  • Term-Error: only ever gone, when the log disappeared.
  • Method Details

    • checkId

      public static String checkId(String id)
      Checks a terminal id against ^[A-Za-z0-9_-]{1,128}$.
      Parameters:
      id - The id from the URL path.
      Returns:
      The same id.
      Throws:
      BadRequest - If the id does not match.
    • bytes

      public static void bytes(Optional<TerminalSource> source, RestRequest req, RestResponse res) throws IOException
      Serves ?from=<offset>&max=<n> as raw bytes with the Term-* headers.

      Answers 404 for an empty source, 400 for a malformed from or max, 416 with Term-End when from is past the end, and otherwise 200. A from equal to the end is a 200 with no bytes.

      A gone source answers 200 with no bytes, Term-Done: true and Term-Error: gone, whatever from is. Its Term-Next and Term-End are from itself, so a client that keeps polling never rewinds; the chunk's own offsets are not consulted.

      Parameters:
      source - The resolved source; empty answers 404.
      req - The request.
      res - The response.
      Throws:
      IOException - If the source could not be read or the response written.
    • raw

      public static void raw(Optional<TerminalSource> source, String id, RestResponse res) throws IOException
      Serves every byte still held as an attachment named <id>.log.

      A gone source still answers 200 with an empty body, and carries Term-Error: gone as bytes does.

      The download is not capped and takes no range: it streams the whole log, TerminalSource.MAX_READ_BYTES at a time, up to the end at the time of the request. The id is checked here as well as by TerminalMixin, because it becomes the file name.

      Parameters:
      source - The resolved source; empty answers 404.
      id - The terminal id (also the download file name).
      res - The response.
      Throws:
      IOException - If the source could not be read or the response written.
    • script

      public static HttpResource script()
      The terminal runtime.
      Returns:
      juneau-terminal.js as a JavaScript HttpResource.
    • stylesheet

      public static HttpResource stylesheet()
      The terminal stylesheet.
      Returns:
      juneau-terminal.css as a CSS HttpResource.
    • terminalAssetUrl

      public static String terminalAssetUrl(RestRequest req, String path)
      Returns the absolute URL of a terminal asset, resolved against the request, with a ?v=<buildVersion>-<hash8> cache-buster.
      Parameters:
      req - The current request.
      path - TerminalMixin.JS_PATH or TerminalMixin.CSS_PATH.
      Returns:
      The asset URL.
      Throws:
      IllegalArgumentException - If this module does not ship the given path.