Package com.linecorp.armeria.server
Class VirtualHostBuilder
java.lang.Object
com.linecorp.armeria.server.VirtualHostBuilder
public final class VirtualHostBuilder extends Object
Builds a new
VirtualHost
.
This class can only be instantiated through the ServerBuilder.defaultVirtualHost()
or
ServerBuilder.virtualHost(String)
method of the ServerBuilder
.
Call and()
method and return to ServerBuilder
.
- See Also:
ServerBuilder
,Route
-
Method Summary
Modifier and Type Method Description VirtualHostBuilder
accessLogger(String loggerName)
VirtualHostBuilder
accessLogger(Function<? super VirtualHost,? extends Logger> mapper)
Sets the access logger mapper of thisVirtualHost
.VirtualHostBuilder
accessLogger(Logger logger)
Sets theLogger
of thisVirtualHost
, which is used for writing access logs.VirtualHostBuilder
accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
Sets the access log writer of thisVirtualHost
.ServerBuilder
and()
Returns the parentServerBuilder
.VirtualHostAnnotatedServiceBindingBuilder
annotatedService()
Returns a new instance ofVirtualHostAnnotatedServiceBindingBuilder
to build an annotated service fluently.VirtualHostBuilder
annotatedService(Object service)
Binds the specified annotated service object under the path prefix"/"
.VirtualHostBuilder
annotatedService(Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.VirtualHostBuilder
annotatedService(Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.VirtualHostBuilder
annotatedService(String pathPrefix, Object service)
Binds the specified annotated service object under the specified path prefix.VirtualHostBuilder
annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.VirtualHostBuilder
annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.VirtualHostBuilder
annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.VirtualHostBuilder
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.VirtualHostBuilder
annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.VirtualHostBuilder
annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
Sets theRequestConverterFunction
s,ResponseConverterFunction
andExceptionHandlerFunction
s for creating anAnnotatedServiceExtensions
.VirtualHostBuilder
decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
.VirtualHostBuilder
decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
VirtualHostBuilder
decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)
VirtualHostBuilder
decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
VirtualHostBuilder
decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator)
VirtualHostBuilder
decorator(Function<? super HttpService,? extends HttpService> decorator)
Decorates allHttpService
s with the specifieddecorator
.VirtualHostBuilder
decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
DecoratesHttpService
s under the specified directory.VirtualHostBuilder
decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)
DecoratesHttpService
s under the specified directory.VirtualHostBuilder
defaultHostname(String defaultHostname)
Sets the default hostname of thisVirtualHost
.VirtualHostBuilder
hostnamePattern(String hostnamePattern)
Sets the hostname pattern of thisVirtualHost
.VirtualHostBuilder
maxRequestLength(long maxRequestLength)
Sets the maximum allowed length of the content decoded at the session layer.VirtualHostBuilder
rejectedRouteHandler(RejectedRouteHandler handler)
Sets theRejectedRouteHandler
which will be invoked when an attempt to bind anHttpService
at a certainRoute
is rejected.VirtualHostBuilder
requestTimeout(Duration requestTimeout)
Sets the timeout of a request.VirtualHostBuilder
requestTimeoutMillis(long requestTimeoutMillis)
Sets the timeout of a request in milliseconds.VirtualHostServiceBindingBuilder
route()
Returns aServiceBindingBuilder
which is for binding anHttpService
fluently.VirtualHostDecoratingServiceBindingBuilder
routeDecorator()
Returns aVirtualHostDecoratingServiceBindingBuilder
which is for binding adecorator
fluently.VirtualHostBuilder
service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)
Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.VirtualHostBuilder
service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService,? extends HttpService>... decorators)
Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.VirtualHostBuilder
service(Route route, HttpService service)
Binds the specifiedHttpService
at the specifiedRoute
.VirtualHostBuilder
service(String pathPattern, HttpService service)
Binds the specifiedHttpService
at the specified path pattern. e.g.VirtualHostBuilder
serviceUnder(String pathPrefix, HttpService service)
Binds the specifiedHttpService
under the specified directory.VirtualHostBuilder
tls(File keyCertChainFile, File keyFile)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
and cleartextkeyFile
.VirtualHostBuilder
tls(File keyCertChainFile, File keyFile, String keyPassword)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
,keyFile
andkeyPassword
.VirtualHostBuilder
tls(InputStream keyCertChainInputStream, InputStream keyInputStream)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainInputStream
and cleartextkeyInputStream
.VirtualHostBuilder
tls(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainInputStream
,keyInputStream
andkeyPassword
.VirtualHostBuilder
tls(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
andX509Certificate
chain.VirtualHostBuilder
tls(PrivateKey key, String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
,keyPassword
andX509Certificate
chain.VirtualHostBuilder
tls(PrivateKey key, String keyPassword, X509Certificate... keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
,keyPassword
andX509Certificate
chain.VirtualHostBuilder
tls(PrivateKey key, X509Certificate... keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
andX509Certificate
chain.VirtualHostBuilder
tls(KeyManagerFactory keyManagerFactory)
Configures SSL or TLS of thisVirtualHost
with the specifiedKeyManagerFactory
.VirtualHostBuilder
tlsCustomizer(Consumer<? super SslContextBuilder> tlsCustomizer)
Adds theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session.VirtualHostBuilder
tlsSelfSigned()
Configures SSL or TLS of thisVirtualHost
with an auto-generated self-signed certificate.VirtualHostBuilder
tlsSelfSigned(boolean tlsSelfSigned)
Configures SSL or TLS of thisVirtualHost
with an auto-generated self-signed certificate.String
toString()
VirtualHostBuilder
verboseResponses(boolean verboseResponses)
Sets whether the verbose response mode is enabled.VirtualHostBuilder
withRoute(Consumer<? super VirtualHostServiceBindingBuilder> customizer)
-
Method Details
-
and
Returns the parentServerBuilder
.- Returns:
- serverBuilder the parent
ServerBuilder
.
-
defaultHostname
Sets the default hostname of thisVirtualHost
. -
hostnamePattern
Sets the hostname pattern of thisVirtualHost
.- Throws:
UnsupportedOperationException
- if this is the defaultVirtualHostBuilder
-
tls
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
and cleartextkeyFile
.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
,keyFile
andkeyPassword
.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainInputStream
and cleartextkeyInputStream
.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(InputStream keyCertChainInputStream, InputStream keyInputStream, @Nullable String keyPassword)Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainInputStream
,keyInputStream
andkeyPassword
.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(PrivateKey key, @Nullable String keyPassword, X509Certificate... keyCertChain)Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
,keyPassword
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(PrivateKey key, @Nullable String keyPassword, Iterable<? extends X509Certificate> keyCertChain)Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
,keyPassword
andX509Certificate
chain.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHost
with the specifiedKeyManagerFactory
.- See Also:
tlsCustomizer(Consumer)
-
tlsSelfSigned
Configures SSL or TLS of thisVirtualHost
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 thisVirtualHost
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. -
withRoute
-
route
Returns aServiceBindingBuilder
which is for binding anHttpService
fluently. -
routeDecorator
Returns aVirtualHostDecoratingServiceBindingBuilder
which is for binding adecorator
fluently. -
serviceUnder
Binds the specifiedHttpService
under the specified directory. -
service
Binds the specifiedHttpService
at the specified path pattern. 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
Binds the specifiedHttpService
at the specifiedRoute
. -
service
public VirtualHostBuilder 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 VirtualHostBuilder 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
public VirtualHostBuilder annotatedService(Object service, Object... exceptionHandlersAndConverters)Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public VirtualHostBuilder 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 VirtualHostBuilder 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 VirtualHostBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public VirtualHostBuilder 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 VirtualHostBuilder 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
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public VirtualHostBuilder 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 a new instance ofVirtualHostAnnotatedServiceBindingBuilder
to build an annotated service fluently. -
decorator
public VirtualHostBuilder decorator(Function<? super HttpService,? extends HttpService> decorator)Decorates allHttpService
s with the specifieddecorator
.- Parameters:
decorator
- theFunction
that decoratesHttpService
s
-
decorator
Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decorator
public VirtualHostBuilder decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decorator
public VirtualHostBuilder decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator) -
decorator
public VirtualHostBuilder decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)- Parameters:
route
- the route being decorateddecorator
- theFunction
that decoratesHttpService
-
decorator
public VirtualHostBuilder decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)- Parameters:
route
- the route being decorateddecoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decoratorUnder
public VirtualHostBuilder decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpService
s under the specified directory. -
decoratorUnder
public VirtualHostBuilder decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpService
s under the specified directory.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
accessLogger
Sets the access logger mapper of thisVirtualHost
. -
accessLogger
Sets theLogger
of thisVirtualHost
, which is used for writing access logs. -
accessLogger
-
rejectedRouteHandler
Sets theRejectedRouteHandler
which will be invoked when an attempt to bind anHttpService
at a certainRoute
is rejected. If not set, theRejectedRouteHandler
set viaServerBuilder.rejectedRouteHandler(RejectedRouteHandler)
is used. -
requestTimeout
Sets the timeout of a request. If not set, the value set viaServerBuilder.requestTimeoutMillis(long)
is used.- Parameters:
requestTimeout
- the timeout.0
disables the timeout.
-
requestTimeoutMillis
Sets the timeout of a request in milliseconds. If not set, the value set viaServerBuilder.requestTimeoutMillis(long)
is used.- 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. If not set, the value set viaServerBuilder.maxRequestLength(long)
is used.- 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. If not set, the value set viaServerBuilder.verboseResponses(boolean)
is used. -
accessLogWriter
Sets the access log writer of thisVirtualHost
. If not set, theAccessLogWriter
set viaServerBuilder.accessLogWriter(AccessLogWriter, boolean)
is used.- Parameters:
shutdownOnStop
- whether to shut down theAccessLogWriter
when theServer
stops
-
annotatedServiceExtensions
public VirtualHostBuilder 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
-
toString
-