Package com.linecorp.armeria.server
Class ContextPathServicesBuilder
java.lang.Object
com.linecorp.armeria.server.ContextPathServicesBuilder
Builds
ServiceConfigs for a ServerBuilder.
All ServiceConfigs 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 ofAbstractContextPathAnnotatedServiceConfigSettersto 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 allHttpServices with the specifiedDecoratingHttpServiceFunction.decorator(Route route, DecoratingHttpServiceFunction decoratingHttpServiceFunction) decorator(Route route, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpServices 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 allHttpServices with the specifieddecorator.decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpServices under the specified directory.decoratorUnder(String prefix, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpServices under the specified directory.route()Returns aContextPathServiceBindingBuilderwhich is for binding anHttpServicefluently.Returns aContextPathDecoratingBindingBuilderwhich is for binding adecoratorfluently.service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService, ? extends HttpService>> decorators) Decorates and binds the specifiedHttpServiceWithRoutesat multipleRoutes under the context path.service(HttpServiceWithRoutes serviceWithRoutes, Function<? super HttpService, ? extends HttpService>... decorators) Decorates and binds the specifiedHttpServiceWithRoutesat multipleRoutes under the context path.service(Route route, HttpService service) Binds the specifiedHttpServiceat the specifiedRouteunder the context path.service(String pathPattern, HttpService service) Binds the specifiedHttpServiceat the specified path pattern under the context path.serviceUnder(String pathPrefix, HttpService service) Binds the specifiedHttpServiceunder the specified context path.withRoute(Consumer<? super ContextPathServiceBindingBuilder> customizer) Configures anHttpServiceunder the context path with thecustomizer.
-
Method Details
-
withRoute
public ContextPathServicesBuilder withRoute(Consumer<? super ContextPathServiceBindingBuilder> customizer) Configures anHttpServiceunder the context path with thecustomizer. -
route
Returns aContextPathServiceBindingBuilderwhich is for binding anHttpServicefluently. -
routeDecorator
Returns aContextPathDecoratingBindingBuilderwhich is for binding adecoratorfluently. The specified decorator(s) is/are executed in reverse order of the insertion. -
serviceUnder
Binds the specifiedHttpServiceunder the specified context path. If the specifiedHttpServiceis anHttpServiceWithRoutes, thepathPrefixis added to eachRouteofServiceWithRoutes.routes(). For example, theserviceWithRoutesin 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 specifiedHttpServiceat 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 specifiedHttpServiceat the specifiedRouteunder the context path. -
service
public ContextPathServicesBuilder service(HttpServiceWithRoutes serviceWithRoutes, Iterable<? extends Function<? super HttpService, ? extends HttpService>> decorators) Decorates and binds the specifiedHttpServiceWithRoutesat multipleRoutes 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 specifiedHttpServiceWithRoutesat multipleRoutes 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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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,RequestConverterFunctionand/orResponseConverterFunction
-
annotatedService
public ContextPathServicesBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters) Binds the specified annotated service object under the specified path prefix.- Parameters:
exceptionHandlersAndConverters- theExceptionHandlerFunctions, theRequestConverterFunctions and/or theResponseConverterFunctions
-
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,RequestConverterFunctionand/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- theExceptionHandlerFunctionsrequestConverterFunctions- theRequestConverterFunctionsresponseConverterFunctions- theResponseConverterFunctions
-
annotatedService
Returns a new instance ofAbstractContextPathAnnotatedServiceConfigSettersto build an annotated service fluently. -
decorator
public ContextPathServicesBuilder decorator(Function<? super HttpService, ? extends HttpService> decorator) Decorates allHttpServices with the specifieddecorator. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decorator- theFunctionthat decoratesHttpServices
-
decorator
public ContextPathServicesBuilder decorator(DecoratingHttpServiceFunction decoratingHttpServiceFunction) Decorates allHttpServices with the specifiedDecoratingHttpServiceFunction. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decorator
public ContextPathServicesBuilder decorator(String pathPattern, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpServices whoseRoutematches the specifiedpathPattern. The specified decorator(s) is/are executed in reverse order of the insertion. -
decorator
public ContextPathServicesBuilder decorator(String pathPattern, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpServices whoseRoutematches the specifiedpathPattern. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decorator
public ContextPathServicesBuilder decorator(Route route, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpServices 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) DecoratesHttpServices whoseRoutematches the specifiedRoute. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
route- the route being decorateddecoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decoratorUnder
public ContextPathServicesBuilder decoratorUnder(String prefix, DecoratingHttpServiceFunction decoratingHttpServiceFunction) DecoratesHttpServices under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion.- Parameters:
decoratingHttpServiceFunction- theDecoratingHttpServiceFunctionthat decoratesHttpServices
-
decoratorUnder
public ContextPathServicesBuilder decoratorUnder(String prefix, Function<? super HttpService, ? extends HttpService> decorator) DecoratesHttpServices under the specified directory. The specified decorator(s) is/are executed in reverse order of the insertion. -
and
Returns the parentAbstractContextPathServicesBuilder.
-