/** * Binds the specified annotated service object under the specified path prefix. * * @param exceptionHandlersAndConverters an iterable object of {@link ExceptionHandlerFunction}, * {@link RequestConverterFunction} and/or * {@link ResponseConverterFunction} */ public ServerBuilder annotatedService(String pathPrefix, Object service, Iterable<?> exceptionHandlersAndConverters) { return annotatedService(pathPrefix, service, Function.identity(), exceptionHandlersAndConverters); }
/** * Binds the specified annotated service object under the path prefix {@code "/"}. */ public ServerBuilder annotatedService(Object service) { return annotatedService("/", service, Function.identity(), ImmutableList.of()); }
/** * Binds the specified annotated service object under the specified path prefix. */ public ServerBuilder annotatedService(String pathPrefix, Object service) { return annotatedService(pathPrefix, service, Function.identity(), ImmutableList.of()); }
/** * Binds the specified annotated service object under the path prefix {@code "/"}. * * @param exceptionHandlersAndConverters instances of {@link ExceptionHandlerFunction}, * {@link RequestConverterFunction} and/or * {@link ResponseConverterFunction} */ public ServerBuilder annotatedService(Object service, Object... exceptionHandlersAndConverters) { return annotatedService("/", service, Function.identity(), ImmutableList.copyOf(requireNonNull(exceptionHandlersAndConverters, "exceptionHandlersAndConverters"))); }
/** * Binds the specified annotated service object under the specified path prefix. * * @param exceptionHandlersAndConverters instances of {@link ExceptionHandlerFunction}, * {@link RequestConverterFunction} and/or * {@link ResponseConverterFunction} */ public ServerBuilder annotatedService(String pathPrefix, Object service, Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator, Object... exceptionHandlersAndConverters) { return annotatedService(pathPrefix, service, decorator, ImmutableList.copyOf(requireNonNull(exceptionHandlersAndConverters, "exceptionHandlersAndConverters"))); }
/** * Binds the specified annotated service object under the specified path prefix. * * @param exceptionHandlersAndConverters instances of {@link ExceptionHandlerFunction}, * {@link RequestConverterFunction} and/or * {@link ResponseConverterFunction} */ public ServerBuilder annotatedService(String pathPrefix, Object service, Object... exceptionHandlersAndConverters) { return annotatedService(pathPrefix, service, Function.identity(), ImmutableList.copyOf(requireNonNull(exceptionHandlersAndConverters, "exceptionHandlersAndConverters"))); }
/** * Binds the specified annotated service object under the path prefix {@code "/"}. * * @param exceptionHandlersAndConverters instances of {@link ExceptionHandlerFunction}, * {@link RequestConverterFunction} and/or * {@link ResponseConverterFunction} */ public ServerBuilder annotatedService(Object service, Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator, Object... exceptionHandlersAndConverters) { return annotatedService("/", service, decorator, ImmutableList.copyOf(requireNonNull(exceptionHandlersAndConverters, "exceptionHandlersAndConverters"))); }
/** * Returns a new {@link Server} instance configured with annotated HTTP services. * * @param port the port that the server is to be bound to */ public static Server of(int port) { final ServerBuilder sb = new ServerBuilder(); return sb.http(port) .annotatedService("/pathPattern", new PathPatternService()) .annotatedService("/injection", new InjectionService()) .annotatedService("/messageConverter", new MessageConverterService()) .annotatedService("/exception", new ExceptionHandlerService()) .build(); }
@Override protected void configure(ServerBuilder sb) throws Exception { sb.annotatedService(new Object() { @Get("/foo") public HttpResponse foo(ServiceRequestContext ctx, HttpRequest req) {
@Override protected void configure(ServerBuilder sb) throws Exception { sb.annotatedService("/maybe", new Object() { @Get("/string") public Maybe<String> string() { sb.annotatedService("/single", new Object() { @Get("/string") public Single<String> string() { sb.annotatedService("/completable", new Object() { @Get("/done") public Completable done() { sb.annotatedService("/observable", new Object() { @Get("/string") @ProducesText sb.annotatedService("/streaming", new Object() { @Get("/json") @ProducesJsonSequences sb.annotatedService("/failure", new Object() { @Get("/immediate1") public Observable<String> immediate1() {
/** * Adds annotated HTTP services to the specified {@link ServerBuilder}. */ public static void configureAnnotatedHttpServices( ServerBuilder server, List<AnnotatedServiceRegistrationBean> beans, @Nullable MeterIdPrefixFunctionFactory meterIdPrefixFunctionFactory) { requireNonNull(server, "server"); requireNonNull(beans, "beans"); beans.forEach(bean -> { Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator = Function.identity(); for (Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> d : bean.getDecorators()) { decorator = decorator.andThen(d); } if (meterIdPrefixFunctionFactory != null) { decorator = decorator.andThen( metricCollectingServiceDecorator(bean, meterIdPrefixFunctionFactory)); } final ImmutableList<Object> exceptionHandlersAndConverters = ImmutableList.builder() .addAll(bean.getExceptionHandlers()) .addAll(bean.getRequestConverters()) .addAll(bean.getResponseConverters()) .build(); server.annotatedService(bean.getPathPrefix(), bean.getService(), decorator, exceptionHandlersAndConverters); }); }
/** * Adds annotated HTTP services to the specified {@link ServerBuilder}. */ public static void configureAnnotatedHttpServices( ServerBuilder server, List<AnnotatedServiceRegistrationBean> beans, @Nullable MeterIdPrefixFunctionFactory meterIdPrefixFunctionFactory) { requireNonNull(server, "server"); requireNonNull(beans, "beans"); beans.forEach(bean -> { Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator = Function.identity(); for (Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> d : bean.getDecorators()) { decorator = decorator.andThen(d); } if (meterIdPrefixFunctionFactory != null) { decorator = decorator.andThen( metricCollectingServiceDecorator(bean, meterIdPrefixFunctionFactory)); } final ImmutableList<Object> exceptionHandlersAndConverters = ImmutableList.builder() .addAll(bean.getExceptionHandlers()) .addAll(bean.getRequestConverters()) .addAll(bean.getResponseConverters()) .build(); server.annotatedService(bean.getPathPrefix(), bean.getService(), decorator, exceptionHandlersAndConverters); }); }
public static void main(String[] args) throws Exception { final SamlServiceProvider ssp = samlServiceProvider(); final Server server = new ServerBuilder() .https(8443) // You can add this certificate to your trust store in order to make your web browser happy. .tls(new File(ClassLoader.getSystemResource("localhost.crt").toURI()), new File(ClassLoader.getSystemResource("localhost.key").toURI())) // Decorate you service with SAML decorator. .annotatedService("/", new MyService(), ssp.newSamlDecorator()) // Add SAML service to your server which handles a SAML response and a metadata request. .service(ssp.newSamlService()) .build(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { server.stop().join(); logger.info("Server has been stopped."); })); server.start().join(); logger.info("Server has been started."); } }
.annotatedService("/", new Object() { @Get("/{bindingProtocol}") public String root() {
sb.annotatedService(API_V1_PATH_PREFIX, new AdministrativeService(safePm, executor), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new ProjectServiceV1(safePm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new RepositoryServiceV1(safePm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new ContentServiceV1(safePm, executor, watchService), decorator, v1RequestConverter, v1ResponseConverter); final AuthConfig authCfg = cfg.authConfig(); assert authCfg != null : "authCfg"; sb.annotatedService(API_V1_PATH_PREFIX, new MetadataApiService(mds, authCfg.loginNameNormalizer()), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new TokenService(pm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V0_PATH_PREFIX, new UserService(safePm, executor), decorator, httpApiV0Converter) .annotatedService(API_V0_PATH_PREFIX, new RepositoryService(safePm, executor), decorator, httpApiV0Converter);
sb.annotatedService(API_V1_PATH_PREFIX, new AdministrativeService(safePm, executor), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new ProjectServiceV1(safePm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new RepositoryServiceV1(safePm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new ContentServiceV1(safePm, executor, watchService), decorator, v1RequestConverter, v1ResponseConverter); final AuthConfig authCfg = cfg.authConfig(); assert authCfg != null : "authCfg"; sb.annotatedService(API_V1_PATH_PREFIX, new MetadataApiService(mds, authCfg.loginNameNormalizer()), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new TokenService(pm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V0_PATH_PREFIX, new UserService(safePm, executor), decorator, httpApiV0Converter) .annotatedService(API_V0_PATH_PREFIX, new RepositoryService(safePm, executor), decorator, httpApiV0Converter);
sb.annotatedService(API_V1_PATH_PREFIX, new AdministrativeService(safePm, executor), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new ProjectServiceV1(safePm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new RepositoryServiceV1(safePm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new ContentServiceV1(safePm, executor, watchService), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new MetadataApiService(mds, loginNameNormalizer), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(API_V1_PATH_PREFIX, new TokenService(pm, executor, mds), decorator, v1RequestConverter, v1ResponseConverter); sb.annotatedService(apiV0PathPrefix, new UserService(safePm, executor), decorator, httpApiV0Converter) .annotatedService(apiV0PathPrefix, new RepositoryService(safePm, executor), decorator, httpApiV0Converter);
meterIdPrefixFuncFactory.get(METER_TYPE, bean.getServiceName()))); server.annotatedService(bean.getPathPrefix(), bean.getService(), decorator); }));
meterIdPrefixFuncFactory.get(METER_TYPE, bean.getServiceName()))); server.annotatedService(bean.getPathPrefix(), bean.getService(), decorator); }));
MetadataServiceInjector.newDecorator(mds).andThen(HttpAuthService.newDecorator( new ApplicationTokenAuthorizer(mds::findTokenBySecret))); sb.annotatedService(new Object() { @Get("/projects/{projectName}") @RequiresRole(roles = { ProjectRole.OWNER, ProjectRole.MEMBER })