com.linecorp.armeria.server.HttpServiceWithRoutes Java Examples

The following examples show how to use com.linecorp.armeria.server.HttpServiceWithRoutes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArmeriaGrpcServer.java    From grpc-by-example-java with Apache License 2.0 5 votes vote down vote up
static Server newServer(int httpPort, int httpsPort) throws Exception {
    final HelloRequest exampleRequest = HelloRequest.newBuilder().setName("Armeria").build();
    final HttpServiceWithRoutes grpcService =
            GrpcService.builder()
                       .addService(new HelloServiceImpl())
                       // See https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md
                       .addService(ProtoReflectionService.newInstance())
                       .supportedSerializationFormats(GrpcSerializationFormats.values())
                       .enableUnframedRequests(true)
                       // You can set useBlockingTaskExecutor(true) in order to execute all gRPC
                       // methods in the blockingTaskExecutor thread pool.
                       // .useBlockingTaskExecutor(true)
                       .build();

    return Server.builder()
                 .http(httpPort)
                 .https(httpsPort)
                 .tlsSelfSigned()
                 .service(grpcService)
                 // You can access the documentation service at http://127.0.0.1:8080/docs.
                 // See https://line.github.io/armeria/server-docservice.html for more information.
                 .serviceUnder("/docs", DocService.builder()
                                                  .exampleRequestForMethod(HelloServiceGrpc.SERVICE_NAME,
                                                                           "Hello", exampleRequest)
                                                  .exampleRequestForMethod(HelloServiceGrpc.SERVICE_NAME,
                                                                           "LazyHello", exampleRequest)
                                                  .exampleRequestForMethod(HelloServiceGrpc.SERVICE_NAME,
                                                                           "BlockingHello", exampleRequest)
                                                  .exclude(DocServiceFilter.ofServiceName(
                                                          ServerReflectionGrpc.SERVICE_NAME))
                                                  .build())
                 .build();
}
 
Example #2
Source File: Main.java    From armeria with Apache License 2.0 5 votes vote down vote up
static Server newServer(int httpPort, int httpsPort) throws Exception {
    final HelloRequest exampleRequest = HelloRequest.newBuilder().setName("Armeria").build();
    final HttpServiceWithRoutes grpcService =
            GrpcService.builder()
                       .addService(new HelloServiceImpl())
                       // See https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md
                       .addService(ProtoReflectionService.newInstance())
                       .supportedSerializationFormats(GrpcSerializationFormats.values())
                       .enableUnframedRequests(true)
                       // You can set useBlockingTaskExecutor(true) in order to execute all gRPC
                       // methods in the blockingTaskExecutor thread pool.
                       // .useBlockingTaskExecutor(true)
                       .build();
    return Server.builder()
                 .http(httpPort)
                 .https(httpsPort)
                 .tlsSelfSigned()
                 .service(grpcService)
                 // You can access the documentation service at http://127.0.0.1:8080/docs.
                 // See https://armeria.dev/docs/server-docservice for more information.
                 .serviceUnder("/docs",
                         DocService.builder()
                                   .exampleRequestForMethod(
                                           HelloServiceGrpc.SERVICE_NAME,
                                           "Hello", exampleRequest)
                                   .exampleRequestForMethod(
                                           HelloServiceGrpc.SERVICE_NAME,
                                           "LazyHello", exampleRequest)
                                   .exampleRequestForMethod(
                                           HelloServiceGrpc.SERVICE_NAME,
                                           "BlockingHello", exampleRequest)
                                   .exclude(DocServiceFilter.ofServiceName(
                                           ServerReflectionGrpc.SERVICE_NAME))
                                   .build())
                 .build();
}
 
Example #3
Source File: Main.java    From armeria with Apache License 2.0 5 votes vote down vote up
static Server newServer(int httpPort, int httpsPort) throws Exception {
    final HelloRequest exampleRequest = HelloRequest.newBuilder().setName("Armeria").build();
    final HttpServiceWithRoutes grpcService =
            GrpcService.builder()
                       .addService(new HelloServiceImpl())
                       // See https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md
                       .addService(ProtoReflectionService.newInstance())
                       .supportedSerializationFormats(GrpcSerializationFormats.values())
                       .enableUnframedRequests(true)
                       // You can set useBlockingTaskExecutor(true) in order to execute all gRPC
                       // methods in the blockingTaskExecutor thread pool.
                       // .useBlockingTaskExecutor(true)
                       .build();
    return Server.builder()
                 .http(httpPort)
                 .https(httpsPort)
                 .tlsSelfSigned()
                 .service(grpcService)
                 // You can access the documentation service at http://127.0.0.1:8080/docs.
                 // See https://armeria.dev/docs/server-docservice for more information.
                 .serviceUnder("/docs",
                         DocService.builder()
                                   .exampleRequestForMethod(HelloServiceGrpc.SERVICE_NAME,
                                              "Hello", exampleRequest)
                                   .exampleRequestForMethod(HelloServiceGrpc.SERVICE_NAME,
                                              "LazyHello", exampleRequest)
                                   .exampleRequestForMethod(HelloServiceGrpc.SERVICE_NAME,
                                              "BlockingHello", exampleRequest)
                                   .exclude(DocServiceFilter.ofServiceName(
                                                ServerReflectionGrpc.SERVICE_NAME))
                                   .build())
                 .build();
}
 
