Class ServerSettings

java.lang.Object
com.iizix.prop.GProp<GProp<?>[]>
com.iizix.prop.PropCnr
com.iizix.server.prop.ServerSettings
All Implemented Interfaces:
IServerSettings, EventListener, IGProp<GProp<?>[]>, IPropCnr, Cloneable
Direct Known Subclasses:
EditorServerSettings

public class ServerSettings extends PropCnr implements IServerSettings
This property is a container that holds the required settings for the server to operate and initialize itself with.
  • Field Details

    • CONFIG_FILE_EXT

      public static final String CONFIG_FILE_EXT
      The extension of the iiziServer configuration file: ".iiziServer".
      See Also:
    • CONFIG_FILE_DEFAULT_BASE_NAME

      public static final String CONFIG_FILE_DEFAULT_BASE_NAME
      Default base name without file extension of the iiziServer configuration file: "config".
      See Also:
    • CONFIG_FILE_DEFAULT_NAME

      public static final String CONFIG_FILE_DEFAULT_NAME
      Default name of the iiziServer configuration file: "config.iiziServer".
      See Also:
    • DEFAULT_SERVER_CONFIG_ENV

      public static final String DEFAULT_SERVER_CONFIG_ENV
      The default server configuration environment.
      See Also:
    • IDLE_TIMEOUT

      public static final String IDLE_TIMEOUT
      Timeout before a client session is disposed when it has not processes any transactions, default 2 hours. Range is 2 minutes to 2 days. The idle timeout includes dormant session timeout.
      See Also:
    • DORMANT_TIMEOUT

      public static final String DORMANT_TIMEOUT
      Timeout before an app session is disposed of when no more client sessions are present, default 10 minutes. Range is 30 seconds to 12 hours.
      See Also:
    • HEARTBEAT_INTERVAL

      public static final String HEARTBEAT_INTERVAL
      Heartbeat interval in seconds to keep communication link up, default 45 seconds. Range is 30 seconds to 5 minutes.
      See Also:
    • TRANS_CACHE_MIN

      public static final String TRANS_CACHE_MIN
      Property name of "minimum string length of a transactional cache".
      See Also:
    • TRANS_CACHE_MAX

      public static final String TRANS_CACHE_MAX
      Property name of "maximum string length of a transactional cache".
      See Also:
    • TRANS_CACHE_COUNT

      public static final String TRANS_CACHE_COUNT
      Property name of "count of strings in transactional cache".
      See Also:
    • REDIRECT_CODE_HTTP_to_HTTPS

      public static final String REDIRECT_CODE_HTTP_to_HTTPS
      The return code to use when web server receives HTTP requests to redirect to HTTPS. Can be 0 = no redirection, 301 = moved permanently, 302 = moved temporarily (default).
      See Also:
    • EXTERNAL_SERVER_URL

      public static final String EXTERNAL_SERVER_URL
      Property name for external server URL, including protocol and potential port number (if different from protocol port).

      This setting must be set if the retrieval of the local host name e.g. does not include the domain DNS suffix, or that the name is known on external nets differently than on the internal network. This host name is typically used for the OAuth 2.0 authentication callback URL's.

      See Also:
    • WS_LOG_DIR

      public static final String WS_LOG_DIR
      Property name for the logger directory for web server log files.
      See Also:
    • WS_LOG_RETAIN_DAYS

      public static final String WS_LOG_RETAIN_DAYS
      Property name for the number of days to retain web server log files.
      See Also:
    • WS_LOG_TIME_ZONE

      public static final String WS_LOG_TIME_ZONE
      Property name for the time zone ID for logging web server requests.
      See Also:
    • DIR_LIST

      public static final String DIR_LIST
      Property name for "directory listing allowed".
      See Also:
    • GZIP

      public static final String GZIP
      The Gzip boolean setting.
      See Also:
    • WS_IDLE_TIMEOUT

      public static final String WS_IDLE_TIMEOUT
      The web server maximum thread idle time settings.
      See Also:
    • WS_MAX_THREADS

      public static final String WS_MAX_THREADS
      The web server maximum number of threads setting.
      See Also:
    • WS_MIN_THREADS

      public static final String WS_MIN_THREADS
      The web server minimum number of threads setting.
      See Also:
    • WS_RESERVED_THREADS

      public static final String WS_RESERVED_THREADS
      The web server number of reserved threads setting.
      See Also:
    • REALM

      public static final String REALM
      The authentication realm.
      See Also:
    • REALM_PROPERTIES

      public static final String REALM_PROPERTIES
      The file name for authentication realm properties, default "authentication-realm-properties.txt" in the current directory of the server.
      See Also:
    • AUTH_BASIC

      public static final String AUTH_BASIC
      Authentication required: basic.
      See Also:
    • MAX_SERVER_KEY_AGE

      public static final String MAX_SERVER_KEY_AGE
      Maximum server key age in days: "maxServerKeyAge".
      See Also:
    • DEFAULT_MAX_SERVER_KEY_AGE

      public static final int DEFAULT_MAX_SERVER_KEY_AGE
      Default value for maximum server key age: 90 days.
      See Also:
    • FILE_PROVIDER_ROOT

      public static final String FILE_PROVIDER_ROOT
      Root directory relative the server's current directory where to place external files provided for remote usage over the web server.
      See Also:
    • DEFAULT_FILE_PROVIDER_ROOT

      public static final String DEFAULT_FILE_PROVIDER_ROOT
      The default directory for the file provider root.
      See Also:
    • URLBOX_IO_API_KEY

      public static final String URLBOX_IO_API_KEY
      The "urlbox.io" API key. You will find this key on your Dashboard when you login to "urlbox.io".
      See Also:
    • MAX_CONCURRENT_THUMBNAILS_COUNT

      public static final String MAX_CONCURRENT_THUMBNAILS_COUNT
      The maximum count of current thumbnail requests to "urlbox.io", default 10.

      Be careful not to exceed your quota, there are different plans available.

      See Also:
    • DEFAULT_MAX_CONCURRENT_THUMBNAILS_COUNT

      public static final int DEFAULT_MAX_CONCURRENT_THUMBNAILS_COUNT
      The default maximum count of current thumbnail requests to "urlbox.io", default 5.
      See Also:
    • MAX_HISTORY_LOCATION

      public static final String MAX_HISTORY_LOCATION
      The maximum history size for geolocation entries per user.
      See Also:
    • DEFAULT_MAX_HISTORY_LOCATION

      public static final int DEFAULT_MAX_HISTORY_LOCATION
      The default maximum history size for geolocation entries per user.
      See Also:
    • DB_AUTO_CREATE

      public static final String DB_AUTO_CREATE
      Database tables auto-creation flag, default true.
      See Also:
    • DB_DIRECTORY

      public static final String DB_DIRECTORY
      Database directory (local embedded Derby), default "db".
      See Also:
    • DB_HOST

      public static final String DB_HOST
      Database server host name or address (remote Derby).
      See Also:
    • DB_PORT

      public static final String DB_PORT
      Database server port number, default 1527.
      See Also:
    • DB_AUTO_START

      public static final String DB_AUTO_START
      Database server auto-start (Derby Database Server running on same machine), default true.
      See Also:
    • DB_MAX_FILE_COUNT

      public static final String DB_MAX_FILE_COUNT
      Maximum number of cached database files.
      See Also:
    • DEFAULT_DB_MAX_FILE_COUNT

      public static final int DEFAULT_DB_MAX_FILE_COUNT
      Default maximum number of cached database files: 10_000.
      See Also:
    • DB_MAX_FILE_AGE

      public static final String DB_MAX_FILE_AGE
      Maximum age of cached database files: milliseconds.
      See Also:
    • DEFAULT_DB_MAX_FILE_AGE

      public static final long DEFAULT_DB_MAX_FILE_AGE
      Default maximum age of cached database files: 90 days or 7_776_000_000 milliseconds.
      See Also:
    • LOGFILE_NAME

      public static final String LOGFILE_NAME
      Log file name.
      See Also:
    • DEFAULT_LOGFILE_NAME

      public static final String DEFAULT_LOGFILE_NAME
      Default log file name.
      See Also:
    • MAX_LOGFILE_SIZE

      public static final String MAX_LOGFILE_SIZE
      Max size of log file before new file.
      See Also:
    • DEFAULT_MAX_LOGFILE_SIZE

      public static final int DEFAULT_MAX_LOGFILE_SIZE
      Default max log file size in MB = 50 MB, undefined = unlimited (-1).
      See Also:
    • LOG_LEVEL

      public static final String LOG_LEVEL
      Log level.
      See Also:
    • DEFAULT_LOG_LEVEL

      public static final int DEFAULT_LOG_LEVEL
      Default log level = ILog.INFO.
      See Also:
    • LOG_TO_CONSOLE

      public static final String LOG_TO_CONSOLE
      Log to console.
      See Also:
    • LOG_HISTORY_SIZE

      public static final String LOG_HISTORY_SIZE
      The history size.
      See Also:
    • LOG_COMPRESS

      public static final String LOG_COMPRESS
      Old log compression: 0=none, 1=gzip (default), 2=xz.
      See Also:
    • DEFAULT_LOG_HISTORY_SIZE

      public static final int DEFAULT_LOG_HISTORY_SIZE
      Default history size = 500.
      See Also:
    • ALLOW_UPLOAD

      public static final String ALLOW_UPLOAD
      Flag to allow file upload, default false.
      See Also:
    • MAX_UPLOAD_SIZE

      public static final String MAX_UPLOAD_SIZE
      Maximum upload size in MB.
      See Also:
    • DEFAULT_MAX_UPLOAD_SIZE

      public static final int DEFAULT_MAX_UPLOAD_SIZE
      Default maximum upload size: 50 MB.
      See Also:
    • UPLOAD_DIRECTORY

      public static final String UPLOAD_DIRECTORY
      Directory name for file upload.
      See Also:
    • DEFAULT_UPLOAD_DIRECTORY

      public static final String DEFAULT_UPLOAD_DIRECTORY
      Default directory name for file upload = "uploads";
      See Also:
  • Constructor Details

    • ServerSettings

      public ServerSettings()
      Creates the server settings without a name. The name must be set in all cases using the setPropertyAtom call.
    • ServerSettings

      public ServerSettings(Atom atom)
      Creates the server settings with a name.
      Parameters:
      atom - The name of the property.
  • Method Details

    • addPredefinedProps

      protected void addPredefinedProps() throws PropException
      Adds the predefined containers for identifications, fields and actions. This method is overridden fully by the Editor versions of the class.
      Overrides:
      addPredefinedProps in class PropCnr
      Throws:
      PropException - for property exceptions.
    • clone

      public ServerSettings clone()
      Creates a clone out of this property. The cloning is overridden by the subclasses in order to handle cloning of its class variables appropriately.
      Overrides:
      clone in class PropCnr
    • getDescription

      public String getDescription()
      Gets the description of the Server.
      Specified by:
      getDescription in interface IServerSettings
      Returns:
      The description, "iiziServer" for default.
    • setDescription

      public boolean setDescription(String descr)
      Sets the description of the server.
      Parameters:
      descr - New server description, non-null.
      Throws:
      NullPointerException - if descr if null.
    • getLogFileName

      public String getLogFileName()
      Gets the log file name.
      Returns:
      The log file name, default "logs/server.log".
    • getMaximumLogFileSize

      public long getMaximumLogFileSize()
      Gets the maximum log file size.
      Returns:
      The maximum log file size, zero for no maximum.
    • getLogLevel

      public int getLogLevel()
      Gets the log level to use.
      Returns:
      The log level as defined in ILog, range is ILog.SEVERE to ILog.FINEST.
    • getLogToConsole

      public boolean getLogToConsole()
      Logging output also to console.
      Returns:
      true to write log to console as well as to log file, default true.
    • getLogHistorySize

      public int getLogHistorySize()
      Gets the history size for events kept in-memory for the server administration program to retrieve.
      Returns:
      The number of events, minimum 100, maximum 5000, default 500.
    • getAdministratorPasswordPolicy

      public PasswordPolicy getAdministratorPasswordPolicy()
      Gets the password policy for administrators.
      Returns:
      The password policy settings for administrators.
    • getUserPasswordPolicy

      public PasswordPolicy getUserPasswordPolicy()
      Gets the password policy for users.
      Returns:
      The password policy settings for normal users.
    • createPolicyProps

      protected PolicyProps createPolicyProps(Atom atom)
      Creates a policy property with the specified atom name.
      Parameters:
      atom - The atom name.
      Returns:
      The policy property.
    • getWSRedirectCodeHTTP_to_HTTPS

      public int getWSRedirectCodeHTTP_to_HTTPS()
      The return code to use when web server receives HTTP requests to redirect to HTTPS. Can be 0 = no redirection, 301 = moved permanently, 302 = moved temporarily (default).
      Specified by:
      getWSRedirectCodeHTTP_to_HTTPS in interface IServerSettings
      Returns:
      A return code of 0, 301 or 302.
    • setExternalHostName

      public boolean setExternalHostName(String extServerURL)
      Sets the external server URL, including protocol and potential port number (if different from protocol port).

      This setting must be set if the retrieval of the local host name e.g. does not include the domain DNS suffix, or that the name is known on external nets differently than on the internal network. This host name is typically used for the OAuth 2.0 authentication callback URL's.

      Parameters:
      extServerURL - The URL to use.
      Returns:
      true when this property container has been changed, false otherwise (or for error).
      Throws:
      NullPointerException - If extHostName is null.
      IllegalArgumentException - If extHostName is empty or not valid.
    • getExternalHostName

      public String getExternalHostName()
      Gets the external server URL, including protocol and potential port number (if different from protocol port).

      This setting must be set if the retrieval of the local host name e.g. does not include the domain DNS suffix, or that the name is known on external nets differently than on the internal network. This host name is typically used for the OAuth 2.0 authentication callback URL's.

      Returns:
      The URL, or null for none.
    • setRootDirectory

      public boolean setRootDirectory(String root) throws IOException
      Sets the root directory for external files. This call is done from a server instance when e.g. the command line overrides the default root in the settings.
      Parameters:
      root - The new root.
      Returns:
      true when this property container has been changed, false otherwise (or for error).
      Throws:
      IOException - If the directory does not exist.
    • getRootDirectory

      public String getRootDirectory()
      Gets the root directory for external files. If the directory doesn't exist it will be created.
      Specified by:
      getRootDirectory in interface IServerSettings
      Returns:
      The root directory or "./root" if none is specified. The return String is null if the directory cannot be created if not present, or the root is not a readable and writable directory. At the same time, logging will occur.
    • getWSLogDirectory

      public String getWSLogDirectory() throws IOException
      Gets the logger directory for web server log files. If the directory doesn't exist it will be created.
      Specified by:
      getWSLogDirectory in interface IServerSettings
      Returns:
      The root directory or "./logs/web" if none is specified. If the return code is null it is assumed no logging will be performed.
      Throws:
      IOException - In case the web server log directory is not valid or cannot be created.
    • getWSLogsRetainDays

      public int getWSLogsRetainDays()
      Gets the number of days to retain web server log files.
      Specified by:
      getWSLogsRetainDays in interface IServerSettings
      Returns:
      The default is 14, set to zero to disable logging.
    • getWSLogTimeZone

      public String getWSLogTimeZone()
      Gets the time zone ID for logging web server requests.
      Specified by:
      getWSLogTimeZone in interface IServerSettings
      Returns:
      The Time Zone ID, or GMT (default).
    • isDirectoryListingAllowed

      public boolean isDirectoryListingAllowed()
      Flag for directory listing allowed.
      Specified by:
      isDirectoryListingAllowed in interface IServerSettings
      Returns:
      The flag allowing directory listing of the web servers root and subdirectories, default false.
    • useGzip

      public boolean useGzip()
      Flag if Gzip compression should be used in the web server.
      Specified by:
      useGzip in interface IServerSettings
      Returns:
      true to enable Gzip (default), false otherwise.
    • getWSMaxThreads

      public int getWSMaxThreads()
      Get the web server maximum number of threads, default is 200. Range is 20 to 1024, always larger or equal to the minimum threads. An out-of-range value will give the default.
      Specified by:
      getWSMaxThreads in interface IServerSettings
      Returns:
      The maximum number of threads.
    • getWSMinThreads

      public int getWSMinThreads()
      Get the web server minimum number of threads, default is 8. Range is 20 to 1024, always smaller or equal to the minimum threads. An out-of-range value will give the default.
      Specified by:
      getWSMinThreads in interface IServerSettings
      Returns:
      Minimum number of threads.
    • getWSReservedThreads

      public int getWSReservedThreads()
      Get the web server number of reserved threads, default to -1. Range is 8-64, or -1 for heuristically determined. An out-of-range value will give the default -1.
      Specified by:
      getWSReservedThreads in interface IServerSettings
      Returns:
      Number of reserved threads or -1 for heuristically determined.
    • getWSIdleTimeout

      public int getWSIdleTimeout()
      Get the web server maximum thread idle time, default is 60 seconds, 60_000 milliseconds. Range is 5_000 (5 seconds) to 300_000 (5 minutes). An out-of-range value will give the default.
      Specified by:
      getWSIdleTimeout in interface IServerSettings
      Returns:
      Max idle time in ms.
    • getFileProviderRoot

      public String getFileProviderRoot()
      Gets the root directory relative the server's current directory where to place external files provided for remote usage over the web server.
      Returns:
      The root directory name, relative (or absolute path), "wsfiles" as default.
    • getRealmPropertiesFileName

      public String getRealmPropertiesFileName()
      Gets the file name for the authentication realm properties.
      Specified by:
      getRealmPropertiesFileName in interface IServerSettings
      Returns:
      The file name, or "authentication-realm-properties.txt" if undefined.
    • getAuthenticationRealm

      public String getAuthenticationRealm()
      Gets the realm for authentication.
      Specified by:
      getAuthenticationRealm in interface IServerSettings
      Returns:
      The realm string, "iiziServer Authentication" if not defined or empty String.
    • isBasicAuthenticationEnabled

      public boolean isBasicAuthenticationEnabled()
      Checks if basic authentication should be used.
      Specified by:
      isBasicAuthenticationEnabled in interface IServerSettings
      Returns:
      The flag for authentication enabled.
    • getUrlboxIOAPIKey

      public String getUrlboxIOAPIKey()
      Gets the "urlbox.io" API key.

      You will find this key on your Dashboard when you login to "urlbox.io".

      Returns:
      The configured API key, empty string for none.
    • getMaxConcurrentThumbnailsRequests

      public int getMaxConcurrentThumbnailsRequests()
      The maximum count of current thumbnail requests to "urlbox.io", default 5.

      Be careful not to exceed your quota, there are different plans available.

    • isFileUploadEnabled

      public boolean isFileUploadEnabled()
      Checks if file upload is enabled or not.
      Returns:
      The upload enablement flag, false by default.
    • getMaximumUploadFileSize

      public int getMaximumUploadFileSize()
      Returns the maximum size of any uploaded file in MB.
      Returns:
      The file size in MB, default 50 MB.
    • getFileUploadStagingDirectory

      public String getFileUploadStagingDirectory()
      Gets the upload directory where files are placed in a staging area.
      Returns:
      The directory name, relative the server's current directory.
    • getMaximumGeolocationHistorySizePerUser

      public int getMaximumGeolocationHistorySizePerUser()
      Gets the maximum number of geolocation entries per user in the history.
      Returns:
      The maximum number of locations, default 100, minimum 10, maximum 10000.
    • getClientIdleTimeout

      public long getClientIdleTimeout()
      Gets the timeout before a client session is disposed when it has not processes any transactions, default 2 hours. Range is 2 minutes to 2 days. The idle timeout includes dormant session timeout.
      Returns:
      Value in milliseconds.
    • getClientDormantTimeout

      public long getClientDormantTimeout()
      Timeout before an app session is disposed of when no more client sessions are present, default 10 minutes. Range is 30 seconds to 12 hours.
      Returns:
      Value in milliseconds.
    • getClientHeartBeatInterval

      public long getClientHeartBeatInterval()
      Heartbeat interval in seconds to keep communication link up, default 45 seconds. Range is 30 seconds to 5 minutes.
      Returns:
      Value in milliseconds (between 45_000L and 300_000L).
    • getMaximumServerKeyAge

      public int getMaximumServerKeyAge()
      Gets the maximum server key age in days.
      Returns:
      A value between 7 and 365 in days.
    • setCacheParams

      public void setCacheParams(int minLength, int maxLength, int count)
      Sets the parameters for cache: minLength, maxLength, count.
      Parameters:
      minLength - The minimum length for caching, 7 is the smallest value.
      maxLength - The maximum length for caching, normally 80 or so (maximum 1024).
      count - The count should normally be larger than 200 and smaller than 1000 (maximum 2048).
      Throws:
      IllegalArgumentException - If arguments are not valid.
    • getCacheParams

      public int[] getCacheParams()
      Gets the cache parameters as 3 integers in an array, param[0] is minLength, param[1] is maxLength, param[2] is count.

      The default values are minLength=7, maxLength=200, count=700 if nothing is specified.

      Specified by:
      getCacheParams in interface IServerSettings
      Returns:
      Array of 3 integer parameters, param[0] is minLength, param[1] is maxLength, param[2] is count.
    • getPortConfigurations

      public WebServerPortConfig[] getPortConfigurations()
      Gets the configured ports.
      Specified by:
      getPortConfigurations in interface IServerSettings
      Returns:
      The array of server port configurations.
    • getLetsEncryptDomains

      public LetsEncryptDomain[] getLetsEncryptDomains()
      Gets the Let's Encrypt domains.
      Returns:
      The array of Let's Encrypt domains.
    • getDefaultServerConfigurationEnvironmentName

      public String getDefaultServerConfigurationEnvironmentName()
      Gets the default Server configuration environment name.
      Returns:
      The defined default Server configuration environment name, or "default" if such definition is not done.
    • getServerConfigEnvironment

      public ServerConfigEnvProps getServerConfigEnvironment(String name)
      Gets the configuration environment of a name.
      Parameters:
      name - The name (e.g. "test", "development" or "production"), or null for default configuration environment name.
      Returns:
      The configuration setup, or null if not found.
    • getServerConfigEnvironments

      public ServerConfigEnvProps[] getServerConfigEnvironments()
      Gets the array of configuration environments present.
    • onServerSettingsChanged

      protected void onServerSettingsChanged()
      Called when loaded to update the ServerProps instance.
    • getDBCacheMaxFileCount

      public int getDBCacheMaxFileCount()
      Gets the maximum number of cached database files.
      Returns:
      Maximum number of files, minimum 100, default 10_000.
    • getDBCacheMaxFileAge

      public long getDBCacheMaxFileAge()
      Gets the maximum file age of cached database files.
      Returns:
      Maximum age in milliseconds of files: minimum 1 hour, default 90 days.
    • verify

      public boolean verify(PropVerification verification)
      Verifies this property container. The check performed is the extension of classes and that no circular reference is present.
      Specified by:
      verify in interface IGProp<GProp<?>[]>
      Overrides:
      verify in class PropCnr
      Parameters:
      verification - The property verification class.
      Returns:
      true if verification should proceed, false if disposed of and verification should not take place.
    • onApplicationLoad

      public void onApplicationLoad(AppFactory app) throws ServerApplicationSetupException
      Called when the application is loaded.
      Parameters:
      app - The application factory.
      Throws:
      ServerApplicationSetupException - For setup exceptions.
    • onApplicationUnload

      public void onApplicationUnload(AppFactory app)
      Called when the application is unloaded.
      Parameters:
      app - The application begin unloaded.
    • onApplicationSessionStarted

      public void onApplicationSessionStarted(AppSessionGyro appGyro)
      Called when an application is instantiated and started by a user session.
    • onApplicationSessionStopped

      public void onApplicationSessionStopped(AppSessionGyro appGyro)
      Called when an application is stopped.
    • getMailSender

      public MailSender getMailSender(String name, ExecutorService executorService, File baseDir) throws NotFoundException, AddressException, NoSuchProviderException, IOException
      Gets the mail sender with the specified name.
      Parameters:
      name - The mail properties name, null for default.
      executorService - The executor service.
      baseDir - The base directory where the server is (generally current directory).
      Returns:
      The mail sender.
      Throws:
      NotFoundException - If the mail sender is not found.
      IOException - If the mail queue directory does not exist.
      NoSuchProviderException - If the "smtp" or "smtps" providers do not exist!
      AddressException - If the default sender failed to parse.
    • getRegionLocationGlobalCacheSize

      public int getRegionLocationGlobalCacheSize()
      Gets the global cache size for the region location service providers.
      Returns:
      A value between 100 and 100_000, default is 20_000.
    • getRegionLocationAPIKey

      public String getRegionLocationAPIKey(String providerName)
      Gets the API key for a region location service provider.
      Parameters:
      providerName - The provider name, e.g. "IPStack.com".
      Returns:
      The API key, or null if not configured.