Klasse PathHandler

java.lang.Object
de.srsoftware.tools.PathHandler
Alle implementierten Schnittstellen:
HttpHandler

public abstract class PathHandler extends Object implements HttpHandler
implementation of HttpHandler that attaches to a given path
  • Felddetails

  • Konstruktordetails

    • PathHandler

      public PathHandler()
  • Methodendetails

    • badRequest

      public static boolean badRequest(HttpExchange ex, byte[] bytes) throws IOException
      create a response with status code 400, send payload
      Parameter:
      ex - the HttpExchange to write to
      bytes - the payload
      Gibt zurück:
      true – result is only created to allow return badRequest(…)
      Löst aus:
      IOException - if writing to the HttpEchange object fails
    • badRequest

      public static boolean badRequest(HttpExchange ex, Object o) throws IOException
      create a response with status code 400, send payload
      Parameter:
      ex - the HttpExchange to write to
      o - the payload
      Gibt zurück:
      true – result is only created to allow return badRequest(…)
      Löst aus:
      IOException - if writing to the HttpEchange object fails
    • bindPath

      public PathHandler.Bond bindPath(String... path)
      Bind the PathHandler object to one/several paths
      Parameter:
      path - the paths to bind to
      Gibt zurück:
      a bond, that can be used to create a context on a HttpServer
    • doDelete

      public boolean doDelete(String path, HttpExchange ex) throws IOException
      "not found" default implementation
      Parameter:
      path - ignored
      ex - HttpExchange used to return the not-implmented notification
      Gibt zurück:
      false
      Löst aus:
      IOException - if sending the response fails
    • doGet

      public boolean doGet(String path, HttpExchange ex) throws IOException
      "not found" default implementation
      Parameter:
      path - ignored
      ex - HttpExchange used to return the not-implmented notification
      Gibt zurück:
      false
      Löst aus:
      IOException - if sending the response fails
    • doPost

      public boolean doPost(String path, HttpExchange ex) throws IOException
      "not found" default implementation
      Parameter:
      path - ignored
      ex - HttpExchange used to return the not-implmented notification
      Gibt zurück:
      false
      Löst aus:
      IOException - if sending the response fails
    • handle

      public void handle(HttpExchange ex) throws IOException
      Angegeben von:
      handle in Schnittstelle HttpHandler
      Löst aus:
      IOException
    • relativePath

      public String relativePath(HttpExchange ex)
    • body

      public static String body(HttpExchange ex) throws IOException
      extracts the body of an HttpExchange
      Parameter:
      ex - the exchange to process
      Gibt zurück:
      the content of the HttpExchange
      Löst aus:
      IOException - if reading the body failed
    • getAuthToken

      public static Optional<String> getAuthToken(HttpExchange ex)
      extract the value of an Authorization header, if present
      Parameter:
      ex - the HttpExchange to extract from
      Gibt zurück:
      an optional, carrying the first value of an Authorization header, of present. empty, otherwise.
    • getBasicAuth

      public static Optional<PathHandler.BasicAuth> getBasicAuth(HttpExchange ex)
    • getBearer

      public static Optional<String> getBearer(HttpExchange ex)
    • getHeader

      public static Optional<String> getHeader(HttpExchange ex, String key)
    • hostname

      public static String hostname(HttpExchange ex)
    • json

      public static org.json.JSONObject json(HttpExchange ex) throws IOException
      Löst aus:
      IOException
    • language

      public static String language(HttpExchange ex)
    • notFound

      public static boolean notFound(HttpExchange ex) throws IOException
      Löst aus:
      IOException
    • queryParam

      public Map<String,String> queryParam(HttpExchange ex)
    • sendEmptyResponse

      public static boolean sendEmptyResponse(int statusCode, HttpExchange ex) throws IOException
      Löst aus:
      IOException
    • sendRedirect

      public static boolean sendRedirect(HttpExchange ex, String url) throws IOException
      Löst aus:
      IOException
    • sendContent

      public static boolean sendContent(HttpExchange ex, int status, byte[] bytes) throws IOException
      create a response given status code, send payload
      Parameter:
      ex - the HttpExchange to write to
      status - the status code
      bytes - the payload
      Gibt zurück:
      true – result is only created to allow return badRequest(…)
      Löst aus:
      IOException - if writing to the HttpEchange object fails
    • sendContent

      public static boolean sendContent(HttpExchange ex, int status, Object o) throws IOException
      create a response given status code, send payload
      Parameter:
      ex - the HttpExchange to write to
      status - the status code
      o - the payload
      Gibt zurück:
      true – result is only created to allow return badRequest(…)
      Löst aus:
      IOException - if writing to the HttpEchange object fails
    • sendContent

      public static boolean sendContent(HttpExchange ex, byte[] bytes) throws IOException
      Löst aus:
      IOException
    • sendContent

      public static boolean sendContent(HttpExchange ex, Object o) throws IOException
      Löst aus:
      IOException
    • serverError

      public static boolean serverError(HttpExchange ex, Object o) throws IOException
      create a "internal server error" response
      Parameter:
      ex - the HttpExchange object
      o - an additional payload
      Gibt zurück:
      false
      Löst aus:
      IOException - if the content cannot be sent
    • url

      public static String url(HttpExchange ex)
      recover the URL from an HttpExchange object
      Parameter:
      ex - the HttpExchange object
      Gibt zurück:
      the url of this object