Package org.h2.server.web

# 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 Summary

Constructors
Constructor
Description
`WebServer()`

## Method Summary

Modifier and Type
Method
Description
`String`
`addSession(Connection conn)`
Create a session with a given connection.
`static String`
`encodeAdminPassword(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.
`ArrayList<String>`
`getCommandHistoryList()`
`String`
`getHost()`
`String`
`getName()`
Get the human readable name of the service.
`int`
`getPort()`
Gets the port this service is listening on.
`String`
`getType()`
Get the human readable short name of the service.
`String`
`getURL()`
Get the URL of this service in a human readable form
`void`
`init(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(ArrayList<String> commandHistory)`
Save the command history to the properties file.
`void`
`setAllowSecureCreation(boolean allowSecureCreation)`
`void`
`setCommandHistoryAllowed(boolean allowed)`
`void`
`setKey(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 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