Class WebServer

  • All Implemented Interfaces:
    Service

    public class WebServer
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      WebServer()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String addSession​(java.sql.Connection conn)
      Create a session with a given connection.
      static java.lang.String encodeAdminPassword​(java.lang.String password)
      Generates a random salt and returns it with a hash of specified password with this salt.
      boolean getAllowOthers()
      Check if remote connections are allowed.
      java.util.ArrayList<java.lang.String> getCommandHistoryList()  
      java.lang.String getHost()  
      java.lang.String getName()
      Get the human readable name of the service.
      int getPort()
      Gets the port this service is listening on.
      java.lang.String getType()
      Get the human readable short name of the service.
      java.lang.String getURL()
      Get the URL of this service in a human readable form
      void init​(java.lang.String... args)
      Initialize the service from command line options.
      boolean isCommandHistoryAllowed()  
      boolean isDaemon()
      Check if a daemon thread should be used.
      boolean isRunning​(boolean traceError)
      Check if the service is running.
      boolean isStopped()  
      void listen()
      Listen for incoming connections.
      void saveCommandHistoryList​(java.util.ArrayList<java.lang.String> commandHistory)
      Save the command history to the properties file.
      void setAllowSecureCreation​(boolean allowSecureCreation)  
      void setCommandHistoryAllowed​(boolean allowed)  
      void setKey​(java.lang.String key)
      Sets the key for privileged connections.
      void setShutdownHandler​(ShutdownHandler shutdownHandler)  
      void start()
      Start the service.
      void stop()
      Stop the service.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WebServer

        public WebServer()
    • Method Detail

      • setKey

        public void setKey​(java.lang.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​(java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.util.ArrayList<java.lang.String> getCommandHistoryList()
      • saveCommandHistoryList

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

        public void setShutdownHandler​(ShutdownHandler shutdownHandler)
      • addSession

        public java.lang.String addSession​(java.sql.Connection conn)
                                    throws java.sql.SQLException
        Create a session with a given connection.
        Parameters:
        conn - the connection
        Returns:
        the URL of the web site to access this connection
        Throws:
        java.sql.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 java.lang.String encodeAdminPassword​(java.lang.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:
        java.lang.IllegalArgumentException - when password is too short