Package com.linecorp.armeria.server
Class VirtualHostBuilder
- java.lang.Object
-
- com.linecorp.armeria.server.VirtualHostBuilder
-
public class VirtualHostBuilder extends Object
Builds a newVirtualHost
.Example
VirtualHostBuilder vhb = new VirtualHostBuilder("*.example.com"); vhb.service("/foo", new FooService()) .serviceUnder("/bar/", new BarService()) .service(PathMapping.ofRegex("^/baz/.*", new BazService()); VirtualHost vh = vhb.build();
- See Also:
PathMapping
-
-
Constructor Summary
Constructors Constructor Description VirtualHostBuilder()
Creates a newVirtualHostBuilder
whose hostname pattern is"*"
(match-all).VirtualHostBuilder(String hostnamePattern)
Creates a newVirtualHostBuilder
with the specified hostname pattern.VirtualHostBuilder(String defaultHostname, String hostnamePattern)
Creates a newVirtualHostBuilder
with the default host name and the specified hostname pattern.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description B
accessLogger(String loggerName)
B
accessLogger(Function<VirtualHost,Logger> mapper)
Sets the access logger mapper of thisVirtualHost
.B
accessLogger(Logger logger)
Sets theLogger
of thisVirtualHost
, which is used for writing access logs.B
annotatedService(Object service)
Binds the specified annotated service object under the path prefix"/"
.B
annotatedService(Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.B
annotatedService(Object service, Function<Service<HttpRequest,HttpResponse>,? extends Service<HttpRequest,HttpResponse>> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.B
annotatedService(String pathPrefix, Object service)
Binds the specified annotated service object under the specified path prefix.B
annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.B
annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.B
annotatedService(String pathPrefix, Object service, Function<Service<HttpRequest,HttpResponse>,? extends Service<HttpRequest,HttpResponse>> decorator, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.B
annotatedService(String pathPrefix, Object service, Function<Service<HttpRequest,HttpResponse>,? extends Service<HttpRequest,HttpResponse>> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.VirtualHost
build()
Returns a newly-createdVirtualHost
based on the properties of this builder and the services added to this builder.B
contentPreview(int length)
Sets theContentPreviewerFactory
creating aContentPreviewer
which produces the preview with the maxmiumlength
limit for a request and a response of thisVirtualHost
.B
contentPreview(int length, Charset defaultCharset)
Sets theContentPreviewerFactory
creating aContentPreviewer
which produces the preview with the maxmiumlength
limit for a request and a response of thisVirtualHost
.B
contentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request and a response of thisVirtualHost
.<T extends Service<HttpRequest,HttpResponse>,R extends Service<HttpRequest,HttpResponse>>
Bdecorator(Function<T,R> decorator)
Decorates allService
s with the specifieddecorator
.B
requestContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request of thisVirtualHost
.B
responseContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a response of thisVirtualHost
.B
service(PathMapping pathMapping, Service<HttpRequest,HttpResponse> service)
Binds the specifiedService
at the specifiedPathMapping
.B
service(PathMapping pathMapping, Service<HttpRequest,HttpResponse> service, String loggerName)
Deprecated.Use a logging framework integration such asRequestContextExportingAppender
inarmeria-logback
.B
service(String pathPattern, Service<HttpRequest,HttpResponse> service)
Binds the specifiedService
at the specified path pattern. e.g.<T extends ServiceWithPathMappings<HttpRequest,HttpResponse>>
Bservice(T serviceWithPathMappings)
Binds the specifiedServiceWithPathMappings
at multiplePathMapping
s.<T extends ServiceWithPathMappings<HttpRequest,HttpResponse>,R extends Service<HttpRequest,HttpResponse>>
Bservice(T serviceWithPathMappings, Function<? super T,R> decorator)
Decorates and binds the specifiedServiceWithPathMappings
at multiplePathMapping
s.B
serviceAt(String pathPattern, Service<HttpRequest,HttpResponse> service)
Deprecated.Useservice(String, Service)
instead.B
serviceUnder(String pathPrefix, Service<HttpRequest,HttpResponse> service)
Binds the specifiedService
under the specified directory.B
sslContext(SessionProtocol protocol, File keyCertChainFile, File keyFile)
Deprecated.Usetls(File, File)
.B
sslContext(SessionProtocol protocol, File keyCertChainFile, File keyFile, String keyPassword)
Deprecated.B
sslContext(SslContext sslContext)
Deprecated.Usetls(SslContext)
.B
tls(SslContext sslContext)
Configures SSL or TLS of thisVirtualHost
with the specifiedSslContext
.B
tls(File keyCertChainFile, File keyFile)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
and cleartextkeyFile
.B
tls(File keyCertChainFile, File keyFile, String keyPassword)
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
,keyFile
andkeyPassword
.B
tlsSelfSigned()
Configures SSL or TLS of thisVirtualHost
with an auto-generated self-signed certificate.String
toString()
-
-
-
Constructor Detail
-
VirtualHostBuilder
public VirtualHostBuilder()
Creates a newVirtualHostBuilder
whose hostname pattern is"*"
(match-all).
-
VirtualHostBuilder
public VirtualHostBuilder(String hostnamePattern)
Creates a newVirtualHostBuilder
with the specified hostname pattern.
-
VirtualHostBuilder
public VirtualHostBuilder(String defaultHostname, String hostnamePattern)
Creates a newVirtualHostBuilder
with the default host name and the specified hostname pattern.
-
-
Method Detail
-
build
public VirtualHost build()
Returns a newly-createdVirtualHost
based on the properties of this builder and the services added to this builder.
-
tls
public B tls(SslContext sslContext)
Configures SSL or TLS of thisVirtualHost
with the specifiedSslContext
.
-
tls
public B tls(File keyCertChainFile, File keyFile) throws SSLException
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
and cleartextkeyFile
.- Throws:
SSLException
-
tls
public B tls(File keyCertChainFile, File keyFile, @Nullable String keyPassword) throws SSLException
Configures SSL or TLS of thisVirtualHost
with the specifiedkeyCertChainFile
,keyFile
andkeyPassword
.- Throws:
SSLException
-
tlsSelfSigned
public B tlsSelfSigned() throws SSLException, CertificateException
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.- Throws:
CertificateException
- if failed to generate a self-signed certificateSSLException
-
sslContext
@Deprecated public B sslContext(SslContext sslContext)
Deprecated.Usetls(SslContext)
.Sets theSslContext
of thisVirtualHost
.
-
sslContext
@Deprecated public B sslContext(SessionProtocol protocol, File keyCertChainFile, File keyFile) throws SSLException
Deprecated.Usetls(File, File)
.Sets theSslContext
of thisVirtualHost
from the specifiedSessionProtocol
,keyCertChainFile
and cleartextkeyFile
.- Throws:
SSLException
-
sslContext
@Deprecated public B sslContext(SessionProtocol protocol, File keyCertChainFile, File keyFile, @Nullable String keyPassword) throws SSLException
Deprecated.Sets theSslContext
of thisVirtualHost
from the specifiedSessionProtocol
,keyCertChainFile
,keyFile
andkeyPassword
.- Throws:
SSLException
-
serviceAt
@Deprecated public B serviceAt(String pathPattern, Service<HttpRequest,HttpResponse> service)
Deprecated.Useservice(String, Service)
instead.Binds the specifiedService
at the specified path pattern.
-
serviceUnder
public B serviceUnder(String pathPrefix, Service<HttpRequest,HttpResponse> service)
Binds the specifiedService
under the specified directory.
-
service
public B service(String pathPattern, Service<HttpRequest,HttpResponse> service)
Binds the specifiedService
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
public B service(PathMapping pathMapping, Service<HttpRequest,HttpResponse> service)
Binds the specifiedService
at the specifiedPathMapping
.
-
service
@Deprecated public B service(PathMapping pathMapping, Service<HttpRequest,HttpResponse> service, String loggerName)
Deprecated.Use a logging framework integration such asRequestContextExportingAppender
inarmeria-logback
.Binds the specifiedService
at the specifiedPathMapping
.
-
service
public <T extends ServiceWithPathMappings<HttpRequest,HttpResponse>> B service(T serviceWithPathMappings)
Binds the specifiedServiceWithPathMappings
at multiplePathMapping
s.
-
service
public <T extends ServiceWithPathMappings<HttpRequest,HttpResponse>,R extends Service<HttpRequest,HttpResponse>> B service(T serviceWithPathMappings, Function<? super T,R> decorator)
Decorates and binds the specifiedServiceWithPathMappings
at multiplePathMapping
s.
-
annotatedService
public B annotatedService(Object service)
Binds the specified annotated service object under the path prefix"/"
.
-
annotatedService
public B annotatedService(Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- instances ofExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public B annotatedService(Object service, Function<Service<HttpRequest,HttpResponse>,? extends Service<HttpRequest,HttpResponse>> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- instances ofExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public B annotatedService(String pathPrefix, Object service)
Binds the specified annotated service object under the specified path prefix.
-
annotatedService
public B annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- instances ofExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public B annotatedService(String pathPrefix, Object service, Function<Service<HttpRequest,HttpResponse>,? extends Service<HttpRequest,HttpResponse>> decorator, Object... exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- instances ofExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public B annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- an iterable object ofExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public B annotatedService(String pathPrefix, Object service, Function<Service<HttpRequest,HttpResponse>,? extends Service<HttpRequest,HttpResponse>> decorator, Iterable<?> exceptionHandlersAndConverters)
Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- an iterable object ofExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
decorator
public <T extends Service<HttpRequest,HttpResponse>,R extends Service<HttpRequest,HttpResponse>> B decorator(Function<T,R> decorator)
Decorates allService
s with the specifieddecorator
.
-
accessLogger
public B accessLogger(Function<VirtualHost,Logger> mapper)
Sets the access logger mapper of thisVirtualHost
. Whenbuild()
is called, thisVirtualHost
getsLogger
via themapper
for writing access logs.
-
accessLogger
public B accessLogger(Logger logger)
Sets theLogger
of thisVirtualHost
, which is used for writing access logs.
-
accessLogger
public B accessLogger(String loggerName)
-
requestContentPreviewerFactory
public B requestContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request of thisVirtualHost
.
-
responseContentPreviewerFactory
public B responseContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a response of thisVirtualHost
.
-
contentPreviewerFactory
public B contentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request and a response of thisVirtualHost
.
-
contentPreview
public B contentPreview(int length, Charset defaultCharset)
Sets theContentPreviewerFactory
creating aContentPreviewer
which produces the preview with the maxmiumlength
limit for a request and a response of thisVirtualHost
. The previewer is enabled only if the content type of a request/response meets any of the following cases.- when it matches
text/*
orapplication/x-www-form-urlencoded
- when its charset has been specified
- when its subtype is
"xml"
or"json"
- when its subtype ends with
"+xml"
or"+json"
- Parameters:
length
- the maximum length of the preview.defaultCharset
- the default charset for a request/response with unspecified charset in"Content-Type"
header.
- when it matches
-
contentPreview
public B contentPreview(int length)
Sets theContentPreviewerFactory
creating aContentPreviewer
which produces the preview with the maxmiumlength
limit for a request and a response of thisVirtualHost
. The previewer is enabled only if the content type of a request/response meets any of the following cases.- when it matches
text/*
orapplication/x-www-form-urlencoded
- when its charset has been specified
- when its subtype is
"xml"
or"json"
- when its subtype ends with
"+xml"
or"+json"
- Parameters:
length
- the maximum length of the preview.
- when it matches
-
-