Package com.linecorp.armeria.server
Class VirtualHostAnnotatedServiceBindingBuilder
java.lang.Object
com.linecorp.armeria.server.VirtualHostAnnotatedServiceBindingBuilder
A builder class for binding an
HttpService
to a virtual host fluently. This class can be instantiated
through VirtualHostBuilder.annotatedService()
.
Call build(Object)
to build the HttpService
and return to the VirtualHostBuilder
.
ServerBuilder sb = Server.builder();
sb.virtualHost("foo.com") // Return a new instance of {@link VirtualHostBuilder}
.annotatedService() // Return a new instance of this class
.requestTimeoutMillis(5000)
.maxRequestLength(8192)
.exceptionHandler((ctx, request, cause) -> HttpResponse.of(400))
.pathPrefix("/foo")
.verboseResponses(true)
.build(new FooService()) // Return to {@link VirtualHostBuilder}
.and() // Return to {@link ServerBuilder}
.annotatedService(new MyDefaultHostService())
.build();
- See Also:
VirtualHostBuilder
,AnnotatedServiceBindingBuilder
-
Method Summary
Modifier and TypeMethodDescriptionaccessLogFormat(String accessLogFormat)
accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
Registers the given service to the VirtualHostBuilder.decorator(Function<? super HttpService,? extends HttpService> decorator)
decorators(Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators)
decorators(Function<? super HttpService,? extends HttpService>... decorators)
defaultLogName(String defaultLogName)
defaultServiceName(String defaultServiceName)
defaultServiceNaming(ServiceNaming defaultServiceNaming)
exceptionHandlers(ExceptionHandlerFunction... exceptionHandlerFunctions)
Adds the givenExceptionHandlerFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
.exceptionHandlers(Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
Adds the givenExceptionHandlerFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
.maxRequestLength(long maxRequestLength)
pathPrefix(String pathPrefix)
Sets the path prefix to be used for thisVirtualHostAnnotatedServiceBindingBuilder
.requestConverters(RequestConverterFunction... requestConverterFunctions)
Adds the givenRequestConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
.requestConverters(Iterable<? extends RequestConverterFunction> requestConverterFunctions)
Adds the givenRequestConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
.requestTimeout(Duration requestTimeout)
requestTimeoutMillis(long requestTimeoutMillis)
responseConverters(ResponseConverterFunction... responseConverterFunctions)
Adds the givenResponseConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
.responseConverters(Iterable<? extends ResponseConverterFunction> responseConverterFunctions)
Adds the givenResponseConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
.useBlockingTaskExecutor(boolean useBlockingTaskExecutor)
Sets whether the service executes service methods using the blocking executor.verboseResponses(boolean verboseResponses)
-
Method Details
-
pathPrefix
Sets the path prefix to be used for thisVirtualHostAnnotatedServiceBindingBuilder
.- Parameters:
pathPrefix
- string representing the path prefix.
-
exceptionHandlers
public VirtualHostAnnotatedServiceBindingBuilder exceptionHandlers(ExceptionHandlerFunction... exceptionHandlerFunctions)Adds the givenExceptionHandlerFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
. -
exceptionHandlers
public VirtualHostAnnotatedServiceBindingBuilder exceptionHandlers(Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)Adds the givenExceptionHandlerFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
. -
responseConverters
public VirtualHostAnnotatedServiceBindingBuilder responseConverters(ResponseConverterFunction... responseConverterFunctions)Adds the givenResponseConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
. -
responseConverters
public VirtualHostAnnotatedServiceBindingBuilder responseConverters(Iterable<? extends ResponseConverterFunction> responseConverterFunctions)Adds the givenResponseConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
. -
requestConverters
public VirtualHostAnnotatedServiceBindingBuilder requestConverters(RequestConverterFunction... requestConverterFunctions)Adds the givenRequestConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
. -
requestConverters
public VirtualHostAnnotatedServiceBindingBuilder requestConverters(Iterable<? extends RequestConverterFunction> requestConverterFunctions)Adds the givenRequestConverterFunction
s to thisVirtualHostAnnotatedServiceBindingBuilder
. -
useBlockingTaskExecutor
public VirtualHostAnnotatedServiceBindingBuilder useBlockingTaskExecutor(boolean useBlockingTaskExecutor)Sets whether the service executes service methods using the blocking executor. By default, service methods are executed directly on the event loop for implementing fully asynchronous services. If your service uses blocking logic, you should either execute such logic in a separate thread using something likeExecutors.newCachedThreadPool()
or enable this setting. -
requestTimeout
-
requestTimeoutMillis
-
maxRequestLength
-
verboseResponses
-
accessLogFormat
-
accessLogWriter
public VirtualHostAnnotatedServiceBindingBuilder accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop) -
decorator
public VirtualHostAnnotatedServiceBindingBuilder decorator(Function<? super HttpService,? extends HttpService> decorator) -
decorators
@SafeVarargs public final VirtualHostAnnotatedServiceBindingBuilder decorators(Function<? super HttpService,? extends HttpService>... decorators) -
decorators
public VirtualHostAnnotatedServiceBindingBuilder decorators(Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators) -
defaultServiceName
-
defaultServiceNaming
public VirtualHostAnnotatedServiceBindingBuilder defaultServiceNaming(ServiceNaming defaultServiceNaming) -
defaultLogName
-
build
Registers the given service to the VirtualHostBuilder.- Parameters:
service
- annotated service object to handle incoming requests matching path prefix, which can be configured throughAnnotatedServiceBindingBuilder.pathPrefix(String)
. If path prefix is not set then this service is registered to handle requests matching/
- Returns:
VirtualHostBuilder
to continue buildingVirtualHost
-