Class WebServer
java.lang.Object
org.h2.server.web.WebServer
- All Implemented Interfaces:
Service
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classThe translate thread reads and writes the file translation.properties once a second. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]private booleanprivate booleanprivate booleanprivate static final Stringprivate Stringprivate final HashMap<String, ConnectionInfo> private static final Stringprivate Stringprivate static final String[]private Stringprivate booleanprivate booleanprivate String(package private) static final String[][]private longprivate Threadprivate intprivate Stringprivate ServerSocketprivate static final longThe session timeout (the default is 30 minutes).private final HashMap<String, WebSession> private ShutdownHandlerprivate booleanprivate Stringprivate static intprivate booleanprivate WebServer.TranslateThreadprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSession(Connection conn) Create a session with a given connection.(package private) booleancheckAdminPassword(String password) Check the admin password.(package private) WebSessioncreateNewSession(String hostAddr) Create a new web session id and object.private static String(package private) byte[](package private) booleanbooleanCheck if remote connections are allowed.(package private) ConnectiongetConnection(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) StringgetKey()Returns the key for privileged connections.getName()Get the human readable name of the service.intgetPort()Gets the port this service is listening on.(package private) WebSessiongetSession(String sessionId) Get the web session object for the given session id.(package private) ConnectionInfogetSetting(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) booleangetSSL()(package private) StringgetType()Get the human readable short name of the service.getURL()Get the URL of this service in a human readable formvoidInitialize the service from command line options.booleanbooleanisDaemon()Check if a daemon thread should be used.booleanisRunning(boolean traceError) Check if the service is running.booleanvoidlisten()Listen for incoming connections.private Properties(package private) voidreadTranslations(WebSession session, String language) Read the translation for this language and save them in the 'text' property of this session.(package private) voidRemove this web thread from the set of running threads.(package private) voidremoveSetting(String name) Remove a connection information setting from the listvoidsaveCommandHistoryList(ArrayList<String> commandHistory) Save the command history to the properties file.(package private) voidsaveProperties(Properties prop) Save the settings to the properties file.(package private) voidsetAdminPassword(String password) (package private) voidsetAllowChunked(boolean allowChunked) (package private) voidsetAllowOthers(boolean b) voidsetAllowSecureCreation(boolean allowSecureCreation) voidsetCommandHistoryAllowed(boolean allowed) (package private) voidsetExternalNames(String externalNames) voidSets the key for privileged connections.(package private) voidsetPort(int port) voidsetShutdownHandler(ShutdownHandler shutdownHandler) (package private) voidsetSSL(boolean b) (package private) voidshutdown()Shut down the web server.voidstart()Start the service.(package private) StringstartTranslate(Map<Object, Object> translation) Start the translation thread that reads the file once a second.voidstop()Stop the service.(package private) booleansupportsLanguage(String language) Check if this language is supported / translated.(package private) voidWrite trace information if trace is enabled.(package private) voidWrite the stack trace if trace is enabled.(package private) voidupdateSetting(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
-
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
-
getURL
-
getHost
- Returns:
- host name
-
updateURL
private void updateURL() -
start
-
listen
-
isRunning
-
isStopped
public boolean isStopped() -
stop
-
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
-
getName
-
setAllowOthers
void setAllowOthers(boolean b) -
getAllowOthers
public boolean getAllowOthers()Description copied from interface:ServiceCheck if remote connections are allowed.- Specified by:
getAllowOthersin 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
-
isCommandHistoryAllowed
public boolean isCommandHistoryAllowed() -
setCommandHistoryAllowed
public void setCommandHistoryAllowed(boolean allowed) -
getCommandHistoryList
-
saveCommandHistoryList
-
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
-
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
-
isDaemon
-
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
-