Package com.linecorp.armeria.server
Class ContextPathServicesBuilder
java.lang.Object
com.linecorp.armeria.server.ContextPathServicesBuilder
Builds
ServiceConfig
s for a ServerBuilder
.
All ServiceConfig
s built by this builder will be served under the specified context paths.
Server.builder()
.contextPath("/v1", "/v2")
.service(myService) // served under "/v1" and "/v2"
-
Method Summary
Modifier and TypeMethodDescriptionand()
Returns the parentAbstractContextPathServicesBuilder
.Returns a new instance ofAbstractContextPathAnnotatedServiceConfigSetters
to build an annotated service fluently.annotatedService
(Object service) Binds the specified annotated service object under the context path.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.decorator
(DecoratingHttpServiceFunction decoratingHttpServiceFunction) Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
.decorator
(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction) decorator
(Route route, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpService
s under the specified directory.decorator
(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction) decorator
(String pathPattern, Function<? super HttpService, ? extends HttpService> decorator) decorator
(Function<? super HttpService, ? extends HttpService> decorator) Decorates allHttpService
s with the specifieddecorator
.decoratorUnder
(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpService
s under the specified directory.decoratorUnder
(String prefix, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpService
s under the specified directory.route()
Returns aContextPathServiceBindingBuilder
which is for binding anHttpService
fluently.Returns aContextPathDecoratingBindingBuilder
which is for binding adecorator
fluently.service
(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService, ? extends HttpService>> decorators) Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s under the context path.service
(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService, ? extends HttpService>... decorators) Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s under the context path.service
(Route route, HttpService service) Binds the specifiedHttpService
at the specifiedRoute
under the context path.service
(String pathPattern, HttpService service) Binds the specifiedHttpService
at the specified path pattern under the context path.serviceUnder
(String pathPrefix, HttpService service) Binds the specifiedHttpService
under the specified context path.withRoute
(Consumer<? super ContextPathServiceBindingBuilder> customizer) Configures anHttpService
under the context path with thecustomizer
.
-
Method Details
-
withRoute
public ContextPathServicesBuilder withRoute(Consumer<? super ContextPathServiceBindingBuilder> customizer) Configures anHttpService
under the context path with thecustomizer
. -
route
Returns aContextPathServiceBindingBuilder
which is for binding anHttpService
fluently. -
routeDecorator
Returns aContextPathDecoratingBindingBuilder
which is for binding adecorator
fluently. The specified decorator(s) is/are executed in reverse order of the insertion. -
serviceUnder
Binds the specifiedHttpService
under the specified context path. If the specifiedHttpService
is anHttpServiceWithRoutes
, thepathPrefix
is added to eachRoute
ofServiceWithRoutes.routes()
. For example, theserviceWithRoutes
in the following code will be bound to ("/v1/foo/bar"
) and ("/v1/foo/baz"
):> HttpServiceWithRoutes serviceWithRoutes = new HttpServiceWithRoutes() { > @Override > public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) { ... } > > @Override > public Set<Route> routes() { > return Set.of(Route.builder().path("/bar").build(), > Route.builder().path("/baz").build()); > } > }; > > Server.builder() > .contextPath("/v1") > .serviceUnder("/foo", serviceWithRoutes) > .build();
-
service
Binds the specifiedHttpService
at the specified path pattern under the context path. 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)
-
service
Binds the specifiedHttpService
at the specifiedRoute
under the context path. -
service
public ContextPathServicesBuilder service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService, ? extends HttpService>> decorators) Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s under the context path.- Parameters:
serviceWithRoutes
- theHttpServiceWithRoutes
.decorators
- the decorator functions, which will be applied in the order specified.
-
service
@SafeVarargs public final ContextPathServicesBuilder service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService, ? extends HttpService>... decorators) Decorates and binds the specifiedHttpServiceWithRoutes
at multipleRoute
s under the context path.- Parameters:
serviceWithRoutes
- theHttpServiceWithRoutes
.decorators
- the decorator functions, which will be applied in the order specified.
-
annotatedService
Binds the specified annotated service object under the context path. -
annotatedService
public ContextPathServicesBuilder annotatedService(Object service, Object... exceptionHandlersAndConverters) Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ContextPathServicesBuilder annotatedService(Object service, Function<? super HttpService, ? extends HttpService> decorator, Object... exceptionHandlersAndConverters) Binds the specified annotated service object under the path prefix"/"
.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
Binds the specified annotated service object under the specified path prefix. -
annotatedService
public ContextPathServicesBuilder annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters) Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ContextPathServicesBuilder 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
- theExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public ContextPathServicesBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters) Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters
- theExceptionHandlerFunction
s, theRequestConverterFunction
s and/or theResponseConverterFunction
s
-
annotatedService
public ContextPathServicesBuilder 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
- theExceptionHandlerFunction
,RequestConverterFunction
and/orResponseConverterFunction
-
annotatedService
public ContextPathServicesBuilder 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
- theExceptionHandlerFunction
srequestConverterFunctions
- theRequestConverterFunction
sresponseConverterFunctions
- theResponseConverterFunction
s
-
annotatedService
Returns a new instance ofAbstractContextPathAnnotatedServiceConfigSetters
to build an annotated service fluently. -
decorator
public ContextPathServicesBuilder decorator(Function<? super HttpService, ? extends HttpService> decorator) Decorates allHttpService
s with the specifieddecorator
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decorator
- theFunction
that decoratesHttpService
s
-
decorator
public ContextPathServicesBuilder decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction) Decorates allHttpService
s with the specifiedDecoratingHttpServiceFunction
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decorator
public ContextPathServicesBuilder decorator(String pathPattern, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpService
s whoseRoute
matches the specifiedpathPattern
. The specified decorator(s) is/are executed in reverse order of the insertion. -
decorator
public ContextPathServicesBuilder decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpService
s whoseRoute
matches the specifiedpathPattern
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decorator
public ContextPathServicesBuilder decorator(Route route, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpService
s under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion. -
decorator
public ContextPathServicesBuilder decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpService
s whoseRoute
matches the specifiedRoute
. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route
- the route being decorateddecoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decoratorUnder
public ContextPathServicesBuilder decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpService
s under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction
- theDecoratingHttpServiceFunction
that decoratesHttpService
s
-
decoratorUnder
public ContextPathServicesBuilder decoratorUnder(String prefix, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpService
s under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion. -
and
Returns the parentAbstractContextPathServicesBuilder
.
-