Interface WebServer

All Superinterfaces:
RuntimeType.Api<WebServerConfig>

public interface WebServer extends RuntimeType.Api<WebServerConfig>
Server that opens server sockets and handles requests through routing.
  • Field Details

    • DEFAULT_SOCKET_NAME

      static final String DEFAULT_SOCKET_NAME
      The default server socket configuration name. All the default server socket configuration such as port(String) is accessible using this name. The value is "@default".
      See Also:
  • Method Details

    • create

      static WebServer create(WebServerConfig serverConfig)
      Create a new web server from its configuration.
      Parameters:
      serverConfig - configuration
      Returns:
      a new web server
    • create

      static WebServer create(Consumer<WebServerConfig.Builder> builderConsumer)
      Create a new webserver customizing its configuration.
      Parameters:
      builderConsumer - consumer of configuration builder
      Returns:
      a new web server
    • builder

      static WebServerConfig.Builder builder()
      A new builder to set up server.
      Returns:
      builder
    • start

      WebServer start()
      Starts the server. Has no effect if server is running. The start will fail on a server that is shut down, or that failed to start. In such cases, create a new instance of WebServer. If startup fails, all started channels are shut down before the failure is propagated. Additional cleanup failures may be attached as suppressed exceptions.
      Returns:
      a started server
      Throws:
      IllegalStateException - if startup or startup cleanup fails
    • stop

      WebServer stop()
      Attempt to gracefully shutdown the server. All channels are asked to stop even when one fails. If shutdown fails, the server is marked as stopped before the failure is propagated. Additional shutdown failures may be attached as suppressed exceptions.
      Returns:
      a stopped server
      Throws:
      RuntimeException - if shutdown cleanup fails
      See Also:
    • isRunning

      boolean isRunning()
      Returns true if the server is currently running. Running server in stopping phase returns true until it is not fully stopped.
      Returns:
      true if server is running
    • port

      default int port()
      Returns a port number the default server socket is bound to and is listening on; or -1 if unknown (i.e. Unix Domain Socket) or not active.

      It is supported only when server is running.

      Returns:
      a listen port; or -1 if unknown or the default server socket is not active
    • port

      int port(String socketName)
      Returns a port number an additional named server socket is bound to and is listening on; or -1 if unknown (i.e. Unix Domain Socket) or not active.
      Parameters:
      socketName - the name of an additional named server socket
      Returns:
      a listen port; or -1 if socket name is unknown or the server socket is not active
    • hasTls

      default boolean hasTls()
      Returns true if TLS is configured for the default socket.

      This is strictly a listener TLS configuration query. It does not report effective transport security and is not changed by bindings that provide their own TLS-equivalent protection.

      Returns:
      whether TLS is enabled for the default socket
    • context

      Context context()
      Context associated with the WebServer, used as a parent for listener contexts.
      Returns:
      a server context
    • hasTls

      boolean hasTls(String socketName)
      Returns true if TLS is configured for the named socket.

      This is strictly a listener TLS configuration query. It does not report effective transport security and is not changed by bindings that provide their own TLS-equivalent protection.

      Parameters:
      socketName - the name of a socket
      Returns:
      whether TLS is enabled for the socket, returns false if the socket does not exists
    • reloadTls

      @Deprecated(forRemoval=true, since="27.0.0") default void reloadTls(Tls tls)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Reload TLS keystore and truststore configuration for the default socket.
      Parameters:
      tls - new TLS configuration
    • reloadTls

      @Deprecated(forRemoval=true, since="27.0.0") void reloadTls(String socketName, Tls tls)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Reload TLS keystore and truststore configuration for the named socket.
      Parameters:
      socketName - socket name to reload TLS configuration on
      tls - new TLS configuration
    • reloadTls

      default void reloadTls(TlsMaterial material)
      Reload TLS key and trust material for the default socket.
      Parameters:
      material - new TLS material
    • reloadTls

      default void reloadTls(TlsMaterial material, String socketName)
      Reload TLS key and trust material for the named socket.
      Parameters:
      material - new TLS material
      socketName - socket name to reload TLS material on
    • reloadVirtualHostTls

      default void reloadVirtualHostTls(TlsMaterial material, String host)
      Reload TLS key and trust material for a virtual host configured on the default socket.
      Parameters:
      material - new TLS material
      host - configured virtual host name
    • reloadVirtualHostTls

      default void reloadVirtualHostTls(TlsMaterial material, String socketName, String host)
      Reload TLS key and trust material for a virtual host configured on the named socket.
      Parameters:
      material - new TLS material
      socketName - socket name containing the virtual host
      host - configured virtual host name