Example #4
Source File: GrpcDocServicePluginTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static Map<String, ServiceInfo> services(DocServiceFilter include, DocServiceFilter exclude) {
    final ServerBuilder serverBuilder = Server.builder();

    // The case where a GrpcService is added to ServerBuilder without a prefix.
    final HttpServiceWithRoutes prefixlessService =
            GrpcService.builder()
                       .addService(mock(TestServiceImplBase.class))
                       .build();
    serverBuilder.service(prefixlessService);

    // The case where a GrpcService is added to ServerBuilder with a prefix.
    serverBuilder.service(
            Route.builder().pathPrefix("/test").build(),
            GrpcService.builder().addService(mock(UnitTestServiceImplBase.class)).build());

    // Another GrpcService with a different prefix.
    serverBuilder.service(
            Route.builder().pathPrefix("/reconnect").build(),
            GrpcService.builder().addService(mock(ReconnectServiceImplBase.class)).build());

    // Make sure all services and their endpoints exist in the specification.
    final ServiceSpecification specification = generator.generateSpecification(
            ImmutableSet.copyOf(serverBuilder.build().serviceConfigs()),
            unifyFilter(include, exclude));
    return specification
            .services()
            .stream()
            .collect(toImmutableMap(ServiceInfo::name, Function.identity()));
}
 
Example #5
Source File: SamlAuthProvider.java    From centraldogma with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<HttpServiceWithRoutes> moreServices() {
    return ImmutableList.of(sp.newSamlService());
}
 
Example #6
Source File: ArmeriaConfigurationUtil.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Adds gRPC services to the specified {@link ServerBuilder}.
 */
public static void configureGrpcServices(
        ServerBuilder server, DocServiceBuilder docServiceBuilder,
        List<GrpcServiceRegistrationBean> beans,
        @Nullable MeterIdPrefixFunctionFactory meterIdPrefixFunctionFactory,
        @Nullable String docsPath) {
    requireNonNull(server, "server");
    requireNonNull(docServiceBuilder, "docServiceBuilder");
    requireNonNull(beans, "beans");

    final List<GrpcExampleRequest> docServiceRequests = new ArrayList<>();
    final List<GrpcExampleHeaders> docServiceHeaders = new ArrayList<>();
    beans.forEach(bean -> {
        final HttpServiceWithRoutes serviceWithRoutes = bean.getService();
        docServiceRequests.addAll(bean.getExampleRequests());
        docServiceHeaders.addAll(bean.getExampleHeaders());
        serviceWithRoutes.routes().forEach(
                route -> {
                    HttpService service = bean.getService();
                    for (Function<? super HttpService, ? extends HttpService> decorator
                            : bean.getDecorators()) {
                        service = service.decorate(decorator);
                    }
                    server.service(route,
                                   setupMetricCollectingService(service, bean,
                                                                meterIdPrefixFunctionFactory));
                }
        );
    });

    if (Strings.isNullOrEmpty(docsPath)) {
        return;
    }

    docServiceRequests.forEach(
            exampleReq -> docServiceBuilder.exampleRequestForMethod(exampleReq.getServiceType(),
                                                                    exampleReq.getMethodName(),
                                                                    exampleReq.getExampleRequest()));
    docServiceHeaders.forEach(exampleHeader -> configureExampleHeaders(docServiceBuilder,
                                                                       exampleHeader.getServiceType(),
                                                                       exampleHeader.getMethodName(),
                                                                       exampleHeader.getHeaders()));
}
 
Example #7
Source File: SamlServiceProvider.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an {@link HttpService} which handles SAML messages.
 */
public HttpServiceWithRoutes newSamlService() {
    return new SamlService(this);
}
 
Example #8
Source File: AuthProvider.java    From centraldogma with Apache License 2.0 2 votes vote down vote up
/**
 * Returns additional {@link Service}s which are required for working this {@link AuthProvider}
 * well.
 */
default Iterable<HttpServiceWithRoutes> moreServices() {
    return ImmutableList.of();
}