Package com.linecorp.armeria.server
Class AnnotatedServiceBindingBuilder
java.lang.Object
com.linecorp.armeria.server.AnnotatedServiceBindingBuilder
A builder class for binding an
HttpService
fluently. This class can be instantiated through
ServerBuilder.annotatedService()
.
Call build(Object)
to build the HttpService
and return to the ServerBuilder
.
ServerBuilder sb = Server.builder();
sb.annotatedService() // Returns an instance of this class
.requestTimeoutMillis(5000)
.maxRequestLength(8192)
.exceptionHandler((ctx, request, cause) -> HttpResponse.of(400))
.pathPrefix("/foo")
.verboseResponses(true)
.build(new Service()) // Return to the ServerBuilder.
.build();
- See Also:
ServiceBindingBuilder
-
Method Summary
Modifier and TypeMethodDescriptionaccessLogFormat(String accessLogFormat)
accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop)
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 thisAnnotatedServiceBindingBuilder
.exceptionHandlers(Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)
Adds the givenExceptionHandlerFunction
s to thisAnnotatedServiceBindingBuilder
.maxRequestLength(long maxRequestLength)
pathPrefix(String pathPrefix)
Sets the path prefix to be used for thisAnnotatedServiceBindingBuilder
.requestConverters(RequestConverterFunction... requestConverterFunctions)
Adds the givenRequestConverterFunction
s to thisAnnotatedServiceBindingBuilder
.requestConverters(Iterable<? extends RequestConverterFunction> requestConverterFunctions)
Adds the givenRequestConverterFunction
s to thisAnnotatedServiceBindingBuilder
.requestTimeout(Duration requestTimeout)
requestTimeoutMillis(long requestTimeoutMillis)
responseConverters(ResponseConverterFunction... responseConverterFunctions)
Adds the givenResponseConverterFunction
s to thisAnnotatedServiceBindingBuilder
.responseConverters(Iterable<? extends ResponseConverterFunction> responseConverterFunctions)
Adds the givenResponseConverterFunction
s to thisAnnotatedServiceBindingBuilder
.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 thisAnnotatedServiceBindingBuilder
.- Parameters:
pathPrefix
- string representing the path prefix.
-
exceptionHandlers
public AnnotatedServiceBindingBuilder exceptionHandlers(ExceptionHandlerFunction... exceptionHandlerFunctions)Adds the givenExceptionHandlerFunction
s to thisAnnotatedServiceBindingBuilder
. -
exceptionHandlers
public AnnotatedServiceBindingBuilder exceptionHandlers(Iterable<? extends ExceptionHandlerFunction> exceptionHandlerFunctions)Adds the givenExceptionHandlerFunction
s to thisAnnotatedServiceBindingBuilder
. -
responseConverters
public AnnotatedServiceBindingBuilder responseConverters(ResponseConverterFunction... responseConverterFunctions)Adds the givenResponseConverterFunction
s to thisAnnotatedServiceBindingBuilder
. -
responseConverters
public AnnotatedServiceBindingBuilder responseConverters(Iterable<? extends ResponseConverterFunction> responseConverterFunctions)Adds the givenResponseConverterFunction
s to thisAnnotatedServiceBindingBuilder
. -
requestConverters
public AnnotatedServiceBindingBuilder requestConverters(RequestConverterFunction... requestConverterFunctions)Adds the givenRequestConverterFunction
s to thisAnnotatedServiceBindingBuilder
. -
requestConverters
public AnnotatedServiceBindingBuilder requestConverters(Iterable<? extends RequestConverterFunction> requestConverterFunctions)Adds the givenRequestConverterFunction
s to thisAnnotatedServiceBindingBuilder
. -
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. -
decorator
public AnnotatedServiceBindingBuilder decorator(Function<? super HttpService,? extends HttpService> decorator) -
decorators
@SafeVarargs public final AnnotatedServiceBindingBuilder decorators(Function<? super HttpService,? extends HttpService>... decorators) -
decorators
public AnnotatedServiceBindingBuilder decorators(Iterable<? extends Function<? super HttpService,? extends HttpService>> decorators) -
requestTimeout
-
requestTimeoutMillis
-
maxRequestLength
-
verboseResponses
-
accessLogFormat
-
accessLogWriter
public AnnotatedServiceBindingBuilder accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop) -
defaultServiceName
-
defaultServiceNaming
-
defaultLogName
-
build
- Parameters:
service
- annotated service object to handle incoming requests matching path prefix, which can be configured throughpathPrefix(String)
. If path prefix is not set then this service is registered to handle requests matching/
- Returns:
ServerBuilder
to continue buildingServer
-