/** * Creates a new {@link CompositeServiceEntry} whose {@link Service} is bound at * {@linkplain PathMapping#ofCatchAll() the catch-all path mapping}. */ public static <I extends Request, O extends Response> CompositeServiceEntry<I, O> ofCatchAll(Service<I, O> service) { return new CompositeServiceEntry<>(PathMapping.ofCatchAll(), service); }
/** * Creates a new {@link PathMapping} that matches a {@linkplain ServiceRequestContext#path() path} * under the specified directory prefix. When {@code stripPrefix} is {@code true}, it also removes the * specified directory prefix from the matched path so that {@link ServiceRequestContext#path()} * does not have the specified directory prefix. For example, when {@code pathPrefix} is {@code "/foo/"}: * <ul> * <li>{@code "/foo/"} translates to {@code "/"}</li> * <li>{@code "/foo/bar"} translates to {@code "/bar"}</li> * <li>{@code "/foo/bar/baz"} translates to {@code "/bar/baz"}</li> * </ul> */ static PathMapping ofPrefix(String pathPrefix, boolean stripPrefix) { requireNonNull(pathPrefix, "pathPrefix"); if ("/".equals(pathPrefix)) { // Every path starts with '/'. return ofCatchAll(); } return new PrefixPathMapping(pathPrefix, stripPrefix); }
private static ServerBuilder configureService(ServerBuilder sb, HttpHandler httpHandler, DataBufferFactoryWrapper<?> factoryWrapper, @Nullable String serverHeader) { final ArmeriaHttpHandlerAdapter handler = new ArmeriaHttpHandlerAdapter(httpHandler, factoryWrapper); return sb.service(PathMapping.ofCatchAll(), (ctx, req) -> { final CompletableFuture<HttpResponse> future = new CompletableFuture<>(); final HttpResponse response = HttpResponse.from(future); final Disposable disposable = handler.handle(ctx, req, future, serverHeader).subscribe(); response.completionFuture().whenComplete((unused, cause) -> { if (cause != null) { logger.debug("{} Response stream has been cancelled.", ctx, cause); disposable.dispose(); } }); return response; }); }