Interface WebServer
- All Superinterfaces:
RuntimeType.Api<WebServerConfig>
Server that opens server sockets and handles requests through routing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default server socket configuration name. -
Method Summary
Modifier and TypeMethodDescriptionstatic WebServerConfig.Builderbuilder()A new builder to set up server.context()Context associated with theWebServer, used as a parent for listener contexts.static WebServercreate(WebServerConfig serverConfig) Create a new web server from its configuration.static WebServercreate(Consumer<WebServerConfig.Builder> builderConsumer) Create a new webserver customizing its configuration.default booleanhasTls()Returnstrueif TLS is configured for the default socket.booleanReturnstrueif TLS is configured for the named socket.booleanReturnstrueif the server is currently running.default intport()Returns a port number the default server socket is bound to and is listening on; or-1if unknown (i.e.intReturns a port number an additional named server socket is bound to and is listening on; or-1if unknown (i.e.default voidDeprecated, for removal: This API element is subject to removal in a future version.default voidreloadTls(TlsMaterial material) Reload TLS key and trust material for the default socket.default voidreloadTls(TlsMaterial material, String socketName) Reload TLS key and trust material for the named socket.voidDeprecated, for removal: This API element is subject to removal in a future version.default voidreloadVirtualHostTls(TlsMaterial material, String host) Reload TLS key and trust material for a virtual host configured on the default socket.default voidreloadVirtualHostTls(TlsMaterial material, String socketName, String host) Reload TLS key and trust material for a virtual host configured on the named socket.start()Starts the server.stop()Attempt to gracefully shutdown the server.Methods inherited from interface RuntimeType.Api
prototypeModifier and TypeMethodDescriptionThe prototype as it was received when creating this runtime object instance.
-
Field Details
-
DEFAULT_SOCKET_NAME
The default server socket configuration name. All the default server socket configuration such asport(String)is accessible using this name. The value is "@default".- See Also:
-
-
Method Details
-
create
Create a new web server from its configuration.- Parameters:
serverConfig- configuration- Returns:
- a new web server
-
create
Create a new webserver customizing its configuration.- Parameters:
builderConsumer- consumer of configuration builder- Returns:
- a new web server
-
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()Returnstrueif the server is currently running. Running server in stopping phase returnstrueuntil it is not fully stopped.- Returns:
trueif server is running
-
port
default int port()Returns a port number the default server socket is bound to and is listening on; or-1if unknown (i.e. Unix Domain Socket) or not active.It is supported only when server is running.
- Returns:
- a listen port; or
-1if unknown or the default server socket is not active
-
port
Returns a port number an additional named server socket is bound to and is listening on; or-1if unknown (i.e. Unix Domain Socket) or not active.- Parameters:
socketName- the name of an additional named server socket- Returns:
- a listen port; or
-1if socket name is unknown or the server socket is not active
-
hasTls
default boolean hasTls()Returnstrueif 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 theWebServer, used as a parent for listener contexts.- Returns:
- a server context
-
hasTls
Returnstrueif 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
falseif the socket does not exists
-
reloadTls
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, 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 ontls- new TLS configuration
-
reloadTls
Reload TLS key and trust material for the default socket.- Parameters:
material- new TLS material
-
reloadTls
Reload TLS key and trust material for the named socket.- Parameters:
material- new TLS materialsocketName- socket name to reload TLS material on
-
reloadVirtualHostTls
Reload TLS key and trust material for a virtual host configured on the default socket.- Parameters:
material- new TLS materialhost- configured virtual host name
-
reloadVirtualHostTls
Reload TLS key and trust material for a virtual host configured on the named socket.- Parameters:
material- new TLS materialsocketName- socket name containing the virtual hosthost- configured virtual host name
-
reloadTls(TlsMaterial)