Class WebServerPortConfig

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

public class WebServerPortConfig extends PropCnr implements IWebServerPortConfig
Property container for the configuration of a Port "group" of the web server. A port configuration defines ONE port to use, the bind address and the protocol to bind to (HTTP or HTTPS); the old port range of the file format (port.start/port.end) is read as that one port and never written.
  • Field Details

    • PORT

      public static final String PORT
      The name of the port value.
      See Also:
    • PROTOCOL

      public static final String PROTOCOL
      The protocol to use (HTTP or HTTPS).
      See Also:
    • HTTP2

      public static final String HTTP2
      The name for the flag to use HTTP/2.
      See Also:
    • HTTP3

      public static final String HTTP3
      The name for the flag to use HTTP/3.
      See Also:
    • BIND_ADDRESS

      public static final String BIND_ADDRESS
      The name for the bind address string property.
      See Also:
    • FRONT_END_SECURED

      public static final String FRONT_END_SECURED
      If the port is secure by means of a front-end proxy, even if the server protocol uses HTTP.
      See Also:
    • EXTERNAL_HOST_NAME

      public static final String EXTERNAL_HOST_NAME
      Name for property for external host name or address when reverse-proxied.
      See Also:
    • UDP_PORT

      public static final String UDP_PORT
      The name of the UDP port value for HTTP/3.
      See Also:
    • EXTERNAL_PORT

      public static final String EXTERNAL_PORT
      The name of the port value when reverse-proxied.
      See Also:
    • ID_PKCS12

      public static final String ID_PKCS12
      The PKCS#12 identity.
      See Also:
    • ID_PASSWORD

      public static final String ID_PASSWORD
      The PKCS#12 identity password.
      See Also:
    • DOMAIN_NAMES

      public static final String DOMAIN_NAMES
      Domain names.
      See Also:
    • LETS_ENCRYPT_DOMAINS

      public static final String LETS_ENCRYPT_DOMAINS
      Domain names associated with Let's Encrypt, comma separated list.
      See Also:
    • DEFAULT_PASSWORD

      public static final String DEFAULT_PASSWORD
      The default password used for keystores, Let's Encrypt certificates, etc: "changeit".
      See Also:
    • EXCLUDE_TLS_VERSION

      public static final String EXCLUDE_TLS_VERSION
      Protocols to exclude: 0 = none, 1 = TLSv1.0, 2 = TLSv1.0 + 1.1.
      See Also:
    • NAME

      public static final String NAME
      The name of the port configuration (CC-FIX-APP-DEFINITIONS): what an application's ports list names. Unique among the server's port configurations and CASE-SENSITIVE, like every property name; trimmed, no comma, 1-64 characters. Absent or empty = the configuration's atom name, which is never renamed. Takes effect at the port's or the server's restart, as every other port setting.
      See Also:
    • MAX_NAME_LENGTH

      public static final int MAX_NAME_LENGTH
      The longest name of a port configuration.
      See Also:
  • Constructor Details

    • WebServerPortConfig

      public WebServerPortConfig()
      Creates the port configuration without a name. The name must be set in all cases using the setPropertyAtom call.
    • WebServerPortConfig

      public WebServerPortConfig(Atom atom)
      Creates the port configuration with a name.
      Parameters:
      atom - The name of the property.
  • Method Details

    • convertLoadedProp

      protected GProp<?> convertLoadedProp(GProp<?> childProp) throws PropException
      Enables conversion or omission of a property loaded from XML.

      This method is typically used to process changes of e.g. property types, e.g. from IntProp to NumberProp, in case of a change of property definitions.

      Overrides:
      convertLoadedProp in class PropCnr
      Parameters:
      childProp - The child property that is about to be added.
      Returns:
      The property to add, null to omit it. The default processing is to return the same property, i.e. childProp.
      Throws:
      PropException - for property errors.
    • getType

      public String getType()
      Gets the type of port: HTTP or HTTPS.
      Specified by:
      getType in interface IWebServerPortConfig
      Returns:
      The type string.
    • isFrontEndSecured

      public boolean isFrontEndSecured()
      Returns if the connection is secure by means of a front-end proxy, load balancer, etc. This means that the protocol can be HTTP but still be secure.
      Specified by:
      isFrontEndSecured in interface IWebServerPortConfig
      Returns:
      true if secure and HTTPS is used by the client side, false otherwise.
    • getDescription

      public String getDescription()
      Gets the description of the port configuration.
      Specified by:
      getDescription in interface IWebServerPortConfig
      Returns:
      The description, null for none.
    • getName

      public String getName()
      Gets the name of the port configuration: the NAME property trimmed, or the atom name when none is set.
      Specified by:
      getName in interface IWebServerPortConfig
      Returns:
      The name, never null nor empty.
    • isNamed

      public boolean isNamed()
      Checks if the port configuration has a name set, i.e. a non-empty NAME property, as opposed to the default of its atom name.
      Returns:
      true when a name is set.
    • getPortDescription

      public String getPortDescription()
      Gets the description of the port configuration.
      Specified by:
      getPortDescription in interface IWebServerPortConfig
      Returns:
      The description of the port configuration as [name: ]Port NNN, HTTP[S] [, bind address]...
    • clone

      public WebServerPortConfig 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
    • getPort

      public int getPort()
      Gets the (local) port.
      Specified by:
      getPort in interface IWebServerPortConfig
      Returns:
      The local port number. If the port is undefined, the default port for the local protocol is used, i.e. 80 for HTTP or 443 for HTTPS. The value is always between 1 and 65534, otherwise the default port value is returned.
    • useHTTP2

      public boolean useHTTP2()
      Use HTTP/2 alongside with HTTP/1.x. This setting is also valid for clear-text connections, i.e. non-TLS connections.
      Specified by:
      useHTTP2 in interface IWebServerPortConfig
      Returns:
      Enable HTTP/2 protocol flag, default true.
    • useHTTP3

      public boolean useHTTP3()
      Use HTTP/3 alongside with HTTP/2 and HTTP/1.x over secure TLS connections, requiring HTTP/2 also. HTTP/3 uses an UDP port and not a TCP port.
      Specified by:
      useHTTP3 in interface IWebServerPortConfig
      Returns:
      Enable HTTP/3 protocol flag, always false for clear-text connections.
    • getUDPPort

      public int getUDPPort()
      Retrieves the local UDP port number to use for HTTP/3 connections. The port may be set to another value than the HTTPS port used for HTTP/1.1 and HTTP/2. If not modified by configuration, this port will have the same number as the TCP port.
      Specified by:
      getUDPPort in interface IWebServerPortConfig
      Returns:
      The UDP port number for HTTP/3 connections.
    • getProtocol

      public int getProtocol()
      Gets the protocol to use.
      Specified by:
      getProtocol in interface IWebServerPortConfig
      Returns:
      The protocol: 0=HTTP (default), 1=HTTPS.
    • getBindAddress

      public String getBindAddress()
      Gets the bind address.
      Specified by:
      getBindAddress in interface IWebServerPortConfig
      Returns:
      The bind address, or null if not defined (never empty string).
    • getExternalHostName

      public String getExternalHostName()
      Gets the name for property for external host name or address when reverse-proxied.
      Specified by:
      getExternalHostName in interface IWebServerPortConfig
      Returns:
      The host name or IP address of the external access to the port when reverse-proxied, null for none, never empty string.
    • getExternalPort

      public int getExternalPort()
      Gets the external port when front-end proxied.
      Specified by:
      getExternalPort in interface IWebServerPortConfig
      Returns:
      The external port number (1-65534), or 0 if not defined.
    • getKeyStorePassword

      public String getKeyStorePassword()
      Gets the KeyStore password.
      Specified by:
      getKeyStorePassword in interface IWebServerPortConfig
      Returns:
      The password, null for none.
    • getKeyStore

      Gets the KeyStore from a PKCS#12 identity property and password.
      Specified by:
      getKeyStore in interface IWebServerPortConfig
      Returns:
      The configured KeyStore, or null if not defined.
      Throws:
      KeyStoreException - If no Provider supports a KeyStoreSpi implementation for the PKCS#12 type.
      NoSuchAlgorithmException - If the algorithm used to check the integrity of the KeyStore cannot be found.
      CertificateException - If any of the certificates in the KeyStore could not be loaded or the Let's Encrypt domain was not found and this configuration is associated with Let's Encrypt.
      IOException - If there is an I/O or format problem with the KeyStore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException.
      UnrecoverableEntryException - For errors in keystore.
    • getKeyStore

      Gets the KeyStore from a PKCS#12 identity property and password. If the configuration is associated with a Let's Encrypt domain
      Specified by:
      getKeyStore in interface IWebServerPortConfig
      Parameters:
      pwReturn - A StringBuilder instance that is filled with the password, null for none.
      Returns:
      The configured KeyStore, or null if not defined.
      Throws:
      KeyStoreException - If no Provider supports a KeyStoreSpi implementation for the PKCS#12 type.
      NoSuchAlgorithmException - If the algorithm used to check the integrity of the KeyStore cannot be found.
      CertificateException - If any of the certificates in the KeyStore could not be loaded or the Let's Encrypt domain was not found and this configuration is associated with Let's Encrypt.
      IOException - If there is an I/O or format problem with the KeyStore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException.
      UnrecoverableEntryException - For errors in keystore.
    • setProperty

      public <T> T setProperty(String name, T property, Class<T> propClass) throws ClassCastException
      Sets a runtime property based on a HashMap.
      Specified by:
      setProperty in interface IWebServerPortConfig
      Parameters:
      name - The property name.
      property - The property, or null to remove it.
      propClass - The class of the property to return if replaced.
      Returns:
      The previous property, null for none.
      Throws:
      ClassCastException - If the object is not null and is not assignable to the type T.
    • getProperty

      public <T> T getProperty(String name, Class<T> propClass) throws ClassCastException
      Gets a runtime property based on a HashMap.
      Specified by:
      getProperty in interface IWebServerPortConfig
      Parameters:
      name - The property name.
      propClass - The class of the property to return if replaced.
      Returns:
      The property, null if not previously set.
      Throws:
      ClassCastException - If the object is not null and is not assignable to the type T.
    • getDomainNames

      public String getDomainNames()
      Gets the Let's Encrypt domain name associated with this port configuration.
      Returns:
      The domain name as e.g. "hello.example.com", or null if not associated with Let's Encrypt.
    • getDomainNamesSet

      public Set<String> getDomainNamesSet()
      Gets the different domain names as String set. The domains names set includes all defined domain names that are configured for this port.
      Returns:
      A new set of domain names.
    • getLetsEncryptDomainNames

      public String getLetsEncryptDomainNames()
      Gets the Let's Encrypt domain name(s) associated with this port configuration.
      Specified by:
      getLetsEncryptDomainNames in interface IWebServerPortConfig
      Returns:
      The domain name(s) as e.g. "hello.example.com", or null if not associated with Let's Encrypt.
    • getLetsEncryptDomainNamesSet

      public Set<String> getLetsEncryptDomainNamesSet()
      Gets a new set of Let's Encrypt domain name(s) associated with this port configuration.
      Specified by:
      getLetsEncryptDomainNamesSet in interface IWebServerPortConfig
      Returns:
      The domain name(s) as e.g. "hello.example.com", or empty list if not associated with Let's Encrypt.
    • getLetsEncryptDomains

      public LetsEncryptDomain[] getLetsEncryptDomains()
      Gets the Let's Encrypt domain instances associated with this port configuration.
      Returns:
      The domain instance that are configured and found.
    • getLetsEncryptDomain

      public LetsEncryptDomain getLetsEncryptDomain(String domain)
      Gets the Let's Encrypt domain instance for a specific domain name.
      Parameters:
      domain - The domain name.
      Returns:
      The Let's encrypt domain for that name, null if not found.
    • setConfig

      public void setConfig(PortConfig config)
      Sets the Jetty server connector configuration used with this configuration.
      Specified by:
      setConfig in interface IWebServerPortConfig
      Parameters:
      config - The configuration instance.
    • restartConnector

      public void restartConnector()
      Restarts the Jetty (HTTPS) server connector after Let's Encrypt domain certificate renewal.
    • getController

      public IPortController getController()
      Gets the Jetty port controller.
      Returns:
      The port controller, or null if not initialized.
    • getExcludedSecureProtocols

      public String[] getExcludedSecureProtocols()
      Gets the excluded secure protocols.
      Specified by:
      getExcludedSecureProtocols in interface IWebServerPortConfig
      Returns:
      Empty string for none, otherwise e.g. "TLSv1", "TLSv1.1".
    • verify

      public boolean verify(PropVerification verification)
      Verifies this property container: the NAME rules - trimmed, no comma, at most MAX_NAME_LENGTH characters, and unique among the server's port configurations by effective name (NAME, else the atom name), case-sensitive.
      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.