Class WebServer

java.lang.Object
org.h2.server.web.WebServer
All Implemented Interfaces:
Service

public class WebServer extends Object implements Service
The web server is a simple standalone HTTP server that implements the H2 Console application. It is not optimized for performance.
  • Constructor Details

    • WebServer

      public WebServer()
  • Method Details

    • setKey

      public void setKey(String key)
      Sets the key for privileged connections.
      Parameters:
      key - key, or null
    • setAllowSecureCreation

      public void setAllowSecureCreation(boolean allowSecureCreation)
      Parameters:
      allowSecureCreation - whether creation of databases using the key should be allowed
    • init

      public void init(String... args)
      Description copied from interface: Service
      Initialize the service from command line options.
      Specified by:
      init in interface Service
      Parameters:
      args - the command line options
    • getURL

      public String getURL()
      Description copied from interface: Service
      Get the URL of this service in a human readable form
      Specified by:
      getURL in interface Service
      Returns:
      the url
    • getHost

      public String getHost()
      Returns:
      host name
    • start

      public void start()
      Description copied from interface: Service
      Start the service. This usually means create the server socket. This method must not block.
      Specified by:
      start in interface Service
    • listen

      public void listen()
      Description copied from interface: Service
      Listen for incoming connections. This method blocks.
      Specified by:
      listen in interface Service
    • isRunning

      public boolean isRunning(boolean traceError)
      Description copied from interface: Service
      Check if the service is running.
      Specified by:
      isRunning in interface Service
      Parameters:
      traceError - if errors should be written
      Returns:
      if the server is running
    • isStopped

      public boolean isStopped()
    • stop

      public void stop()
      Description copied from interface: Service
      Stop the service.
      Specified by:
      stop in interface Service
    • getType

      public String getType()
      Description copied from interface: Service
      Get the human readable short name of the service.
      Specified by:
      getType in interface Service
      Returns:
      the type
    • getName

      public String getName()
      Description copied from interface: Service
      Get the human readable name of the service.
      Specified by:
      getName in interface Service
      Returns:
      the name
    • getAllowOthers

      public boolean getAllowOthers()
      Description copied from interface: Service
      Check if remote connections are allowed.
      Specified by:
      getAllowOthers in interface Service
      Returns:
      true if remote connections are allowed
    • getPort

      public int getPort()
      Description copied from interface: Service
      Gets the port this service is listening on.
      Specified by:
      getPort in interface Service
      Returns:
      the port
    • isCommandHistoryAllowed

      public boolean isCommandHistoryAllowed()
    • setCommandHistoryAllowed

      public void setCommandHistoryAllowed(boolean allowed)
    • getCommandHistoryList

      public ArrayList<String> getCommandHistoryList()
    • saveCommandHistoryList

      public void saveCommandHistoryList(ArrayList<String> commandHistory)
      Save the command history to the properties file.
      Parameters:
      commandHistory - the history
    • setShutdownHandler

      public void setShutdownHandler(ShutdownHandler shutdownHandler)
    • addSession

      public String addSession(Connection conn) throws SQLException
      Create a session with a given connection.
      Parameters:
      conn - the connection
      Returns:
      the URL of the web site to access this connection
      Throws:
      SQLException - on failure
    • isDaemon

      public boolean isDaemon()
      Description copied from interface: Service
      Check if a daemon thread should be used.
      Specified by:
      isDaemon in interface Service
      Returns:
      true if a daemon thread should be used
    • encodeAdminPassword

      public static String encodeAdminPassword(String password)
      Generates a random salt and returns it with a hash of specified password with this salt.
      Parameters:
      password - the password
      Returns:
      a salt and hash of salted password as a hex encoded string to be used in configuration file
      Throws:
      IllegalArgumentException - when password is too short