Class ServerBuilder
public final class ServerBuilder extends Object
Server
and its ServerConfig
.
Example
ServerBuilder sb = Server.builder();
// Add a port to listen
sb.http(8080);
// Add services to the default virtual host.
sb.service(...);
sb.serviceUnder(...);
// Build a server.
Server s = sb.build();
Example 2
ServerBuilder sb = Server.builder();
Server server =
sb.http(8080) // Add a port to listen
.defaultVirtualHost() // Add services to the default virtual host.
.service(...)
.serviceUnder(...)
.and().virtualHost("*.foo.com") // Add a another virtual host.
.service(...)
.serviceUnder(...)
.and().build(); // Build a server.
What happens if no HTTP(S) port is specified?
When no TCP/IP port number or local address is specified, ServerBuilder
will automatically bind
to a random TCP/IP port assigned by the OS. It will serve HTTPS if you configured TLS (or HTTP otherwise),
e.g.
// Build an HTTP server that runs on an ephemeral TCP/IP port.
Server httpServer = Server.builder()
.service(...)
.build();
// Build an HTTPS server that runs on an ephemeral TCP/IP port.
Server httpsServer = Server.builder()
.tls(...)
.service(...)
.build();
- See Also:
VirtualHostBuilder
-
Method Summary
Modifier and Type Method Description ServerBuilder
accessLogFormat(String accessLogFormat)
Sets the format of thisServer
's access log.ServerBuilder
accessLogger(String loggerName)
Sets the default access logger name for allVirtualHost
s.ServerBuilder
accessLogger(Function<? super VirtualHost,? extends Logger> mapper)
Sets the default access logger mapper for allVirtualHost
s.ServerBuilder
accessLogger(Logger logger)
Sets the default accessLogger
for allVirtualHost
s.ServerBuilder
accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
Sets an access log writer of thisServer
.AnnotatedServiceBindingBuilder
annotatedService()
Returns anAnnotatedServiceBindingBuilder
to build annotated service.ServerBuilder
annotatedService(Object service)
Binds the specified annotated service object under the path prefix"/"
.ServerBuilder
annotatedService(Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.ServerBuilder
annotatedService(Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.ServerBuilder
annotatedService(String pathPrefix, Object service)
Binds the specified annotated service object under the specified path prefix.ServerBuilder
annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.ServerBuilder
annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.ServerBuilder
annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.ServerBuilder
annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions, Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions)
Binds the specified annotated service object under the specified path prefix.ServerBuilder
annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.ServerBuilder
annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
Sets theRequestConverterFunction
s,ResponseConverterFunction
andExceptionHandlerFunction
s for creating anAnnotatedServiceExtensions
.ServerBuilder
blockingTaskExecutor(int numThreads)
Uses a newly createdBlockingTaskExecutor
with the specified number of threads dedicated to the execution of blocking tasks or invocations.ServerBuilder
blockingTaskExecutor(ScheduledExecutorService blockingTaskExecutor, boolean shutdownOnStop)
Sets theScheduledExecutorService
dedicated to the execution of blocking tasks or invocations.Server
build()
Returns a newly-createdServer
based on the configuration properties set so far.<T> ServerBuilder
channelOption(ChannelOption<T> option, T value)
Sets theChannelOption
of the server socket bound byServer
.<T> ServerBuilder
childChannelOption(ChannelOption<T> option, T value)
Sets theChannelOption
of sockets accepted byServer
.ServerBuilder
clientAddressFilter(Predicate<? super InetAddress> clientAddressFilter)
Sets a filter which evaluates whether anInetAddress
can be used as a client address.ServerBuilder
clientAddressMapper(Function<? super ProxiedAddresses,? extends InetSocketAddress> clientAddressMapper)
Sets aFunction
to use when determining the client address fromProxiedAddresses
.ServerBuilder
clientAddressSources(ClientAddressSource... clientAddressSources)
Sets a list ofClientAddressSource
s which are used to determine where to look for the client address, in the order of preference.ServerBuilder
clientAddressSources(Iterable<ClientAddressSource> clientAddressSources)
Sets a list ofClientAddressSource
s which are used to determine where to look for the client address, in the order of preference.ServerBuilder
clientAddressTrustedProxyFilter(Predicate<? super InetAddress> clientAddressTrustedProxyFilter)
Sets a filter which evaluates whether anInetAddress
of a remote endpoint is trusted.ServerBuilder
decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
.ServerBuilder
decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
DecoratesHttpService
s with the specifiedRoute
.ServerBuilder
decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)
DecoratesHttpService
s with the specifiedRoute
.ServerBuilder
decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
ServerBuilder
decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator)
ServerBuilder
decorator(Function<? super HttpService,? extends HttpService> decorator)
Decorates allHttpService
s with the specifieddecorator
.ServerBuilder
decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
DecoratesHttpService
s under the specified directory.ServerBuilder
decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)
DecoratesHttpService
s under the specified directory.ServerBuilder
defaultHostname(String defaultHostname)
Sets the default hostname of the defaultVirtualHostBuilder
.ServerBuilder
defaultServiceNaming(ServiceNaming defaultServiceNaming)
Sets a global naming rule for the name of services.VirtualHostBuilder
defaultVirtualHost()
Returns theVirtualHostBuilder
for building the default name-based virtual host.ServerBuilder
disableDateHeader()
Sets the response header not to include default"Date"
header.ServerBuilder
disableServerHeader()
Sets the response header not to include default"Server"
header.ServerBuilder
exceptionHandler(ExceptionHandler exceptionHandler)
ServerBuilder
gracefulShutdownTimeout(Duration quietPeriod, Duration timeout)
Sets the amount of time to wait after callingServer.stop()
for requests to go away before actually shutting down.ServerBuilder
gracefulShutdownTimeoutMillis(long quietPeriodMillis, long timeoutMillis)
Sets the amount of time to wait after callingServer.stop()
for requests to go away before actually shutting down.ServerBuilder
http(int port)
Adds an HTTP port that listens on all available network interfaces.ServerBuilder
http(InetSocketAddress localAddress)
Adds an HTTP port that listens to the specifiedlocalAddress
.ServerBuilder
http1MaxChunkSize(int http1MaxChunkSize)
Sets the maximum length of each chunk in an HTTP/1 response content.ServerBuilder
http1MaxHeaderSize(int http1MaxHeaderSize)
Sets the maximum length of all headers in an HTTP/1 response.ServerBuilder
http1MaxInitialLineLength(int http1MaxInitialLineLength)
Sets the maximum length of an HTTP/1 response initial line.ServerBuilder
http2InitialConnectionWindowSize(int http2InitialConnectionWindowSize)
Sets the initial connection-level HTTP/2 flow control window size.ServerBuilder
http2InitialStreamWindowSize(int http2InitialStreamWindowSize)
Sets the initial stream-level HTTP/2 flow control window size.ServerBuilder
http2MaxFrameSize(int http2MaxFrameSize)
Sets the maximum size of HTTP/2 frame that can be received.ServerBuilder
http2MaxHeaderListSize(long http2MaxHeaderListSize)
Sets the maximum size of headers that can be received.ServerBuilder
http2MaxStreamsPerConnection(long http2MaxStreamsPerConnection)
Sets the maximum number of concurrent streams per HTTP/2 connection.ServerBuilder
https(int port)
Adds an HTTPS port that listens on all available network interfaces.ServerBuilder
https(InetSocketAddress localAddress)
Adds an HTTPS port that listens to the specifiedlocalAddress
.ServerBuilder
idleTimeout(Duration idleTimeout)
Sets the idle timeout of a connection for keep-alive.ServerBuilder
idleTimeoutMillis(long idleTimeoutMillis)
Sets the idle timeout of a connection in milliseconds for keep-alive.ServerBuilder
localPort(int port, SessionProtocol... protocols)
Adds a newServerPort
that listens to the loopbacklocalAddress
using the specifiedSessionProtocol
s.ServerBuilder
localPort(int port, Iterable<SessionProtocol> protocols)
Adds a newServerPort
that listens to the loopbacklocalAddress
using the specifiedSessionProtocol
s.ServerBuilder
maxConnectionAge(Duration maxConnectionAge)
Sets the maximum allowed age of a connection for keep-alive.ServerBuilder
maxConnectionAgeMillis(long maxConnectionAgeMillis)
Sets the maximum allowed age of a connection in millis for keep-alive.ServerBuilder
maxNumConnections(int maxNumConnections)
Sets the maximum allowed number of open connections.ServerBuilder
maxNumRequestsPerConnection(int maxNumRequestsPerConnection)
Sets the maximum allowed number of requests that can be served through one connection.ServerBuilder
maxRequestLength(long maxRequestLength)
Sets the maximum allowed length of the content decoded at the session layer.ServerBuilder
meterRegistry(MeterRegistry meterRegistry)
Sets theMeterRegistry
that collects various stats.ServerBuilder
pingInterval(Duration pingInterval)
Sets the HTTP/2 PING interval.ServerBuilder
pingIntervalMillis(long pingIntervalMillis)
Sets the HTTP/2 PING interval.ServerBuilder
port(int port, SessionProtocol... protocols)
Adds a newServerPort
that listens to the specifiedport
of all available network interfaces using the specifiedSessionProtocol
s.ServerBuilder
port(int port, Iterable<SessionProtocol> protocols)
Adds a newServerPort
that listens to the specifiedport
of all available network interfaces using the specifiedSessionProtocol
s.ServerBuilder
port(ServerPort port)
Adds the specifiedServerPort
.ServerBuilder
port(InetSocketAddress localAddress, SessionProtocol... protocols)
Adds a newServerPort
that listens to the specifiedlocalAddress
using the specifiedSessionProtocol
s.ServerBuilder
port(InetSocketAddress localAddress, Iterable<SessionProtocol> protocols)
Adds a newServerPort
that listens to the specifiedlocalAddress
using the specifiedSessionProtocol
s.ServerBuilder
proxyProtocolMaxTlvSize(int proxyProtocolMaxTlvSize)
Sets the maximum size of additional data for PROXY protocol.ServerBuilder
rejectedRouteHandler(RejectedRouteHandler handler)
Sets theRejectedRouteHandler
which will be invoked when an attempt to bind anHttpService
at a certainRoute
is rejected.ServerBuilder
requestIdGenerator(Supplier<? extends RequestId> requestIdGenerator)
ServerBuilder
requestTimeout(Duration requestTimeout)
Sets the timeout of a request.ServerBuilder
requestTimeoutMillis(long requestTimeoutMillis)
Sets the timeout of a request in milliseconds.ServiceBindingBuilder
route()
Returns aServiceBindingBuilder
which is for binding anHttpService
fluently.DecoratingServiceBindingBuilder
routeDecorator()
Returns aDecoratingServiceBindingBuilder
which is for binding adecorator
fluently.ServerBuilder
serverListener(ServerListener serverListener)
Adds the specifiedServerListener
.ServerBuilder
service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)
Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.ServerBuilder
service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService,? extends HttpService>... decorators)
Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.ServerBuilder
service(Route route, HttpService service)
ServerBuilder
service(String pathPattern, HttpService service)
Binds the specifiedHttpService
at the specified path pattern of the defaultVirtualHost
.ServerBuilder
serviceUnder(String pathPrefix, HttpService service)
Binds the specifiedHttpService
under the specified directory of the defaultVirtualHost
.ServerBuilder
startStopExecutor(Executor startStopExecutor)
Sets theExecutor
which will invoke the callbacks ofServer.start()
,Server.stop()
andServerListener
.ServerBuilder
tls(File keyCertChainFile, File keyFile)
ServerBuilder
tls(File keyCertChainFile, File keyFile, String keyPassword)
ServerBuilder
tls(InputStream keyCertChainInputStream, InputStream keyInputStream)
Configures SSL or TLS of thisServer
with the specifiedkeyCertChainInputStream
and cleartextkeyInputStream
.ServerBuilder
tls(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Configures SSL or TLS of thisServer
with the specifiedkeyCertChainInputStream
,keyInputStream
andkeyPassword
.ServerBuilder
tls(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of thisServer
with the specified cleartextPrivateKey
andX509Certificate
chain.ServerBuilder
tls(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of thisServer
with the specifiedPrivateKey
,keyPassword
andX509Certificate
chain.ServerBuilder
tls(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Configures SSL or TLS of thisServer
with the specifiedPrivateKey
,keyPassword
andX509Certificate
chain.ServerBuilder
tls(PrivateKey key, X509Certificate... keyCertChain)
Configures SSL or TLS of thisServer
with the specified cleartextPrivateKey
andX509Certificate
chain.ServerBuilder
tls(KeyManagerFactory keyManagerFactory)
Configures SSL or TLS of thisServer
with the specifiedKeyManagerFactory
.ServerBuilder
tlsAllowUnsafeCiphers()
Deprecated.It's not recommended to enable this option.ServerBuilder
tlsAllowUnsafeCiphers(boolean tlsAllowUnsafeCiphers)
Deprecated.It's not recommended to enable this option.ServerBuilder
tlsCustomizer(Consumer<? super SslContextBuilder> tlsCustomizer)
Adds theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session.ServerBuilder
tlsSelfSigned()
Configures SSL or TLS of theServer
with an auto-generated self-signed certificate.ServerBuilder
tlsSelfSigned(boolean tlsSelfSigned)
Configures SSL or TLS of theServer
with an auto-generated self-signed certificate.String
toString()
ServerBuilder
verboseResponses(boolean verboseResponses)
Sets whether the verbose response mode is enabled.VirtualHostBuilder
virtualHost(String hostnamePattern)
Adds the name-based virtual host.VirtualHostBuilder
virtualHost(String defaultHostname, String hostnamePattern)
Adds the name-based virtual host.ServerBuilder
withDefaultVirtualHost(Consumer<? super VirtualHostBuilder> customizer)
Configures the defaultVirtualHost
with thecustomizer
.ServerBuilder
withRoute(Consumer<? super ServiceBindingBuilder> customizer)
ServerBuilder
withVirtualHost(Consumer<? super VirtualHostBuilder> customizer)
Configures aVirtualHost
with thecustomizer
.ServerBuilder
workerGroup(int numThreads)
Uses a newly createdEventLoopGroup
with the specified number of threads for performing socket I/O and runningService.serve(ServiceRequestContext, Request)
.ServerBuilder
workerGroup(EventLoopGroup workerGroup, boolean shutdownOnStop)
Sets the workerEventLoopGroup
which is responsible for performing socket I/O and runningService.serve(ServiceRequestContext, Request)
.
-
Method Details
-
http
Adds an HTTP port that listens on all available network interfaces.- Parameters:
port
- the HTTP port number.- See Also:
http(InetSocketAddress)
, What happens if no HTTP(S) port is specified?
-
http
Adds an HTTP port that listens to the specifiedlocalAddress
.- Parameters:
localAddress
- the local address to bind- See Also:
http(int)
, What happens if no HTTP(S) port is specified?
-
https
Adds an HTTPS port that listens on all available network interfaces.- Parameters:
port
- the HTTPS port number.- See Also:
https(InetSocketAddress)
, What happens if no HTTP(S) port is specified?
-
https
Adds an HTTPS port that listens to the specifiedlocalAddress
.- Parameters:
localAddress
- the local address to bind- See Also:
http(int)
, What happens if no HTTP(S) port is specified?
-
port
Adds a newServerPort
that listens to the specifiedport
of all available network interfaces using the specifiedSessionProtocol
s. Specify multiple protocols to serve more than one protocol on the same port:ServerBuilder sb = Server.builder(); // Serve both HTTP and HTTPS at port 8080. sb.port(8080, SessionProtocol.HTTP, SessionProtocol.HTTPS); // Enable HTTPS with PROXY protocol support at port 8443. sb.port(8443, SessionProtocol.PROXY, SessionProtocol.HTTPS);
-
port
Adds a newServerPort
that listens to the specifiedport
of all available network interfaces using the specifiedSessionProtocol
s. Specify multiple protocols to serve more than one protocol on the same port:ServerBuilder sb = Server.builder(); // Serve both HTTP and HTTPS at port 8080. sb.port(8080, Arrays.asList(SessionProtocol.HTTP, SessionProtocol.HTTPS)); // Enable HTTPS with PROXY protocol support at port 8443. sb.port(8443, Arrays.asList(SessionProtocol.PROXY, SessionProtocol.HTTPS));
-
port
Adds a newServerPort
that listens to the specifiedlocalAddress
using the specifiedSessionProtocol
s. Specify multiple protocols to serve more than one protocol on the same port:ServerBuilder sb = Server.builder(); // Serve both HTTP and HTTPS at port 8080. sb.port(new InetSocketAddress(8080), SessionProtocol.HTTP, SessionProtocol.HTTPS); // Enable HTTPS with PROXY protocol support at port 8443. sb.port(new InetSocketAddress(8443), SessionProtocol.PROXY, SessionProtocol.HTTPS);
-
port
Adds a newServerPort
that listens to the specifiedlocalAddress
using the specifiedSessionProtocol
s. Specify multiple protocols to serve more than one protocol on the same port:ServerBuilder sb = Server.builder(); // Serve both HTTP and HTTPS at port 8080. sb.port(new InetSocketAddress(8080), Arrays.asList(SessionProtocol.HTTP, SessionProtocol.HTTPS)); // Enable HTTPS with PROXY protocol support at port 8443. sb.port(new InetSocketAddress(8443), Arrays.asList(SessionProtocol.PROXY, SessionProtocol.HTTPS));
-
port
Adds the specifiedServerPort
. -
localPort
Adds a newServerPort
that listens to the loopbacklocalAddress
using the specifiedSessionProtocol
s. Specify multiple protocols to serve more than one protocol on the same port:ServerBuilder sb = Server.builder(); sb.localPort(8080, SessionProtocol.HTTP, SessionProtocol.HTTPS);
-
localPort
Adds a newServerPort
that listens to the loopbacklocalAddress
using the specifiedSessionProtocol
s. Specify multiple protocols to serve more than one protocol on the same port:ServerBuilder sb = Server.builder(); sb.localPort(8080, Arrays.asList(SessionProtocol.HTTP, SessionProtocol.HTTPS));
-
channelOption
Sets theChannelOption
of the server socket bound byServer
. Note that the previously added option will be overridden if the same option is set again.ServerBuilder sb = Server.builder(); sb.channelOption(ChannelOption.BACKLOG, 1024);
-
childChannelOption
Sets theChannelOption
of sockets accepted byServer
. Note that the previously added option will be overridden if the same option is set again.ServerBuilder sb = Server.builder(); sb.childChannelOption(ChannelOption.SO_REUSEADDR, true) .childChannelOption(ChannelOption.SO_KEEPALIVE, true);
-
workerGroup
Sets the workerEventLoopGroup
which is responsible for performing socket I/O and runningService.serve(ServiceRequestContext, Request)
. If not set, the common worker group is used.- Parameters:
shutdownOnStop
- whether to shut down the workerEventLoopGroup
when theServer
stops
-
workerGroup
Uses a newly createdEventLoopGroup
with the specified number of threads for performing socket I/O and runningService.serve(ServiceRequestContext, Request)
. The workerEventLoopGroup
will be shut down when theServer
stops.- Parameters:
numThreads
- the number of event loop threads
-
startStopExecutor
Sets theExecutor
which will invoke the callbacks ofServer.start()
,Server.stop()
andServerListener
. If not set,GlobalEventExecutor
will be used by default. -
maxNumConnections
Sets the maximum allowed number of open connections. -
idleTimeoutMillis
Sets the idle timeout of a connection in milliseconds for keep-alive.- Parameters:
idleTimeoutMillis
- the timeout in milliseconds.0
disables the timeout.
-
idleTimeout
Sets the idle timeout of a connection for keep-alive.- Parameters:
idleTimeout
- the timeout.0
disables the timeout.
-
pingIntervalMillis
Sets the HTTP/2 PING interval.Note that this settings is only in effect when
idleTimeoutMillis(long)
} oridleTimeout(Duration)
is greater than the specified PING interval.The minimum allowed PING interval is 1000L milliseconds.
0
means the server will not send PING frames on an HTTP/2 connection.- Throws:
IllegalArgumentException
- if the specifiedpingIntervalMillis
is smaller than 1000L milliseconds.
-
pingInterval
Sets the HTTP/2 PING interval.Note that this settings is only in effect when
idleTimeoutMillis(long)
} oridleTimeout(Duration)
is greater than the specified PING interval.The minimum allowed PING interval is 1000L milliseconds.
0
means the server will not send PING frames on an HTTP/2 connection.- Throws:
IllegalArgumentException
- if the specifiedpingInterval
is smaller than 1000L milliseconds.
-
maxConnectionAgeMillis
Sets the maximum allowed age of a connection in millis for keep-alive. A connection is disconnected after the specifiedmaxConnectionAgeMillis
since the connection was established. This option is disabled by default, which means unlimited.- Parameters:
maxConnectionAgeMillis
- the maximum connection age in millis.0
disables the limit.- Throws:
IllegalArgumentException
- if the specifiedmaxConnectionAgeMillis
is smaller than 1000L milliseconds.
-
maxConnectionAge
Sets the maximum allowed age of a connection for keep-alive. A connection is disconnected after the specifiedmaxConnectionAge
since the connection was established. This option is disabled by default, which means unlimited.- Parameters:
maxConnectionAge
- the maximum connection age.0
disables the limit.- Throws:
IllegalArgumentException
- if the specifiedmaxConnectionAge
is smaller than 1000L milliseconds.
-
maxNumRequestsPerConnection
Sets the maximum allowed number of requests that can be served through one connection. This option is disabled by default, which means unlimited.- Parameters:
maxNumRequestsPerConnection
- the maximum number of requests per connection.0
disables the limit.
-
http2InitialConnectionWindowSize
Sets the initial connection-level HTTP/2 flow control window size. Larger values can lower stream warmup time at the expense of being easier to overload the server. Defaults toFlags.defaultHttp2InitialConnectionWindowSize()
. Note that this setting affects the connection-level window size, not the window size of streams.- See Also:
http2InitialStreamWindowSize(int)
-
http2InitialStreamWindowSize
Sets the initial stream-level HTTP/2 flow control window size. Larger values can lower stream warmup time at the expense of being easier to overload the server. Defaults toFlags.defaultHttp2InitialStreamWindowSize()
. Note that this setting affects the stream-level window size, not the window size of connections.- See Also:
http2InitialConnectionWindowSize(int)
-
http2MaxStreamsPerConnection
Sets the maximum number of concurrent streams per HTTP/2 connection. Unset means there is no limit on the number of concurrent streams. Note, this differs frommaxNumConnections()
, which is the maximum number of HTTP/2 connections themselves, not the streams that are multiplexed over each. -
http2MaxFrameSize
Sets the maximum size of HTTP/2 frame that can be received. Defaults toFlags.defaultHttp2MaxFrameSize()
. -
http2MaxHeaderListSize
Sets the maximum size of headers that can be received. Defaults toFlags.defaultHttp2MaxHeaderListSize()
. -
http1MaxInitialLineLength
Sets the maximum length of an HTTP/1 response initial line. -
http1MaxHeaderSize
Sets the maximum length of all headers in an HTTP/1 response. -
http1MaxChunkSize
Sets the maximum length of each chunk in an HTTP/1 response content. The content or a chunk longer than this value will be split into smaller chunks so that their lengths never exceed it. -
gracefulShutdownTimeoutMillis
Sets the amount of time to wait after callingServer.stop()
for requests to go away before actually shutting down.- Parameters:
quietPeriodMillis
- the number of milliseconds to wait for active requests to go end before shutting down. 0 means the server will stop right away without waiting.timeoutMillis
- the number of milliseconds to wait before shutting down the server regardless of active requests. This should be set to a time greater thanquietPeriodMillis
to ensure the server shuts down even if there is a stuck request.
-
gracefulShutdownTimeout
Sets the amount of time to wait after callingServer.stop()
for requests to go away before actually shutting down.- Parameters:
quietPeriod
- the number of milliseconds to wait for active requests to go end before shutting down.Duration.ZERO
means the server will stop right away without waiting.timeout
- the amount of time to wait before shutting down the server regardless of active requests. This should be set to a time greater thanquietPeriod
to ensure the server shuts down even if there is a stuck request.
-
blockingTaskExecutor
public ServerBuilder blockingTaskExecutor(ScheduledExecutorService blockingTaskExecutor, boolean shutdownOnStop)Sets theScheduledExecutorService
dedicated to the execution of blocking tasks or invocations. If not set, the common pool is used.- Parameters:
shutdownOnStop
- whether to shut down theScheduledExecutorService
when theServer
stops
-
blockingTaskExecutor
Uses a newly createdBlockingTaskExecutor
with the specified number of threads dedicated to the execution of blocking tasks or invocations. TheBlockingTaskExecutor
will be shut down when theServer
stops.- Parameters:
numThreads
- the number of threads in the executor
-
meterRegistry
Sets theMeterRegistry
that collects various stats. -
defaultServiceNaming
Sets a global naming rule for the name of services. This property can be overridden viaVirtualHostBuilder.defaultServiceNaming(ServiceNaming)
. The overriding is also possible if service-level naming rule is set viaServiceBindingBuilder.defaultServiceNaming(ServiceNaming)
.- See Also:
RequestOnlyLog.serviceName()
-
accessLogFormat
Sets the format of thisServer
's access log. The specifiedaccessLogFormat
would be parsed byAccessLogWriter.custom(String)
. -
accessLogWriter
Sets an access log writer of thisServer
.AccessLogWriter.disabled()
is used by default.- Parameters:
shutdownOnStop
- whether to shut down theAccessLogWriter
when theServer
stops
-
proxyProtocolMaxTlvSize
Sets the maximum size of additional data for PROXY protocol. The default value of this property is 65319.Note: limiting TLV size only affects processing of v2, binary headers. Also, as allowed by the 1.5 spec, TLV data is currently ignored. For maximum performance, it would be best to configure your upstream proxy host to NOT send TLV data and set this property to
0
. -
tls
- See Also:
tlsCustomizer(Consumer)
-
tls
- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisServer
with the specifiedkeyCertChainInputStream
and cleartextkeyInputStream
.- See Also:
tlsCustomizer(Consumer)
-
tls
public ServerBuilder tls(InputStream keyCertChainInputStream, InputStream keyInputStream, @Nullable String keyPassword)Configures SSL or TLS of thisServer
with the specifiedkeyCertChainInputStream
,keyInputStream
andkeyPassword
.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisServer
with the specified cleartextPrivateKey
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisServer
with the specified cleartextPrivateKey
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
public ServerBuilder tls(PrivateKey key, @Nullable String keyPassword, X509Certificate... keyCertChain)Configures SSL or TLS of thisServer
with the specifiedPrivateKey
,keyPassword
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
public ServerBuilder tls(PrivateKey key, @Nullable String keyPassword, Iterable<? extends X509Certificate> keyCertChain)Configures SSL or TLS of thisServer
with the specifiedPrivateKey
,keyPassword
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisServer
with the specifiedKeyManagerFactory
.- See Also:
tlsCustomizer(Consumer)
-
tlsSelfSigned
Configures SSL or TLS of theServer
with an auto-generated self-signed certificate. Note: You should never use this in production but only for a testing purpose.- See Also:
tlsCustomizer(Consumer)
-
tlsSelfSigned
Configures SSL or TLS of theServer
with an auto-generated self-signed certificate. Note: You should never use this in production but only for a testing purpose.- See Also:
tlsCustomizer(Consumer)
-
tlsCustomizer
Adds theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session. -
tlsAllowUnsafeCiphers
Deprecated.It's not recommended to enable this option. Use it only when you have no other way to communicate with an insecure peer than this.Allows the bad cipher suites listed in RFC7540 for TLS handshake.Note that enabling this option increases the security risk of your connection. Use it only when you must communicate with a legacy system that does not support secure cipher suites. See Section 9.2.2, RFC7540 for more information. This option is disabled by default.
-
tlsAllowUnsafeCiphers
Deprecated.It's not recommended to enable this option. Use it only when you have no other way to communicate with an insecure peer than this.Allows the bad cipher suites listed in RFC7540 for TLS handshake.Note that enabling this option increases the security risk of your connection. Use it only when you must communicate with a legacy system that does not support secure cipher suites. See Section 9.2.2, RFC7540 for more information. This option is disabled by default.
- Parameters:
tlsAllowUnsafeCiphers
- Whether to allow the unsafe ciphers
-
withRoute
-
route
Returns aServiceBindingBuilder
which is for binding anHttpService
fluently. -
routeDecorator
Returns aDecoratingServiceBindingBuilder
which is for binding adecorator
fluently. The specified decorator(s) is/are executed in reverse order of the insertion. -
serviceUnder
Binds the specifiedHttpService
under the specified directory of the defaultVirtualHost
. -
service
Binds the specifiedHttpService
at the specified path pattern of the defaultVirtualHost
. e.g./login
(no path parameters)/users/{userId}
(curly-brace style)/list/:productType/by/:ordering
(colon style)exact:/foo/bar
(exact match)prefix:/files
(prefix match)glob:/~*/downloads/**
(glob pattern)regex:^/files/(?<filePath>.*)$
(regular expression)
- Throws:
IllegalArgumentException
- if the specified path pattern is invalid
-
service
-
service
public ServerBuilder service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.- Parameters:
serviceWithRoutes
- theHttpServiceWithRoutes
.decorators
- the decorator functions, which will be applied in the order specified.
-
service
@SafeVarargs public final ServerBuilder service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService,? extends HttpService>... decorators)Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.- Parameters:
serviceWithRoutes
- theHttpServiceWithRoutes
.decorators
- the decorator functions, which will be applied in the order specified.
-
annotatedService
Binds the specified annotated service object under the path prefix"/"
. -
annotatedService
Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ServerBuilder annotatedService(Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
Binds the specified annotated service object under the specified path prefix. -
annotatedService
public ServerBuilder annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ServerBuilder annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ServerBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ServerBuilder annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<?> exceptionHandlersAndConverters)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
, theRequestConverterFunction
and/or theResponseConverterFunction
-
annotatedService
public ServerBuilder annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions, Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlerFunctions
- theExceptionHandlerFunction
srequestConverterFunctions
- theRequestConverterFunction
sresponseConverterFunctions
- theResponseConverterFunction
s
-
annotatedService
Returns anAnnotatedServiceBindingBuilder
to build annotated service. -
serverListener
Adds the specifiedServerListener
. -
defaultHostname
Sets the default hostname of the defaultVirtualHostBuilder
. -
withDefaultVirtualHost
Configures the defaultVirtualHost
with thecustomizer
. -
defaultVirtualHost
Returns theVirtualHostBuilder
for building the default name-based virtual host. -
withVirtualHost
Configures aVirtualHost
with thecustomizer
. -
virtualHost
Adds the name-based virtual host.- Parameters:
hostnamePattern
- virtual host name regular expression- Returns:
VirtualHostBuilder
for building the virtual host
-
virtualHost
Adds the name-based virtual host.- Parameters:
defaultHostname
- default hostname of this virtual hosthostnamePattern
- virtual host name regular expression- Returns:
VirtualHostBuilder
for building the virtual host
-
decorator
Decorates allHttpService
s with the specifieddecorator
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decorator
- theFunction
that decoratesHttpService
s
-
decorator
Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decorator
public ServerBuilder decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpService
s whoseRoute
matches the specifiedpathPattern
. The specified decorator(s) is/are executed in reverse order of the insertion. -
decorator
public ServerBuilder decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpService
s whoseRoute
matches the specifiedpathPattern
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
.
-
decorator
public ServerBuilder decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpService
s with the specifiedRoute
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route
- the route being decorateddecorator
- theFunction
that decoratesHttpService
which matches the specifiedRoute
-
decorator
public ServerBuilder decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpService
s with the specifiedRoute
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route
- the route being decorateddecoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decoratorUnder
public ServerBuilder decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpService
s under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decoratorUnder
public ServerBuilder decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpService
s under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion. -
exceptionHandler
Sets theExceptionHandler
that converts aThrowable
to anAggregatedHttpResponse
.Note that the
HttpResponseException
is not handled by theExceptionHandler
but theHttpResponseException.httpResponse()
is sent as-is. -
clientAddressSources
Sets a list ofClientAddressSource
s which are used to determine where to look for the client address, in the order of preference.Forwarded
header,X-Forwarded-For
header and the source address of a PROXY protocol header will be used by default. -
clientAddressSources
Sets a list ofClientAddressSource
s which are used to determine where to look for the client address, in the order of preference.Forwarded
header,X-Forwarded-For
header and the source address of a PROXY protocol header will be used by default. -
clientAddressTrustedProxyFilter
public ServerBuilder clientAddressTrustedProxyFilter(Predicate<? super InetAddress> clientAddressTrustedProxyFilter)Sets a filter which evaluates whether anInetAddress
of a remote endpoint is trusted. -
clientAddressFilter
Sets a filter which evaluates whether anInetAddress
can be used as a client address. -
clientAddressMapper
public ServerBuilder clientAddressMapper(Function<? super ProxiedAddresses,? extends InetSocketAddress> clientAddressMapper)Sets aFunction
to use when determining the client address fromProxiedAddresses
. If not set, theProxiedAddresses.sourceAddress()
} is used as a client address. -
accessLogger
Sets the default access logger name for allVirtualHost
s. TheVirtualHost
s which do not have an access logger specified by aVirtualHostBuilder
will have the same accessLogger
named theloggerName
whenbuild()
is called. -
accessLogger
Sets the default accessLogger
for allVirtualHost
s. TheVirtualHost
s which do not have an access logger specified by aVirtualHostBuilder
will have the same accessLogger
whenbuild()
is called. -
accessLogger
Sets the default access logger mapper for allVirtualHost
s. TheVirtualHost
s which do not have an access logger specified by aVirtualHostBuilder
will have an access logger set by themapper
whenbuild()
is called. -
rejectedRouteHandler
Sets theRejectedRouteHandler
which will be invoked when an attempt to bind anHttpService
at a certainRoute
is rejected. By default, the duplicate routes are logged at WARN level. -
disableServerHeader
Sets the response header not to include default"Server"
header. -
disableDateHeader
Sets the response header not to include default"Date"
header. -
requestIdGenerator
Sets theSupplier
which generates aRequestId
. By default, aRequestId
is generated from a random 64-bit integer.- See Also:
RequestContext.id()
-
requestTimeout
Sets the timeout of a request.- Parameters:
requestTimeout
- the timeout.0
disables the timeout.
-
requestTimeoutMillis
Sets the timeout of a request in milliseconds.- Parameters:
requestTimeoutMillis
- the timeout in milliseconds.0
disables the timeout.
-
maxRequestLength
Sets the maximum allowed length of the content decoded at the session layer. e.g. the content length of an HTTP request.- Parameters:
maxRequestLength
- the maximum allowed length.0
disables the length limit.
-
verboseResponses
Sets whether the verbose response mode is enabled. When enabled, the server responses will contain the exception type and its full stack trace, which may be useful for debugging while potentially insecure. When disabled, the server responses will not expose such server-side details to the client. The default value of this property is retrieved fromFlags.verboseResponses()
. -
annotatedServiceExtensions
public ServerBuilder annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)Sets theRequestConverterFunction
s,ResponseConverterFunction
andExceptionHandlerFunction
s for creating anAnnotatedServiceExtensions
.- Parameters:
requestConverterFunctions
- theRequestConverterFunction
sresponseConverterFunctions
- theResponseConverterFunction
sexceptionHandlerFunctions
- theExceptionHandlerFunction
s
-
build
Returns a newly-createdServer
based on the configuration properties set so far. -
toString
-