public final class ServerBuilder extends Object
Server and its ServerConfig.
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();
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.
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();
VirtualHostBuilder| Constructor and Description |
|---|
ServerBuilder()
Deprecated.
Use
Server.builder(). |
| Modifier and Type | Method and Description |
|---|---|
ServerBuilder |
accessLogFormat(String accessLogFormat)
Sets the format of this
Server's access log. |
ServerBuilder |
accessLogger(Function<? super VirtualHost,? extends org.slf4j.Logger> mapper)
Sets the default access logger mapper for all
VirtualHosts. |
ServerBuilder |
accessLogger(org.slf4j.Logger logger)
Sets the default access
Logger for all VirtualHosts. |
ServerBuilder |
accessLogger(String loggerName)
Sets the default access logger name for all
VirtualHosts. |
ServerBuilder |
accessLogWriter(AccessLogWriter accessLogWriter,
boolean shutdownOnStop)
Sets an access log writer of this
Server. |
AnnotatedServiceBindingBuilder |
annotatedService()
Returns an
AnnotatedServiceBindingBuilder to build annotated service. |
ServerBuilder |
annotatedService(Object service)
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(Object service,
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,
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 |
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 |
annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions,
Iterable<? extends ResponseConverterFunction> responseConverterFunctions,
Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
Sets the
RequestConverterFunctions, ResponseConverterFunction
and ExceptionHandlerFunctions for creating an AnnotatedServiceExtensions. |
ServerBuilder |
blockingTaskExecutor(ScheduledExecutorService blockingTaskExecutor,
boolean shutdownOnStop)
Sets the
ScheduledExecutorService dedicated to the execution of blocking tasks or invocations. |
Server |
build()
Returns a newly-created
Server based on the configuration properties set so far. |
<T> ServerBuilder |
channelOption(io.netty.channel.ChannelOption<T> option,
T value)
Sets the
ChannelOption of the server socket bound by Server. |
<T> ServerBuilder |
childChannelOption(io.netty.channel.ChannelOption<T> option,
T value)
Sets the
ChannelOption of sockets accepted by Server. |
ServerBuilder |
clientAddressFilter(Predicate<? super InetAddress> clientAddressFilter)
Sets a filter which evaluates whether an
InetAddress can be used as a client address. |
ServerBuilder |
clientAddressMapper(Function<? super ProxiedAddresses,? extends InetSocketAddress> clientAddressMapper)
Sets a
Function to use when determining the client address from ProxiedAddresses. |
ServerBuilder |
clientAddressSources(ClientAddressSource... clientAddressSources)
Sets a list of
ClientAddressSources 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 of
ClientAddressSources 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 an
InetAddress of a remote endpoint is trusted. |
ServerBuilder |
decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Decorates all
HttpServices with the specified DecoratingHttpServiceFunction. |
ServerBuilder |
decorator(Function<? super HttpService,? extends HttpService> decorator)
Decorates all
HttpServices with the specified decorator. |
ServerBuilder |
decorator(Route route,
DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Decorates
HttpServices with the specified Route. |
ServerBuilder |
decorator(Route route,
Function<? super HttpService,? extends HttpService> decorator)
Decorates
HttpServices with the specified Route. |
ServerBuilder |
decorator(String pathPattern,
DecoratingHttpServiceFunction decoratingHttpServiceFunction)
|
ServerBuilder |
decorator(String pathPattern,
Function<? super HttpService,? extends HttpService> decorator)
|
ServerBuilder |
decoratorUnder(String prefix,
DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Decorates
HttpServices under the specified directory. |
ServerBuilder |
decoratorUnder(String prefix,
Function<? super HttpService,? extends HttpService> decorator)
Decorates
HttpServices under the specified directory. |
ServerBuilder |
defaultHostname(String defaultHostname)
Sets the default hostname of the default
VirtualHostBuilder. |
ServerBuilder |
defaultMaxRequestLength(long maxRequestLength)
Deprecated.
|
ServerBuilder |
defaultRequestTimeout(Duration requestTimeout)
Deprecated.
|
ServerBuilder |
defaultRequestTimeoutMillis(long requestTimeoutMillis)
Deprecated.
|
VirtualHostBuilder |
defaultVirtualHost()
Returns the
VirtualHostBuilder 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 |
gracefulShutdownTimeout(Duration quietPeriod,
Duration timeout)
Sets the amount of time to wait after calling
Server.stop() for
requests to go away before actually shutting down. |
ServerBuilder |
gracefulShutdownTimeout(long quietPeriodMillis,
long timeoutMillis)
Deprecated.
|
ServerBuilder |
gracefulShutdownTimeoutMillis(long quietPeriodMillis,
long timeoutMillis)
Sets the amount of time to wait after calling
Server.stop() for
requests to go away before actually shutting down. |
ServerBuilder |
http(InetSocketAddress localAddress)
Adds an HTTP port that listens to the specified
localAddress. |
ServerBuilder |
http(int port)
Adds an HTTP port that listens on all available network interfaces.
|
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(InetSocketAddress localAddress)
Adds an HTTPS port that listens to the specified
localAddress. |
ServerBuilder |
https(int port)
Adds an HTTPS port that listens on all available network interfaces.
|
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 |
maxNumConnections(int maxNumConnections)
Sets the maximum allowed number of open connections.
|
ServerBuilder |
maxRequestLength(long maxRequestLength)
Sets the maximum allowed length of the content decoded at the session layer.
|
ServerBuilder |
meterRegistry(MeterRegistry meterRegistry)
Sets the
MeterRegistry that collects various stats. |
ServerBuilder |
port(InetSocketAddress localAddress,
Iterable<SessionProtocol> protocols)
Adds a new
ServerPort that listens to the specified localAddress using the specified
SessionProtocols. |
ServerBuilder |
port(InetSocketAddress localAddress,
SessionProtocol... protocols)
Adds a new
ServerPort that listens to the specified localAddress using the specified
SessionProtocols. |
ServerBuilder |
port(InetSocketAddress localAddress,
String protocol)
Deprecated.
|
ServerBuilder |
port(int port,
Iterable<SessionProtocol> protocols)
Adds a new
ServerPort that listens to the specified port of all available network
interfaces using the specified SessionProtocols. |
ServerBuilder |
port(int port,
SessionProtocol... protocols)
Adds a new
ServerPort that listens to the specified port of all available network
interfaces using the specified SessionProtocols. |
ServerBuilder |
port(int port,
String protocol)
Deprecated.
Use
http(int) or https(int). |
ServerBuilder |
port(ServerPort port)
Adds the specified
ServerPort. |
ServerBuilder |
proxyProtocolMaxTlvSize(int proxyProtocolMaxTlvSize)
Sets the maximum size of additional data for PROXY protocol.
|
ServerBuilder |
rejectedRouteHandler(RejectedRouteHandler handler)
Sets the
RejectedRouteHandler which will be invoked when an attempt to bind
an HttpService at a certain Route 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 a
ServiceBindingBuilder which is for binding an HttpService fluently. |
DecoratingServiceBindingBuilder |
routeDecorator()
Returns a
DecoratingServiceBindingBuilder which is for binding a decorator fluently. |
ServerBuilder |
serverListener(ServerListener serverListener)
Adds the specified
ServerListener. |
ServerBuilder |
service(HttpServiceWithRoutes serviceWithRoutes,
Function<? super HttpService,? extends HttpService>... decorators)
Decorates and binds the specified
HttpServiceWithRoutes at multiple Routes
of the default VirtualHost. |
ServerBuilder |
service(HttpServiceWithRoutes serviceWithRoutes,
Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)
Decorates and binds the specified
HttpServiceWithRoutes at multiple Routes
of the default VirtualHost. |
ServerBuilder |
service(Route route,
HttpService service)
|
ServerBuilder |
service(String pathPattern,
HttpService service)
Binds the specified
HttpService at the specified path pattern of the default VirtualHost. |
ServerBuilder |
serviceAt(String pathPattern,
HttpService service)
Deprecated.
Use
service(String, HttpService) instead. |
ServerBuilder |
serviceUnder(String pathPrefix,
HttpService service)
Binds the specified
HttpService under the specified directory of the default VirtualHost. |
ServerBuilder |
startStopExecutor(Executor startStopExecutor)
Sets the
Executor which will invoke the callbacks of Server.start(),
Server.stop() and ServerListener. |
ServerBuilder |
tls(File keyCertChainFile,
File keyFile)
|
ServerBuilder |
tls(File keyCertChainFile,
File keyFile,
Consumer<io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Deprecated.
Use
tls(File, File) and tlsCustomizer(Consumer). |
ServerBuilder |
tls(File keyCertChainFile,
File keyFile,
String keyPassword)
|
ServerBuilder |
tls(File keyCertChainFile,
File keyFile,
String keyPassword,
Consumer<io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Deprecated.
|
ServerBuilder |
tls(InputStream keyCertChainInputStream,
InputStream keyInputStream)
Configures SSL or TLS of this
Server with the specified keyCertChainInputStream and
cleartext keyInputStream. |
ServerBuilder |
tls(InputStream keyCertChainInputStream,
InputStream keyInputStream,
String keyPassword)
Configures SSL or TLS of this
Server with the specified keyCertChainInputStream,
keyInputStream and keyPassword. |
ServerBuilder |
tls(KeyManagerFactory keyManagerFactory)
Configures SSL or TLS of this
Server with the specified KeyManagerFactory. |
ServerBuilder |
tls(KeyManagerFactory keyManagerFactory,
Consumer<io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Deprecated.
|
ServerBuilder |
tls(PrivateKey key,
Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of this
Server with the specified cleartext PrivateKey and
X509Certificate chain. |
ServerBuilder |
tls(PrivateKey key,
String keyPassword,
Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of this
Server with the specified PrivateKey, keyPassword
and X509Certificate chain. |
ServerBuilder |
tls(PrivateKey key,
String keyPassword,
X509Certificate... keyCertChain)
Configures SSL or TLS of this
Server with the specified PrivateKey, keyPassword
and X509Certificate chain. |
ServerBuilder |
tls(PrivateKey key,
X509Certificate... keyCertChain)
Configures SSL or TLS of this
Server with the specified cleartext PrivateKey and
X509Certificate chain. |
ServerBuilder |
tls(io.netty.handler.ssl.SslContext sslContext)
Deprecated.
This method has been deprecated because an incorrectly built
SslContext can cause
a Server to malfunction. Use other tls() methods. |
ServerBuilder |
tlsCustomizer(Consumer<? super io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Adds the
Consumer which can arbitrarily configure the SslContextBuilder that will be
applied to the SSL session. |
ServerBuilder |
tlsSelfSigned()
Configures SSL or TLS of the
Server with an auto-generated self-signed certificate. |
ServerBuilder |
tlsSelfSigned(boolean tlsSelfSigned)
Configures SSL or TLS of the
Server 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.
|
VirtualHostBuilder |
withDefaultVirtualHost()
Deprecated.
Use
defaultVirtualHost(). |
ServerBuilder |
withDefaultVirtualHost(Consumer<? super VirtualHostBuilder> customizer)
Configures the default
VirtualHost with the customizer. |
ServerBuilder |
withRoute(Consumer<? super ServiceBindingBuilder> customizer)
|
ServerBuilder |
withVirtualHost(Consumer<? super VirtualHostBuilder> customizer)
Configures a
VirtualHost with the customizer. |
VirtualHostBuilder |
withVirtualHost(String hostnamePattern)
Deprecated.
Use
virtualHost(String). |
VirtualHostBuilder |
withVirtualHost(String defaultHostname,
String hostnamePattern)
Deprecated.
|
ServerBuilder |
workerGroup(io.netty.channel.EventLoopGroup workerGroup,
boolean shutdownOnStop)
Sets the worker
EventLoopGroup which is responsible for performing socket I/O and running
Service.serve(ServiceRequestContext, Request). |
@Deprecated public ServerBuilder()
Server.builder().ServerBuilder.public ServerBuilder http(int port)
port - the HTTP port number.http(InetSocketAddress),
What happens if no HTTP(S) port is specified?public ServerBuilder http(InetSocketAddress localAddress)
localAddress.localAddress - the local address to bindhttp(int),
What happens if no HTTP(S) port is specified?public ServerBuilder https(int port)
port - the HTTPS port number.https(InetSocketAddress),
What happens if no HTTP(S) port is specified?public ServerBuilder https(InetSocketAddress localAddress)
localAddress.localAddress - the local address to bindhttp(int),
What happens if no HTTP(S) port is specified?@Deprecated public ServerBuilder port(int port, String protocol)
http(int) or https(int).ServerPort that listens to the specified port of all available network
interfaces using the specified protocol.public ServerBuilder port(int port, SessionProtocol... protocols)
ServerPort that listens to the specified port of all available network
interfaces using the specified SessionProtocols. 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);
public ServerBuilder port(int port, Iterable<SessionProtocol> protocols)
ServerPort that listens to the specified port of all available network
interfaces using the specified SessionProtocols. 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));
@Deprecated public ServerBuilder port(InetSocketAddress localAddress, String protocol)
http(InetSocketAddress) or https(InetSocketAddress).ServerPort that listens to the specified localAddress using the specified
protocol.public ServerBuilder port(InetSocketAddress localAddress, SessionProtocol... protocols)
ServerPort that listens to the specified localAddress using the specified
SessionProtocols. 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);
public ServerBuilder port(InetSocketAddress localAddress, Iterable<SessionProtocol> protocols)
ServerPort that listens to the specified localAddress using the specified
SessionProtocols. 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));
public ServerBuilder port(ServerPort port)
ServerPort.public <T> ServerBuilder channelOption(io.netty.channel.ChannelOption<T> option, T value)
ChannelOption of the server socket bound by Server.
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);
public <T> ServerBuilder childChannelOption(io.netty.channel.ChannelOption<T> option, T value)
ChannelOption of sockets accepted by Server.
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);
public ServerBuilder workerGroup(io.netty.channel.EventLoopGroup workerGroup, boolean shutdownOnStop)
EventLoopGroup which is responsible for performing socket I/O and running
Service.serve(ServiceRequestContext, Request).
If not set, the common worker group is used.shutdownOnStop - whether to shut down the worker EventLoopGroup
when the Server stopspublic ServerBuilder startStopExecutor(Executor startStopExecutor)
Executor which will invoke the callbacks of Server.start(),
Server.stop() and ServerListener. If not set, GlobalEventExecutor will be used
by default.public ServerBuilder maxNumConnections(int maxNumConnections)
public ServerBuilder idleTimeoutMillis(long idleTimeoutMillis)
idleTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.public ServerBuilder idleTimeout(Duration idleTimeout)
idleTimeout - the timeout. 0 disables the timeout.public ServerBuilder http2InitialConnectionWindowSize(int http2InitialConnectionWindowSize)
Flags.defaultHttp2InitialConnectionWindowSize().
Note that this setting affects the connection-level window size, not the window size of streams.http2InitialStreamWindowSize(int)public ServerBuilder http2InitialStreamWindowSize(int http2InitialStreamWindowSize)
Flags.defaultHttp2InitialStreamWindowSize().
Note that this setting affects the stream-level window size, not the window size of connections.http2InitialConnectionWindowSize(int)public ServerBuilder http2MaxStreamsPerConnection(long http2MaxStreamsPerConnection)
maxNumConnections(),
which is the maximum number of HTTP/2 connections themselves, not the streams that are
multiplexed over each.public ServerBuilder http2MaxFrameSize(int http2MaxFrameSize)
Flags.defaultHttp2MaxFrameSize().public ServerBuilder http2MaxHeaderListSize(long http2MaxHeaderListSize)
Flags.defaultHttp2MaxHeaderListSize().public ServerBuilder http1MaxInitialLineLength(int http1MaxInitialLineLength)
public ServerBuilder http1MaxHeaderSize(int http1MaxHeaderSize)
public ServerBuilder http1MaxChunkSize(int http1MaxChunkSize)
public ServerBuilder gracefulShutdownTimeoutMillis(long quietPeriodMillis, long timeoutMillis)
Server.stop() for
requests to go away before actually shutting down.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 than quietPeriodMillis
to ensure the server shuts down even if there is a stuck request.@Deprecated public ServerBuilder gracefulShutdownTimeout(long quietPeriodMillis, long timeoutMillis)
gracefulShutdownTimeoutMillis(long, long).Server.stop() for
requests to go away before actually shutting down.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 than quietPeriodMillis
to ensure the server shuts down even if there is a stuck request.public ServerBuilder gracefulShutdownTimeout(Duration quietPeriod, Duration timeout)
Server.stop() for
requests to go away before actually shutting down.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 than quietPeriod to ensure the server
shuts down even if there is a stuck request.public ServerBuilder blockingTaskExecutor(ScheduledExecutorService blockingTaskExecutor, boolean shutdownOnStop)
ScheduledExecutorService dedicated to the execution of blocking tasks or invocations.
If not set, the common pool is used.shutdownOnStop - whether to shut down the ScheduledExecutorService when the
Server stopspublic ServerBuilder meterRegistry(MeterRegistry meterRegistry)
MeterRegistry that collects various stats.public ServerBuilder accessLogFormat(String accessLogFormat)
Server's access log. The specified accessLogFormat would be
parsed by AccessLogWriter.custom(String).public ServerBuilder accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
Server. AccessLogWriter.disabled() is used by default.shutdownOnStop - whether to shut down the AccessLogWriter when the Server stopspublic ServerBuilder proxyProtocolMaxTlvSize(int proxyProtocolMaxTlvSize)
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.
@Deprecated public ServerBuilder tls(io.netty.handler.ssl.SslContext sslContext)
SslContext can cause
a Server to malfunction. Use other tls() methods.SslContext of the Server.public ServerBuilder tls(File keyCertChainFile, File keyFile)
tlsCustomizer(Consumer)@Deprecated public ServerBuilder tls(File keyCertChainFile, File keyFile, Consumer<io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
tls(File, File) and tlsCustomizer(Consumer).Server from the specified keyCertChainFile,
cleartext keyFile and tlsCustomizer.public ServerBuilder tls(File keyCertChainFile, File keyFile, String keyPassword)
tlsCustomizer(Consumer)@Deprecated public ServerBuilder tls(File keyCertChainFile, File keyFile, String keyPassword, Consumer<io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
tls(File, File, String) and tlsCustomizer(Consumer).Server from the specified keyCertChainFile,
keyFile, keyPassword and tlsCustomizer.public ServerBuilder tls(InputStream keyCertChainInputStream, InputStream keyInputStream)
Server with the specified keyCertChainInputStream and
cleartext keyInputStream.tlsCustomizer(Consumer)public ServerBuilder tls(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Server with the specified keyCertChainInputStream,
keyInputStream and keyPassword.tlsCustomizer(Consumer)public ServerBuilder tls(PrivateKey key, X509Certificate... keyCertChain)
Server with the specified cleartext PrivateKey and
X509Certificate chain.tlsCustomizer(Consumer)public ServerBuilder tls(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Server with the specified cleartext PrivateKey and
X509Certificate chain.tlsCustomizer(Consumer)public ServerBuilder tls(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Server with the specified PrivateKey, keyPassword
and X509Certificate chain.tlsCustomizer(Consumer)public ServerBuilder tls(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Server with the specified PrivateKey, keyPassword
and X509Certificate chain.tlsCustomizer(Consumer)public ServerBuilder tls(KeyManagerFactory keyManagerFactory)
Server with the specified KeyManagerFactory.tlsCustomizer(Consumer)@Deprecated public ServerBuilder tls(KeyManagerFactory keyManagerFactory, Consumer<io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
tls(KeyManagerFactory) and tlsCustomizer(Consumer).public ServerBuilder tlsSelfSigned()
Server with an auto-generated self-signed certificate.
Note: You should never use this in production but only for a testing purpose.tlsCustomizer(Consumer)public ServerBuilder tlsSelfSigned(boolean tlsSelfSigned)
Server with an auto-generated self-signed certificate.
Note: You should never use this in production but only for a testing purpose.tlsCustomizer(Consumer)public ServerBuilder tlsCustomizer(Consumer<? super io.netty.handler.ssl.SslContextBuilder> tlsCustomizer)
Consumer which can arbitrarily configure the SslContextBuilder that will be
applied to the SSL session.public ServerBuilder withRoute(Consumer<? super ServiceBindingBuilder> customizer)
public ServiceBindingBuilder route()
ServiceBindingBuilder which is for binding an HttpService fluently.public DecoratingServiceBindingBuilder routeDecorator()
DecoratingServiceBindingBuilder which is for binding a decorator fluently.@Deprecated public ServerBuilder serviceAt(String pathPattern, HttpService service)
service(String, HttpService) instead.HttpService at the specified path pattern of the default VirtualHost.public ServerBuilder serviceUnder(String pathPrefix, HttpService service)
HttpService under the specified directory of the default VirtualHost.public ServerBuilder service(String pathPattern, HttpService service)
HttpService at the specified path pattern of the default VirtualHost.
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)IllegalArgumentException - if the specified path pattern is invalidpublic ServerBuilder service(Route route, HttpService service)
public ServerBuilder service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)
HttpServiceWithRoutes at multiple Routes
of the default VirtualHost.serviceWithRoutes - the HttpServiceWithRoutes.decorators - the decorator functions, which will be applied in the order specified.@SafeVarargs public final ServerBuilder service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService,? extends HttpService>... decorators)
HttpServiceWithRoutes at multiple Routes
of the default VirtualHost.serviceWithRoutes - the HttpServiceWithRoutes.decorators - the decorator functions, which will be applied in the order specified.public ServerBuilder annotatedService(Object service)
"/".public ServerBuilder annotatedService(Object service, Object... exceptionHandlersAndConverters)
"/".exceptionHandlersAndConverters - the ExceptionHandlerFunctions,
the RequestConverterFunctions and/or
the ResponseConverterFunctionspublic ServerBuilder annotatedService(Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
"/".exceptionHandlersAndConverters - the ExceptionHandlerFunctions,
the RequestConverterFunctions and/or
the ResponseConverterFunctionspublic ServerBuilder annotatedService(String pathPrefix, Object service)
public ServerBuilder annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)
exceptionHandlersAndConverters - the ExceptionHandlerFunctions,
the RequestConverterFunctions and/or
the ResponseConverterFunctionspublic ServerBuilder annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
exceptionHandlersAndConverters - the ExceptionHandlerFunctions,
the RequestConverterFunctions and/or
the ResponseConverterFunctionspublic ServerBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)
exceptionHandlersAndConverters - the ExceptionHandlerFunctions,
the RequestConverterFunctions and/or
the ResponseConverterFunctionspublic ServerBuilder annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<?> exceptionHandlersAndConverters)
exceptionHandlersAndConverters - the ExceptionHandlerFunction,
the RequestConverterFunction and/or
the ResponseConverterFunctionpublic ServerBuilder annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions, Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions)
exceptionHandlerFunctions - the ExceptionHandlerFunctionsrequestConverterFunctions - the RequestConverterFunctionsresponseConverterFunctions - the ResponseConverterFunctionspublic AnnotatedServiceBindingBuilder annotatedService()
AnnotatedServiceBindingBuilder to build annotated service.public ServerBuilder serverListener(ServerListener serverListener)
ServerListener.public ServerBuilder defaultHostname(String defaultHostname)
VirtualHostBuilder.public ServerBuilder withDefaultVirtualHost(Consumer<? super VirtualHostBuilder> customizer)
VirtualHost with the customizer.@Deprecated public VirtualHostBuilder withDefaultVirtualHost()
defaultVirtualHost().VirtualHostBuilder for building the default
name-based virtual host.public VirtualHostBuilder defaultVirtualHost()
VirtualHostBuilder for building the default
name-based virtual host.public ServerBuilder withVirtualHost(Consumer<? super VirtualHostBuilder> customizer)
VirtualHost with the customizer.@Deprecated public VirtualHostBuilder withVirtualHost(String hostnamePattern)
virtualHost(String).hostnamePattern - virtual host name regular expressionVirtualHostBuilder for building the virtual host@Deprecated public VirtualHostBuilder withVirtualHost(String defaultHostname, String hostnamePattern)
virtualHost(String, String).defaultHostname - default hostname of this virtual hosthostnamePattern - virtual host name regular expressionVirtualHostBuilder for building the virtual hostpublic VirtualHostBuilder virtualHost(String hostnamePattern)
hostnamePattern - virtual host name regular expressionVirtualHostBuilder for building the virtual hostpublic VirtualHostBuilder virtualHost(String defaultHostname, String hostnamePattern)
defaultHostname - default hostname of this virtual hosthostnamePattern - virtual host name regular expressionVirtualHostBuilder for building the virtual hostpublic ServerBuilder decorator(Function<? super HttpService,? extends HttpService> decorator)
HttpServices with the specified decorator.decorator - the Function that decorates HttpServicespublic ServerBuilder decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction)
HttpServices with the specified DecoratingHttpServiceFunction.decoratingHttpServiceFunction - the DecoratingHttpServiceFunction that decorates
HttpServicespublic ServerBuilder decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator)
public ServerBuilder decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
decoratingHttpServiceFunction - the DecoratingHttpServiceFunction that decorates
HttpService.public ServerBuilder decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)
HttpServices with the specified Route.route - the route being decorateddecorator - the Function that decorates HttpService which matches
the specified Routepublic ServerBuilder decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
HttpServices with the specified Route.route - the route being decorateddecoratingHttpServiceFunction - the DecoratingHttpServiceFunction that decorates
HttpServicespublic ServerBuilder decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
HttpServices under the specified directory.decoratingHttpServiceFunction - the DecoratingHttpServiceFunction that decorates
HttpServicespublic ServerBuilder decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)
HttpServices under the specified directory.public ServerBuilder clientAddressSources(ClientAddressSource... clientAddressSources)
ClientAddressSources 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.public ServerBuilder clientAddressSources(Iterable<ClientAddressSource> clientAddressSources)
ClientAddressSources 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.public ServerBuilder clientAddressTrustedProxyFilter(Predicate<? super InetAddress> clientAddressTrustedProxyFilter)
InetAddress of a remote endpoint is trusted.public ServerBuilder clientAddressFilter(Predicate<? super InetAddress> clientAddressFilter)
InetAddress can be used as a client address.public ServerBuilder clientAddressMapper(Function<? super ProxiedAddresses,? extends InetSocketAddress> clientAddressMapper)
Function to use when determining the client address from ProxiedAddresses.
If not set, the ProxiedAddresses.sourceAddress()} is used as a client address.public ServerBuilder accessLogger(String loggerName)
VirtualHosts.
The VirtualHosts which do not have an access logger specified by a VirtualHostBuilder
will have the same access Logger named the loggerName
when build() is called.public ServerBuilder accessLogger(org.slf4j.Logger logger)
Logger for all VirtualHosts.
The VirtualHosts which do not have an access logger specified by a VirtualHostBuilder
will have the same access Logger when build() is called.public ServerBuilder accessLogger(Function<? super VirtualHost,? extends org.slf4j.Logger> mapper)
VirtualHosts.
The VirtualHosts which do not have an access logger specified by a VirtualHostBuilder
will have an access logger set by the mapper when build() is called.public ServerBuilder rejectedRouteHandler(RejectedRouteHandler handler)
RejectedRouteHandler which will be invoked when an attempt to bind
an HttpService at a certain Route is rejected. By default, the duplicate
routes are logged at WARN level.public ServerBuilder disableServerHeader()
"Server" header.public ServerBuilder disableDateHeader()
"Date" header.public ServerBuilder requestIdGenerator(Supplier<? extends RequestId> requestIdGenerator)
Supplier which generates a RequestId.
By default, a RequestId is generated from a random 64-bit integer.RequestContext.id()@Deprecated public ServerBuilder defaultRequestTimeout(Duration requestTimeout)
requestTimeout(Duration).requestTimeout - the timeout. 0 disables the timeout.@Deprecated public ServerBuilder defaultRequestTimeoutMillis(long requestTimeoutMillis)
requestTimeoutMillis(long).requestTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.public ServerBuilder requestTimeout(Duration requestTimeout)
requestTimeout - the timeout. 0 disables the timeout.public ServerBuilder requestTimeoutMillis(long requestTimeoutMillis)
requestTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.@Deprecated public ServerBuilder defaultMaxRequestLength(long maxRequestLength)
maxRequestLength(long).maxRequestLength - the maximum allowed length. 0 disables the length limit.public ServerBuilder maxRequestLength(long maxRequestLength)
maxRequestLength - the maximum allowed length. 0 disables the length limit.public ServerBuilder verboseResponses(boolean verboseResponses)
Flags.verboseResponses().public ServerBuilder annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
RequestConverterFunctions, ResponseConverterFunction
and ExceptionHandlerFunctions for creating an AnnotatedServiceExtensions.requestConverterFunctions - the RequestConverterFunctionsresponseConverterFunctions - the ResponseConverterFunctionsexceptionHandlerFunctions - the ExceptionHandlerFunctionspublic Server build()
Server based on the configuration properties set so far.Copyright © 2020 LeanCloud. All rights reserved.