Package com.linecorp.armeria.server
Class VirtualHostBuilder
java.lang.Object
com.linecorp.armeria.server.VirtualHostBuilder
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 TypeMethodDescriptionaccessLogger(String loggerName)
accessLogger(Function<? super VirtualHost,? extends Logger> mapper)
Sets the access logger mapper of thisVirtualHost
.accessLogger(Logger logger)
Sets theLogger
of thisVirtualHost
, which is used for writing access logs.accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
Sets the access log writer of thisVirtualHost
.and()
Returns the parentServerBuilder
.Returns a new instance ofVirtualHostAnnotatedServiceBindingBuilder
to build an annotated service fluently.annotatedService(Object service)
Binds the specified annotated service object under the path prefix"/"
.annotatedService(Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.annotatedService(Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.annotatedService(String pathPrefix, Object service)
Binds the specified annotated service object under the specified path prefix.annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.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.annotatedService(String pathPrefix, Object service, Function<? super HttpService,? extends HttpService> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
Sets theRequestConverterFunction
s,ResponseConverterFunction
andExceptionHandlerFunction
s for creating anAnnotatedServiceExtensions
.decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction)
Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
.decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)
decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator)
decorator(Function<? super HttpService,? extends HttpService> decorator)
Decorates allHttpService
s with the specifieddecorator
.decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)
DecoratesHttpService
s under the specified directory.decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)
DecoratesHttpService
s under the specified directory.defaultHostname(String defaultHostname)
Sets the default hostname of thisVirtualHost
.defaultServiceNaming(ServiceNaming defaultServiceNaming)
Sets the default naming rule for the name of services.hostnamePattern(String hostnamePattern)
Sets the hostname pattern of thisVirtualHost
.maxRequestLength(long maxRequestLength)
Sets the maximum allowed length of the content decoded at the session layer.rejectedRouteHandler(RejectedRouteHandler handler)
Sets theRejectedRouteHandler
which will be invoked when an attempt to bind anHttpService
at a certainRoute
is rejected.requestTimeout(Duration requestTimeout)
Sets the timeout of a request.requestTimeoutMillis(long requestTimeoutMillis)
Sets the timeout of a request in milliseconds.route()
Returns aServiceBindingBuilder
which is for binding anHttpService
fluently.Returns aVirtualHostDecoratingServiceBindingBuilder
which is for binding adecorator
fluently.service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)
Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService,? extends HttpService>... decorators)
Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s of the defaultVirtualHost
.service(Route route, HttpService service)
Binds the specifiedHttpService
at the specifiedRoute
.service(String pathPattern, HttpService service)
Binds the specifiedHttpService
at the specified path pattern. e.g.serviceUnder(String pathPrefix, HttpService service)
Binds the specifiedHttpService
under the specified directory.Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
and cleartextkeyFile
.Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
,keyFile
andkeyPassword
.tls(InputStream keyCertChainInputStream, InputStream keyInputStream)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainInputStream
and cleartextkeyInputStream
.tls(InputStream keyCertChainInputStream, InputStream keyInputStream, @Nullable String keyPassword)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainInputStream
,keyInputStream
andkeyPassword
.tls(PrivateKey key, @Nullable String keyPassword, Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
,keyPassword
andX509Certificate
chain.tls(PrivateKey key, @Nullable String keyPassword, X509Certificate... keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
,keyPassword
andX509Certificate
chain.tls(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
andX509Certificate
chain.tls(PrivateKey key, X509Certificate... keyCertChain)
Configures SSL or TLS of thisVirtualHost
with the specified cleartextPrivateKey
andX509Certificate
chain.tls(KeyManagerFactory keyManagerFactory)
Configures SSL or TLS of thisVirtualHost
with the specifiedKeyManagerFactory
.Deprecated.It's not recommended to enable this option.tlsAllowUnsafeCiphers(boolean tlsAllowUnsafeCiphers)
Deprecated.It's not recommended to enable this option.tlsCustomizer(Consumer<? super SslContextBuilder> tlsCustomizer)
Adds theConsumer
which can arbitrarily configure theSslContextBuilder
that will be applied to the SSL session.Configures SSL or TLS of thisVirtualHost
with an auto-generated self-signed certificate.tlsSelfSigned(boolean tlsSelfSigned)
Configures SSL or TLS of thisVirtualHost
with an auto-generated self-signed certificate.toString()
verboseResponses(boolean verboseResponses)
Sets whether the verbose response mode is enabled.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
public VirtualHostBuilder tls(File keyCertChainFile, File keyFile, @Nullable @Nullable String keyPassword)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 @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 @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 @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. -
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 aVirtualHostDecoratingServiceBindingBuilder
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. -
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
. 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 VirtualHostBuilder 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
s
-
decorator
public VirtualHostBuilder 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 VirtualHostBuilder decorator(Route route, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpService
s whoseRoute
matches the specifiedRoute
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route
- the route being decorateddecorator
- theFunction
that decoratesHttpService
-
decorator
public VirtualHostBuilder decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpService
s whoseRoute
matches 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 VirtualHostBuilder 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. -
decoratorUnder
public VirtualHostBuilder 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
-
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.
-
defaultServiceNaming
Sets the default naming rule for the name of services. If not set, the value set viaServerBuilder.defaultServiceNaming(ServiceNaming)
is used. -
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
-