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 theLoggerof 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 ofVirtualHostAnnotatedServiceBindingBuilderto 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 theRequestConverterFunctions,ResponseConverterFunctionandExceptionHandlerFunctions for creating anAnnotatedServiceExtensions.decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction)Decorates allHttpServices 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 allHttpServices with the specifieddecorator.decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpServices under the specified directory.decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpServices 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 theRejectedRouteHandlerwhich will be invoked when an attempt to bind anHttpServiceat a certainRouteis rejected.requestTimeout(Duration requestTimeout)Sets the timeout of a request.requestTimeoutMillis(long requestTimeoutMillis)Sets the timeout of a request in milliseconds.route()Returns aServiceBindingBuilderwhich is for binding anHttpServicefluently.Returns aVirtualHostDecoratingServiceBindingBuilderwhich is for binding adecoratorfluently.service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)Decorates and binds the specifiedHttpServiceWithRoutesat multipleRoutes of the defaultVirtualHost.service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService,? extends HttpService>... decorators)Decorates and binds the specifiedHttpServiceWithRoutesat multipleRoutes of the defaultVirtualHost.service(Route route, HttpService service)Binds the specifiedHttpServiceat the specifiedRoute.service(String pathPattern, HttpService service)Binds the specifiedHttpServiceat the specified path pattern. e.g.serviceUnder(String pathPrefix, HttpService service)Binds the specifiedHttpServiceunder the specified directory.Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainFileand cleartextkeyFile.Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainFile,keyFileandkeyPassword.tls(InputStream keyCertChainInputStream, InputStream keyInputStream)Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainInputStreamand cleartextkeyInputStream.tls(InputStream keyCertChainInputStream, InputStream keyInputStream, @Nullable String keyPassword)Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainInputStream,keyInputStreamandkeyPassword.tls(PrivateKey key, @Nullable String keyPassword, Iterable<? extends X509Certificate> keyCertChain)Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKey,keyPasswordandX509Certificatechain.tls(PrivateKey key, @Nullable String keyPassword, X509Certificate... keyCertChain)Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKey,keyPasswordandX509Certificatechain.tls(PrivateKey key, Iterable<? extends X509Certificate> keyCertChain)Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKeyandX509Certificatechain.tls(PrivateKey key, X509Certificate... keyCertChain)Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKeyandX509Certificatechain.tls(KeyManagerFactory keyManagerFactory)Configures SSL or TLS of thisVirtualHostwith 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 theConsumerwhich can arbitrarily configure theSslContextBuilderthat will be applied to the SSL session.Configures SSL or TLS of thisVirtualHostwith an auto-generated self-signed certificate.tlsSelfSigned(boolean tlsSelfSigned)Configures SSL or TLS of thisVirtualHostwith 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 thisVirtualHostwith the specifiedkeyCertChainFileand cleartextkeyFile.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(File keyCertChainFile, File keyFile, @Nullable @Nullable String keyPassword)Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainFile,keyFileandkeyPassword.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainInputStreamand cleartextkeyInputStream.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(InputStream keyCertChainInputStream, InputStream keyInputStream, @Nullable @Nullable String keyPassword)Configures SSL or TLS of thisVirtualHostwith the specifiedkeyCertChainInputStream,keyInputStreamandkeyPassword.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKeyandX509Certificatechain.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKeyandX509Certificatechain.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(PrivateKey key, @Nullable @Nullable String keyPassword, X509Certificate... keyCertChain)Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKey,keyPasswordandX509Certificatechain.- See Also:
tlsCustomizer(Consumer)
-
tls
public VirtualHostBuilder tls(PrivateKey key, @Nullable @Nullable String keyPassword, Iterable<? extends X509Certificate> keyCertChain)Configures SSL or TLS of thisVirtualHostwith the specified cleartextPrivateKey,keyPasswordandX509Certificatechain.- See Also:
tlsCustomizer(Consumer)
-
tls
Configures SSL or TLS of thisVirtualHostwith the specifiedKeyManagerFactory.- See Also:
tlsCustomizer(Consumer)
-
tlsSelfSigned
Configures SSL or TLS of thisVirtualHostwith 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 thisVirtualHostwith 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 theConsumerwhich can arbitrarily configure theSslContextBuilderthat 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 aServiceBindingBuilderwhich is for binding anHttpServicefluently. -
routeDecorator
Returns aVirtualHostDecoratingServiceBindingBuilderwhich is for binding adecoratorfluently. The specified decorator(s) is/are executed in reverse order of the insertion. -
serviceUnder
Binds the specifiedHttpServiceunder the specified directory. -
service
Binds the specifiedHttpServiceat 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 specifiedHttpServiceat the specifiedRoute. -
service
public VirtualHostBuilder service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)Decorates and binds the specifiedHttpServiceWithRoutesat multipleRoutes 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 specifiedHttpServiceWithRoutesat multipleRoutes 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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
annotatedService
public VirtualHostBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters- theExceptionHandlerFunction,RequestConverterFunctionand/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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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- theExceptionHandlerFunctionsrequestConverterFunctions- theRequestConverterFunctionsresponseConverterFunctions- theResponseConverterFunctions
-
annotatedService
Returns a new instance ofVirtualHostAnnotatedServiceBindingBuilderto build an annotated service fluently. -
decorator
public VirtualHostBuilder decorator(Function<? super HttpService,? extends HttpService> decorator)Decorates allHttpServices with the specifieddecorator. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decorator- theFunctionthat decoratesHttpServices
-
decorator
Decorates allHttpServices with the specifiedDecoratingHttpServiceFunction. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decorator
public VirtualHostBuilder decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpServices whoseRoutematches the specifiedpathPattern. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decorator
public VirtualHostBuilder decorator(String pathPattern, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpServices whoseRoutematches 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)DecoratesHttpServices whoseRoutematches the specifiedRoute. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route- the route being decorateddecorator- theFunctionthat decoratesHttpService
-
decorator
public VirtualHostBuilder decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction)DecoratesHttpServices whoseRoutematches the specifiedRoute. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route- the route being decorateddecoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decoratorUnder
public VirtualHostBuilder decoratorUnder(String prefix, Function<? super HttpService,? extends HttpService> decorator)DecoratesHttpServices 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)DecoratesHttpServices under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
accessLogger
Sets the access logger mapper of thisVirtualHost. -
accessLogger
Sets theLoggerof thisVirtualHost, which is used for writing access logs. -
accessLogger
-
rejectedRouteHandler
Sets theRejectedRouteHandlerwhich will be invoked when an attempt to bind anHttpServiceat a certainRouteis rejected. If not set, theRejectedRouteHandlerset 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.0disables 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.0disables 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.0disables 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, theAccessLogWriterset viaServerBuilder.accessLogWriter(AccessLogWriter, boolean)is used.- Parameters:
shutdownOnStop- whether to shut down theAccessLogWriterwhen theServerstops
-
annotatedServiceExtensions
public VirtualHostBuilder annotatedServiceExtensions(Iterable<? extends RequestConverterFunction> requestConverterFunctions, Iterable<? extends ResponseConverterFunction> responseConverterFunctions, Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)Sets theRequestConverterFunctions,ResponseConverterFunctionandExceptionHandlerFunctions for creating anAnnotatedServiceExtensions.- Parameters:
requestConverterFunctions- theRequestConverterFunctionsresponseConverterFunctions- theResponseConverterFunctionsexceptionHandlerFunctions- theExceptionHandlerFunctions
-
toString
-