Class SimpleHttpsServer

java.lang.Object
com.sun.net.httpserver.HttpServer
com.sun.net.httpserver.HttpsServer
dev.katsute.simplehttpserver.SimpleHttpsServer

public abstract class SimpleHttpsServer extends com.sun.net.httpserver.HttpsServer
A HttpsServer with additional extensions to simplify usage. See SimpleHttpServer for setup documentation.
Since:
5.0.0
Version:
5.0.0
Author:
Katsute
See Also:
  • Method Details

    • create

      public static SimpleHttpsServer create() throws IOException
      Creates an unbounded https server.
      Returns:
      http server
      Throws:
      IOException - IO exception
      Since:
      5.0.0
      See Also:
    • create

      public static SimpleHttpsServer create(int port) throws IOException
      Creates an https server bounded to a port.
      Parameters:
      port - to bind to
      Returns:
      http server
      Throws:
      IOException - IO exception
      BindException - if server could not be bounded
      Since:
      5.0.0
      See Also:
    • create

      public static SimpleHttpsServer create(int port, int backlog) throws IOException
      Creates an https server bounded to a port.
      Parameters:
      port - to bind to
      backlog - maximum amount of inbound connections at any given time
      Returns:
      http server
      Throws:
      IOException - IO exception
      BindException - if server could not be bounded
      Since:
      5.0.0
      See Also:
    • getHttpsServer

      public abstract com.sun.net.httpserver.HttpsServer getHttpsServer()
      Returns the underlying http server.
      Returns:
      http server
      Since:
      5.0.0
      See Also:
      • HttpsServer
    • bind

      InetSocketAddress bind(int port) throws IOException
      Binds the server to a port.
      Parameters:
      port - port to bind to
      Returns:
      server address
      Throws:
      IOException - internal error
      BindException - if server could not be bounded
      Since:
      5.0.0
      See Also:
    • bind

      InetSocketAddress bind(int port, int backlog) throws IOException
      Binds the server to a port.
      Parameters:
      port - port to bind to
      backlog - maximum amount of inbound connections at any given time
      Returns:
      server address
      Throws:
      IOException - internal error
      BindException - if server could not be bounded
      Since:
      5.0.0
      See Also:
    • setSessionHandler

      void setSessionHandler(HttpSessionHandler sessionHandler)
      Sets as session handler to use for the server.
      Parameters:
      sessionHandler - session handler
      Since:
      5.0.0
      See Also:
    • getSessionHandler

      HttpSessionHandler getSessionHandler()
    • getSession

      HttpSession getSession(com.sun.net.httpserver.HttpExchange exchange)
      Returns the session for a given exchange.
      Parameters:
      exchange - http exchange
      Returns:
      session associated with an exchange
      Since:
      5.0.0
      See Also:
    • getContextHandler

      com.sun.net.httpserver.HttpHandler getContextHandler(String context)
      Returns the handler for a given context.
      Parameters:
      context - context
      Returns:
      handler for context
      Since:
      5.0.0
      See Also:
    • getContextHandler

      com.sun.net.httpserver.HttpHandler getContextHandler(com.sun.net.httpserver.HttpContext context)
      Returns the handler for a given context.
      Parameters:
      context - http context
      Returns:
      handler for context
      Since:
      5.0.0
      See Also:
    • getContexts

      Map<com.sun.net.httpserver.HttpContext,com.sun.net.httpserver.HttpHandler> getContexts()
      Returns a map of all the contexts registered to the server.
      Returns:
      map of contexts
      Since:
      5.0.0
      See Also:
    • getRandomContext

      String getRandomContext()
      Returns a random context that doesn't yet exist on the server.
      Returns:
      random unused context
      Since:
      5.0.0
      See Also:
    • getRandomContext

      String getRandomContext(String context)
      Returns a random context prefixed by a set context.
      Parameters:
      context - context to prefix
      Returns:
      random unused context with prefix
      Since:
      5.0.0
      See Also:
    • stop

      void stop()
      Stops the server immediately without waiting.
      Since:
      5.0.0
      See Also:
      • HttpServer.stop(int)