Package org.h2.server.web
Class WebServer
java.lang.Object
org.h2.server.web.WebServer
- All Implemented Interfaces:
Service
The web server is a simple standalone HTTP server that implements the H2
Console application. It is not optimized for performance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
The translate thread reads and writes the file translation.properties once a second. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
private boolean
private boolean
private boolean
private static final String
private String
private final HashMap
<String, ConnectionInfo> private static final String
private String
private static final String[]
private String
private boolean
private boolean
private String
(package private) static final String[][]
private long
private Thread
private int
private String
private ServerSocket
private static final long
The session timeout (the default is 30 minutes).private final HashMap
<String, WebSession> private ShutdownHandler
private boolean
private String
private static int
private boolean
private WebServer.TranslateThread
private String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSession
(Connection conn) Create a session with a given connection.(package private) boolean
checkAdminPassword
(String password) Check the admin password.(package private) WebSession
createNewSession
(String hostAddr) Create a new web session id and object.private static String
(package private) byte[]
(package private) boolean
boolean
Check if remote connections are allowed.(package private) Connection
getConnection
(String driver, String databaseUrl, String user, String password, String userKey, NetworkConnectionInfo networkConnectionInfo) Open a database connection.(package private) String
(package private) byte[]
Read the given file from the file system or from the resources.getHost()
(package private) String
getKey()
Returns the key for privileged connections.getName()
Get the human readable name of the service.int
getPort()
Gets the port this service is listening on.(package private) WebSession
getSession
(String sessionId) Get the web session object for the given session id.(package private) ConnectionInfo
getSetting
(String name) Get the connection information for this setting.(package private) String[]
Get the list of connection information setting names.(package private) ArrayList
<ConnectionInfo> Get the list of connection info objects.(package private) boolean
getSSL()
(package private) String
getType()
Get the human readable short name of the service.getURL()
Get the URL of this service in a human readable formvoid
Initialize the service from command line options.boolean
boolean
isDaemon()
Check if a daemon thread should be used.boolean
isRunning
(boolean traceError) Check if the service is running.boolean
void
listen()
Listen for incoming connections.private Properties
(package private) void
readTranslations
(WebSession session, String language) Read the translation for this language and save them in the 'text' property of this session.(package private) void
Remove this web thread from the set of running threads.(package private) void
removeSetting
(String name) Remove a connection information setting from the listvoid
saveCommandHistoryList
(ArrayList<String> commandHistory) Save the command history to the properties file.(package private) void
saveProperties
(Properties prop) Save the settings to the properties file.(package private) void
setAdminPassword
(String password) (package private) void
setAllowChunked
(boolean allowChunked) (package private) void
setAllowOthers
(boolean b) void
setAllowSecureCreation
(boolean allowSecureCreation) void
setCommandHistoryAllowed
(boolean allowed) (package private) void
setExternalNames
(String externalNames) void
Sets the key for privileged connections.(package private) void
setPort
(int port) void
setShutdownHandler
(ShutdownHandler shutdownHandler) (package private) void
setSSL
(boolean b) (package private) void
shutdown()
Shut down the web server.void
start()
Start the service.(package private) String
startTranslate
(Map<Object, Object> translation) Start the translation thread that reads the file once a second.void
stop()
Stop the service.(package private) boolean
supportsLanguage
(String language) Check if this language is supported / translated.(package private) void
Write trace information if trace is enabled.(package private) void
Write the stack trace if trace is enabled.(package private) void
updateSetting
(ConnectionInfo info) Update a connection information setting.private void
-
Field Details
-
LANGUAGES
-
COMMAND_HISTORY
- See Also:
-
DEFAULT_LANGUAGE
- See Also:
-
GENERIC
-
ticker
private static int ticker -
SESSION_TIMEOUT
private static final long SESSION_TIMEOUTThe session timeout (the default is 30 minutes). -
port
private int port -
allowOthers
private boolean allowOthers -
externalNames
-
isDaemon
private boolean isDaemon -
running
-
ssl
private boolean ssl -
adminPassword
private byte[] adminPassword -
connInfoMap
-
lastTimeoutCheck
private long lastTimeoutCheck -
sessions
-
languages
-
startDateTime
-
serverSocket
-
host
-
url
-
shutdownHandler
-
listenerThread
-
ifExists
private boolean ifExists -
key
-
allowSecureCreation
private boolean allowSecureCreation -
trace
private boolean trace -
translateThread
-
allowChunked
private boolean allowChunked -
serverPropertiesDir
-
commandHistoryString
-
-
Constructor Details
-
WebServer
public WebServer()
-
-
Method Details
-
getFile
Read the given file from the file system or from the resources.- Parameters:
file
- the file name- Returns:
- the data
- Throws:
IOException
- on failure
-
remove
Remove this web thread from the set of running threads.- Parameters:
t
- the thread to remove
-
generateSessionId
-
getSession
Get the web session object for the given session id.- Parameters:
sessionId
- the session id- Returns:
- the web session or null
-
createNewSession
Create a new web session id and object.- Parameters:
hostAddr
- the host address- Returns:
- the web session object
-
getStartDateTime
String getStartDateTime() -
getKey
String getKey()Returns the key for privileged connections.- Returns:
- key key, or null
-
setKey
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
Description copied from interface:Service
Initialize the service from command line options. -
getURL
Description copied from interface:Service
Get the URL of this service in a human readable form -
getHost
- Returns:
- host name
-
updateURL
private void updateURL() -
start
public void start()Description copied from interface:Service
Start the service. This usually means create the server socket. This method must not block. -
listen
public void listen()Description copied from interface:Service
Listen for incoming connections. This method blocks. -
isRunning
public boolean isRunning(boolean traceError) Description copied from interface:Service
Check if the service is running. -
isStopped
public boolean isStopped() -
stop
public void stop()Description copied from interface:Service
Stop the service. -
trace
Write trace information if trace is enabled.- Parameters:
s
- the message to write
-
traceError
Write the stack trace if trace is enabled.- Parameters:
e
- the exception
-
supportsLanguage
Check if this language is supported / translated.- Parameters:
language
- the language- Returns:
- true if a translation is available
-
readTranslations
Read the translation for this language and save them in the 'text' property of this session.- Parameters:
session
- the sessionlanguage
- the language
-
getSessions
-
getType
Description copied from interface:Service
Get the human readable short name of the service. -
getName
Description copied from interface:Service
Get the human readable name of the service. -
setAllowOthers
void setAllowOthers(boolean b) -
getAllowOthers
public boolean getAllowOthers()Description copied from interface:Service
Check if remote connections are allowed.- Specified by:
getAllowOthers
in interfaceService
- Returns:
- true if remote connections are allowed
-
setExternalNames
-
getExternalNames
String getExternalNames() -
setSSL
void setSSL(boolean b) -
setPort
void setPort(int port) -
getSSL
boolean getSSL() -
getPort
public int getPort()Description copied from interface:Service
Gets the port this service is listening on. -
isCommandHistoryAllowed
public boolean isCommandHistoryAllowed() -
setCommandHistoryAllowed
public void setCommandHistoryAllowed(boolean allowed) -
getCommandHistoryList
-
saveCommandHistoryList
Save the command history to the properties file.- Parameters:
commandHistory
- the history
-
getSetting
Get the connection information for this setting.- Parameters:
name
- the setting name- Returns:
- the connection information
-
updateSetting
Update a connection information setting.- Parameters:
info
- the connection information
-
removeSetting
Remove a connection information setting from the list- Parameters:
name
- the setting to remove
-
loadProperties
-
getSettingNames
String[] getSettingNames()Get the list of connection information setting names.- Returns:
- the connection info names
-
getSettings
ArrayList<ConnectionInfo> getSettings()Get the list of connection info objects.- Returns:
- the list
-
saveProperties
Save the settings to the properties file.- Parameters:
prop
- null or the properties webPort, webAllowOthers, and webSSL
-
getConnection
Connection getConnection(String driver, String databaseUrl, String user, String password, String userKey, NetworkConnectionInfo networkConnectionInfo) throws SQLException Open a database connection.- Parameters:
driver
- the driver class namedatabaseUrl
- the database URLuser
- the user namepassword
- the passworduserKey
- the key of privileged usernetworkConnectionInfo
- the network connection information- Returns:
- the database connection
- Throws:
SQLException
- on failure
-
shutdown
void shutdown()Shut down the web server. -
setShutdownHandler
-
addSession
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
-
startTranslate
Start the translation thread that reads the file once a second.- Parameters:
translation
- the translation map- Returns:
- the name of the file to translate
-
isDaemon
public boolean isDaemon()Description copied from interface:Service
Check if a daemon thread should be used. -
setAllowChunked
void setAllowChunked(boolean allowChunked) -
getAllowChunked
boolean getAllowChunked() -
getAdminPassword
byte[] getAdminPassword() -
setAdminPassword
-
checkAdminPassword
Check the admin password.- Parameters:
password
- the password to test- Returns:
- true if admin password not configure, or admin password correct
-