Package com.linecorp.armeria.server
Class ServiceBindingBuilder
java.lang.Object
com.linecorp.armeria.server.ServiceBindingBuilder
A builder class for binding an
HttpService fluently. This class can be instantiated through
ServerBuilder.route(). You can also configure an HttpService using
ServerBuilder.withRoute(Consumer).
Call build(HttpService) to build the HttpService and return to the ServerBuilder.
ServerBuilder sb = Server.builder();
sb.route() // Configure the first service.
.post("/foo/bar")
.consumes(JSON, PLAIN_TEXT_UTF_8)
.produces(JSON_UTF_8)
.requestTimeoutMillis(5000)
.maxRequestLength(8192)
.verboseResponses(true)
.build((ctx, req) -> HttpResponse.of(OK)); // Return to the ServerBuilder.
// Configure the second service with Consumer.
sb.withRoute(builder -> builder.path("/baz")
.methods(HttpMethod.GET, HttpMethod.POST)
.build((ctx, req) -> HttpResponse.of(OK)));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaccessLogFormat(String accessLogFormat) accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop) addHeader(CharSequence name, Object value) addHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> defaultHeaders) Specifies an additionalRoutethat should be matched.blockingTaskExecutor(int numThreads) blockingTaskExecutor(BlockingTaskExecutor blockingTaskExecutor, boolean shutdownOnStop) blockingTaskExecutor(ScheduledExecutorService blockingTaskExecutor, boolean shutdownOnStop) build(HttpService service) Sets theHttpServiceand returns theServerBuilderthat thisServiceBindingBuilderwas created from.Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.CONNECTrequests.SetsMediaTypes that anHttpServicewill consume.SetsMediaTypes that anHttpServicewill consume.contextHook(Supplier<? extends AutoCloseable> contextHook) default ServiceBindingBuilderdecorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction) Decorates anHttpServicewith the specifieddecorator.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) Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.DELETErequests.errorHandler(ServiceErrorHandler serviceErrorHandler) Adds apathPatternthat is supposed to be excluded from theRoutes built by thisAbstractBindingBuilder.Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.GETrequests.Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.HEADrequests.matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate) Sets theRouteto accept a request when the specifiedvaluePredicateevaluatestruewith the value of the specifiedheaderNameheader.matchesHeaders(Iterable<String> headerPredicates) Sets theRouteto accept a request if it matches all the specified predicates forHttpHeaders.matchesHeaders(String... headerPredicates) Sets theRouteto accept a request if it matches all the specified predicates forHttpHeaders.matchesParams(Iterable<String> paramPredicates) Sets theRouteto accept a request if it matches all the specified predicates for HTTP parameters.matchesParams(String... paramPredicates) Sets theRouteto accept a request if it matches all the specified predicates for HTTP parameters.matchesParams(String paramName, Predicate<? super String> valuePredicate) Sets theRouteto accept a request when the specifiedvaluePredicateevaluatestruewith the value of the specifiedparamNameparameter.maxRequestLength(long maxRequestLength) methods(HttpMethod... methods) Sets theHttpMethods that anHttpServicewill support.methods(Iterable<HttpMethod> methods) Sets theHttpMethods that anHttpServicewill support.multipartRemovalStrategy(MultipartRemovalStrategy removalStrategy) multipartUploadsLocation(Path multipartUploadsLocation) Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.OPTIONSrequests.Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.PATCHrequests.Sets the path pattern that anHttpServicewill be bound to.pathPrefix(String prefix) Sets the specified prefix which is a directory that anHttpServicewill be bound under.Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.POSTrequests.SetsMediaTypes that anHttpServicewill produce to be used in content negotiation.SetsMediaTypes that anHttpServicewill produce to be used in content negotiation.Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.PUTrequests.requestAutoAbortDelay(Duration delay) requestAutoAbortDelayMillis(long delayMillis) requestIdGenerator(Function<? super RoutingContext, ? extends RequestId> requestIdGenerator) requestTimeout(Duration requestTimeout) requestTimeoutMillis(long requestTimeoutMillis) serviceWorkerGroup(int numThreads) serviceWorkerGroup(EventLoopGroup serviceWorkerGroup, boolean shutdownOnStop) setHeader(CharSequence name, Object value) setHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> defaultHeaders) successFunction(SuccessFunction successFunction) Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.TRACErequests.verboseResponses(boolean verboseResponses)
-
Method Details
-
build
Sets theHttpServiceand returns theServerBuilderthat thisServiceBindingBuilderwas created from.- Throws:
IllegalStateException- if the path that theHttpServicewill be bound to is not specified
-
requestTimeout
-
requestTimeoutMillis
-
maxRequestLength
-
verboseResponses
-
accessLogFormat
-
accessLogWriter
public ServiceBindingBuilder accessLogWriter(AccessLogWriter accessLogWriter, boolean shutdownOnStop) -
decorator
public ServiceBindingBuilder decorator(Function<? super HttpService, ? extends HttpService> decorator) -
decorators
public ServiceBindingBuilder decorators(Function<? super HttpService, ? extends HttpService>... decorators) -
decorators
public ServiceBindingBuilder decorators(Iterable<? extends Function<? super HttpService, ? extends HttpService>> decorators) -
defaultServiceName
-
defaultServiceNaming
-
defaultLogName
-
blockingTaskExecutor
public ServiceBindingBuilder blockingTaskExecutor(ScheduledExecutorService blockingTaskExecutor, boolean shutdownOnStop) -
blockingTaskExecutor
public ServiceBindingBuilder blockingTaskExecutor(BlockingTaskExecutor blockingTaskExecutor, boolean shutdownOnStop) -
blockingTaskExecutor
-
successFunction
-
requestAutoAbortDelay
-
requestAutoAbortDelayMillis
-
multipartUploadsLocation
-
multipartRemovalStrategy
-
serviceWorkerGroup
public ServiceBindingBuilder serviceWorkerGroup(EventLoopGroup serviceWorkerGroup, boolean shutdownOnStop) -
serviceWorkerGroup
-
requestIdGenerator
public ServiceBindingBuilder requestIdGenerator(Function<? super RoutingContext, ? extends RequestId> requestIdGenerator) -
addHeader
-
addHeaders
public ServiceBindingBuilder addHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> defaultHeaders) -
setHeader
-
setHeaders
public ServiceBindingBuilder setHeaders(Iterable<? extends Map.Entry<? extends CharSequence, ?>> defaultHeaders) -
errorHandler
-
contextHook
-
decorator
default ServiceBindingBuilder decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction) Decorates anHttpServicewith the specifieddecorator.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
path
Sets the path pattern that anHttpServicewill be bound to. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
pathPrefix
Sets the specified prefix which is a directory that anHttpServicewill be bound under.pathPrefix("/my/path")is identical topath("prefix:/my/path").- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
get
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.GETrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
post
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.POSTrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
put
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.PUTrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
patch
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.PATCHrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
delete
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.DELETErequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
options
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.OPTIONSrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
head
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.HEADrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
trace
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.TRACErequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
connect
Sets the path pattern that anHttpServicewill be bound to, only supportingHttpMethod.CONNECTrequests. Please refer to the Path patterns in order to learn how to specify a path pattern.- Throws:
IllegalArgumentException- if the specified path pattern is invalid
-
methods
Sets theHttpMethods that anHttpServicewill support. If not set,HttpMethod.knownMethods()s are set.- See Also:
-
methods
Sets theHttpMethods that anHttpServicewill support. If not set,HttpMethod.knownMethods()s are set.- See Also:
-
consumes
SetsMediaTypes that anHttpServicewill consume. If not set, theHttpServicewill accept all media types. -
consumes
SetsMediaTypes that anHttpServicewill consume. If not set, theHttpServicewill accept all media types. -
produces
SetsMediaTypes that anHttpServicewill produce to be used in content negotiation. See Accept header for more information. -
produces
SetsMediaTypes that anHttpServicewill produce to be used in content negotiation. See Accept header for more information. -
matchesParams
Sets theRouteto accept a request if it matches all the specified predicates for HTTP parameters. The predicate can be one of the following forms:some-param=some-valuewhich means that the request must have asome-param=some-valueparametersome-param!=some-valuewhich means that the request must not have asome-param=some-valueparametersome-paramwhich means that the request must contain asome-paramparameter!some-paramwhich means that the request must not contain asome-paramparameter
Note that these predicates can be evaluated only with the query string of the request URI. Also note that each predicate will be evaluated with the decoded value of HTTP parameters, so do not use percent-encoded value in the predicate.
- See Also:
-
matchesParams
Sets theRouteto accept a request if it matches all the specified predicates for HTTP parameters. The predicate can be one of the following forms:some-param=some-valuewhich means that the request must have asome-param=some-valueparametersome-param!=some-valuewhich means that the request must not have asome-param=some-valueparametersome-paramwhich means that the request must contain asome-paramparameter!some-paramwhich means that the request must not contain asome-paramparameter
Note that these predicates can be evaluated only with the query string of the request URI. Also note that each predicate will be evaluated with the decoded value of HTTP parameters, so do not use percent-encoded value in the predicate.
- See Also:
-
matchesParams
public ServiceBindingBuilder matchesParams(String paramName, Predicate<? super String> valuePredicate) Sets theRouteto accept a request when the specifiedvaluePredicateevaluatestruewith the value of the specifiedparamNameparameter. -
matchesHeaders
Sets theRouteto accept a request if it matches all the specified predicates forHttpHeaders. The predicate can be one of the following forms:some-header=some-valuewhich means that the request must have asome-header: some-valueheadersome-header!=some-valuewhich means that the request must not have asome-header: some-valueheadersome-headerwhich means that the request must contain asome-headerheader!some-headerwhich means that the request must not contain asome-headerheader
- See Also:
-
matchesHeaders
Sets theRouteto accept a request if it matches all the specified predicates forHttpHeaders. The predicate can be one of the following forms:some-header=some-valuewhich means that the request must have asome-header: some-valueheadersome-header!=some-valuewhich means that the request must not have asome-header: some-valuean headersome-headerwhich means that the request must contain asome-headerheader!some-headerwhich means that the request must not contain asome-headerheader
- See Also:
-
matchesHeaders
public ServiceBindingBuilder matchesHeaders(CharSequence headerName, Predicate<? super String> valuePredicate) Sets theRouteto accept a request when the specifiedvaluePredicateevaluatestruewith the value of the specifiedheaderNameheader. -
addRoute
Specifies an additionalRoutethat should be matched. -
exclude
Adds apathPatternthat is supposed to be excluded from theRoutes built by thisAbstractBindingBuilder. Please refer to Path patterns to learn more about path pattern syntax. -
exclude
-