Package org.h2.server.web
Class WebServer
- java.lang.Object
-
- org.h2.server.web.WebServer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classWebServer.TranslateThreadThe translate thread reads and writes the file translation.properties once a second.
-
Field Summary
Fields Modifier and Type Field Description private byte[]adminPasswordprivate booleanallowChunkedprivate booleanallowOthersprivate booleanallowSecureCreationprivate static java.lang.StringCOMMAND_HISTORYprivate java.lang.StringcommandHistoryStringprivate java.util.HashMap<java.lang.String,ConnectionInfo>connInfoMapprivate static java.lang.StringDEFAULT_LANGUAGEprivate java.lang.StringexternalNamesprivate static java.lang.String[]GENERICprivate java.lang.Stringhostprivate booleanifExistsprivate booleanisDaemonprivate java.lang.Stringkeyprivate java.util.HashSet<java.lang.String>languages(package private) static java.lang.String[][]LANGUAGESprivate longlastTimeoutCheckprivate java.lang.ThreadlistenerThreadprivate intportprivate java.util.Set<WebThread>runningprivate java.lang.StringserverPropertiesDirprivate java.net.ServerSocketserverSocketprivate static longSESSION_TIMEOUTThe session timeout (the default is 30 minutes).private java.util.HashMap<java.lang.String,WebSession>sessionsprivate ShutdownHandlershutdownHandlerprivate booleansslprivate java.lang.StringstartDateTimeprivate static inttickerprivate booleantraceprivate WebServer.TranslateThreadtranslateThreadprivate java.lang.Stringurl
-
Constructor Summary
Constructors Constructor Description WebServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringaddSession(java.sql.Connection conn)Create a session with a given connection.(package private) booleancheckAdminPassword(java.lang.String password)Check the admin password.(package private) WebSessioncreateNewSession(java.lang.String hostAddr)Create a new web session id and object.private static java.lang.StringgenerateSessionId()(package private) byte[]getAdminPassword()(package private) booleangetAllowChunked()booleangetAllowOthers()Check if remote connections are allowed.java.util.ArrayList<java.lang.String>getCommandHistoryList()(package private) java.sql.ConnectiongetConnection(java.lang.String driver, java.lang.String databaseUrl, java.lang.String user, java.lang.String password, java.lang.String userKey, NetworkConnectionInfo networkConnectionInfo)Open a database connection.(package private) java.lang.StringgetExternalNames()(package private) byte[]getFile(java.lang.String file)Read the given file from the file system or from the resources.java.lang.StringgetHost()(package private) java.lang.StringgetKey()Returns the key for privileged connections.java.lang.StringgetName()Get the human readable name of the service.intgetPort()Gets the port this service is listening on.(package private) WebSessiongetSession(java.lang.String sessionId)Get the web session object for the given session id.(package private) java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>>getSessions()(package private) ConnectionInfogetSetting(java.lang.String name)Get the connection information for this setting.(package private) java.lang.String[]getSettingNames()Get the list of connection information setting names.(package private) java.util.ArrayList<ConnectionInfo>getSettings()Get the list of connection info objects.(package private) booleangetSSL()(package private) java.lang.StringgetStartDateTime()java.lang.StringgetType()Get the human readable short name of the service.java.lang.StringgetURL()Get the URL of this service in a human readable formvoidinit(java.lang.String... args)Initialize the service from command line options.booleanisCommandHistoryAllowed()booleanisDaemon()Check if a daemon thread should be used.booleanisRunning(boolean traceError)Check if the service is running.booleanisStopped()voidlisten()Listen for incoming connections.private java.util.PropertiesloadProperties()(package private) voidreadTranslations(WebSession session, java.lang.String language)Read the translation for this language and save them in the 'text' property of this session.(package private) voidremove(WebThread t)Remove this web thread from the set of running threads.(package private) voidremoveSetting(java.lang.String name)Remove a connection information setting from the listvoidsaveCommandHistoryList(java.util.ArrayList<java.lang.String> commandHistory)Save the command history to the properties file.(package private) voidsaveProperties(java.util.Properties prop)Save the settings to the properties file.(package private) voidsetAdminPassword(java.lang.String password)(package private) voidsetAllowChunked(boolean allowChunked)(package private) voidsetAllowOthers(boolean b)voidsetAllowSecureCreation(boolean allowSecureCreation)voidsetCommandHistoryAllowed(boolean allowed)(package private) voidsetExternalNames(java.lang.String externalNames)voidsetKey(java.lang.String key)Sets 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) java.lang.StringstartTranslate(java.util.Map<java.lang.Object,java.lang.Object> translation)Start the translation thread that reads the file once a second.voidstop()Stop the service.(package private) booleansupportsLanguage(java.lang.String language)Check if this language is supported / translated.(package private) voidtrace(java.lang.String s)Write trace information if trace is enabled.(package private) voidtraceError(java.lang.Throwable e)Write the stack trace if trace is enabled.(package private) voidupdateSetting(ConnectionInfo info)Update a connection information setting.private voidupdateURL()
-
-
-
Field Detail
-
LANGUAGES
static final java.lang.String[][] LANGUAGES
-
COMMAND_HISTORY
private static final java.lang.String COMMAND_HISTORY
- See Also:
- Constant Field Values
-
DEFAULT_LANGUAGE
private static final java.lang.String DEFAULT_LANGUAGE
- See Also:
- Constant Field Values
-
GENERIC
private static final java.lang.String[] GENERIC
-
ticker
private static int ticker
-
SESSION_TIMEOUT
private static final long SESSION_TIMEOUT
The session timeout (the default is 30 minutes).
-
port
private int port
-
allowOthers
private boolean allowOthers
-
externalNames
private java.lang.String externalNames
-
isDaemon
private boolean isDaemon
-
running
private final java.util.Set<WebThread> running
-
ssl
private boolean ssl
-
adminPassword
private byte[] adminPassword
-
connInfoMap
private final java.util.HashMap<java.lang.String,ConnectionInfo> connInfoMap
-
lastTimeoutCheck
private long lastTimeoutCheck
-
sessions
private final java.util.HashMap<java.lang.String,WebSession> sessions
-
languages
private final java.util.HashSet<java.lang.String> languages
-
startDateTime
private java.lang.String startDateTime
-
serverSocket
private java.net.ServerSocket serverSocket
-
host
private java.lang.String host
-
url
private java.lang.String url
-
shutdownHandler
private ShutdownHandler shutdownHandler
-
listenerThread
private java.lang.Thread listenerThread
-
ifExists
private boolean ifExists
-
key
private java.lang.String key
-
allowSecureCreation
private boolean allowSecureCreation
-
trace
private boolean trace
-
translateThread
private WebServer.TranslateThread translateThread
-
allowChunked
private boolean allowChunked
-
serverPropertiesDir
private java.lang.String serverPropertiesDir
-
commandHistoryString
private java.lang.String commandHistoryString
-
-
Method Detail
-
getFile
byte[] getFile(java.lang.String file) throws java.io.IOExceptionRead the given file from the file system or from the resources.- Parameters:
file- the file name- Returns:
- the data
- Throws:
java.io.IOException- on failure
-
remove
void remove(WebThread t)
Remove this web thread from the set of running threads.- Parameters:
t- the thread to remove
-
generateSessionId
private static java.lang.String generateSessionId()
-
getSession
WebSession getSession(java.lang.String sessionId)
Get the web session object for the given session id.- Parameters:
sessionId- the session id- Returns:
- the web session or null
-
createNewSession
WebSession createNewSession(java.lang.String hostAddr)
Create a new web session id and object.- Parameters:
hostAddr- the host address- Returns:
- the web session object
-
getStartDateTime
java.lang.String getStartDateTime()
-
getKey
java.lang.String getKey()
Returns the key for privileged connections.- Returns:
- key key, or null
-
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:ServiceInitialize the service from command line options.
-
getURL
public java.lang.String getURL()
Description copied from interface:ServiceGet the URL of this service in a human readable form
-
getHost
public java.lang.String getHost()
- Returns:
- host name
-
updateURL
private void updateURL()
-
start
public void start()
Description copied from interface:ServiceStart the service. This usually means create the server socket. This method must not block.
-
listen
public void listen()
Description copied from interface:ServiceListen for incoming connections. This method blocks.
-
isRunning
public boolean isRunning(boolean traceError)
Description copied from interface:ServiceCheck if the service is running.
-
isStopped
public boolean isStopped()
-
stop
public void stop()
Description copied from interface:ServiceStop the service.
-
trace
void trace(java.lang.String s)
Write trace information if trace is enabled.- Parameters:
s- the message to write
-
traceError
void traceError(java.lang.Throwable e)
Write the stack trace if trace is enabled.- Parameters:
e- the exception
-
supportsLanguage
boolean supportsLanguage(java.lang.String language)
Check if this language is supported / translated.- Parameters:
language- the language- Returns:
- true if a translation is available
-
readTranslations
void readTranslations(WebSession session, java.lang.String language)
Read the translation for this language and save them in the 'text' property of this session.- Parameters:
session- the sessionlanguage- the language
-
getSessions
java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.Object>> getSessions()
-
getType
public java.lang.String getType()
Description copied from interface:ServiceGet the human readable short name of the service.
-
getName
public java.lang.String getName()
Description copied from interface:ServiceGet the human readable name of the service.
-
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
void setExternalNames(java.lang.String externalNames)
-
getExternalNames
java.lang.String getExternalNames()
-
setSSL
void setSSL(boolean b)
-
setPort
void setPort(int port)
-
getSSL
boolean getSSL()
-
getPort
public int getPort()
Description copied from interface:ServiceGets the port this service is listening on.
-
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
-
getSetting
ConnectionInfo getSetting(java.lang.String name)
Get the connection information for this setting.- Parameters:
name- the setting name- Returns:
- the connection information
-
updateSetting
void updateSetting(ConnectionInfo info)
Update a connection information setting.- Parameters:
info- the connection information
-
removeSetting
void removeSetting(java.lang.String name)
Remove a connection information setting from the list- Parameters:
name- the setting to remove
-
loadProperties
private java.util.Properties loadProperties()
-
getSettingNames
java.lang.String[] getSettingNames()
Get the list of connection information setting names.- Returns:
- the connection info names
-
getSettings
java.util.ArrayList<ConnectionInfo> getSettings()
Get the list of connection info objects.- Returns:
- the list
-
saveProperties
void saveProperties(java.util.Properties prop)
Save the settings to the properties file.- Parameters:
prop- null or the properties webPort, webAllowOthers, and webSSL
-
getConnection
java.sql.Connection getConnection(java.lang.String driver, java.lang.String databaseUrl, java.lang.String user, java.lang.String password, java.lang.String userKey, NetworkConnectionInfo networkConnectionInfo) throws java.sql.SQLExceptionOpen 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:
java.sql.SQLException- on failure
-
shutdown
void shutdown()
Shut down the web server.
-
setShutdownHandler
public void setShutdownHandler(ShutdownHandler shutdownHandler)
-
addSession
public java.lang.String addSession(java.sql.Connection conn) throws java.sql.SQLExceptionCreate 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
-
startTranslate
java.lang.String startTranslate(java.util.Map<java.lang.Object,java.lang.Object> translation)
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:ServiceCheck if a daemon thread should be used.
-
setAllowChunked
void setAllowChunked(boolean allowChunked)
-
getAllowChunked
boolean getAllowChunked()
-
getAdminPassword
byte[] getAdminPassword()
-
setAdminPassword
void setAdminPassword(java.lang.String password)
-
checkAdminPassword
boolean checkAdminPassword(java.lang.String password)
Check the admin password.- Parameters:
password- the password to test- Returns:
- true if admin password not configure, or admin password correct
-
-