Java Code Examples for com.linecorp.armeria.server.ServerBuilder#http()

The following examples show how to use com.linecorp.armeria.server.ServerBuilder#http() . 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: MockWebServerExtension.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected final void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    sb.serviceUnder("/", new MockWebService());

    configureServer(sb);
}
 
Example 2
Source File: ManagedTomcatServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    sb.serviceUnder(
            "/jsp/",
            TomcatService.builder(webAppRoot())
                         .serviceName(SERVICE_NAME)
                         .configurator(s -> Collections.addAll(tomcatServices, s.findServices()))
                         .build()
                         .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/jar/",
            TomcatService.builder(AppRootFinder.find(Future.class))
                         .serviceName("TomcatServiceTest-JAR")
                         .build()
                         .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/jar_altroot/",
            TomcatService.builder(AppRootFinder.find(Future.class), "/io/netty/util/concurrent")
                         .serviceName("TomcatServiceTest-JAR-AltRoot")
                         .build()
                         .decorate(LoggingService.newDecorator()));
}
 
Example 3
Source File: GrpcDocServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    if (TestUtil.isDocServiceDemoMode()) {
        sb.http(8080);
    }
    sb.serviceUnder("/test",
                    GrpcService.builder()
                               .addService(new TestService())
                               .supportedSerializationFormats(GrpcSerializationFormats.values())
                               .enableUnframedRequests(true)
                               .build());
    sb.serviceUnder("/docs/",
                    DocService.builder()
                              .exampleRequestForMethod(
                                    TestServiceGrpc.SERVICE_NAME,
                                    "UnaryCall",
                                    SimpleRequest.newBuilder()
                                                 .setPayload(
                                                     Payload.newBuilder()
                                                            .setBody(ByteString.copyFromUtf8("world")))
                                                 .build())
                              .injectedScript(INJECTED_HEADER_PROVIDER1, INJECTED_HEADER_PROVIDER2)
                              .injectedScriptSupplier((ctx, req) -> INJECTED_HEADER_PROVIDER3)
                              .exclude(DocServiceFilter.ofMethodName(
                                                TestServiceGrpc.SERVICE_NAME,
                                                "EmptyCall"))
                              .build()
                              .decorate(LoggingService.newDecorator()));
    sb.serviceUnder("/excludeAll/",
                    DocService.builder()
                              .exclude(DocServiceFilter.ofGrpc())
                              .build());
    sb.serviceUnder("/",
                    GrpcService.builder()
                               .addService(mock(ReconnectServiceImplBase.class))
                               .build());
}
 
Example 4
Source File: JettyServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    sb.serviceUnder(
            "/jsp/",
            JettyService.builder()
                        .handler(newWebAppContext())
                        .configurator(s -> jettyBeans.addAll(s.getBeans()))
                        .build()
                        .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/default/",
            JettyService.builder()
                        .handler(new DefaultHandler())
                        .build());

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(webAppRoot().getPath());
    sb.serviceUnder(
            "/resources/",
            JettyService.builder()
                        .handler(resourceHandler)
                        .build());
}
 
Example 5
Source File: JettyServiceStartupTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    sb.serviceUnder(
            "/jsp/",
            JettyService.builder()
                        .handler(newWebAppContext())
                        .configurator(s -> jettyBeans.addAll(s.getBeans()))
                        .build()
                        .decorate(LoggingService.newDecorator()));

    sb.serviceUnder(
            "/default/",
            JettyService.builder()
                        .handler(new DefaultHandler())
                        .build());

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(WebAppContainerTest.webAppRoot().getPath());
    sb.serviceUnder(
            "/resources/",
            JettyService.builder()
                        .handler(resourceHandler)
                        .build());
}
 
Example 6
Source File: UnmanagedJettyServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    jetty = new Server(0);
    jetty.setHandler(JettyServiceTest.newWebAppContext());
    jetty.start();
    sb.serviceUnder(
            "/jsp/",
            JettyService.of(jetty).decorate(LoggingService.newDecorator()));
}
 
Example 7
Source File: HealthCheckedEndpointGroupIntegrationTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();
    sb.service(HEALTH_CHECK_PATH, HealthCheckService.builder().longPolling(0).build());
}
 
Example 8
Source File: GrpcClientTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) {
    sb.workerGroup(EventLoopGroups.newEventLoopGroup(1), true);
    sb.maxRequestLength(MAX_MESSAGE_SIZE);
    sb.idleTimeoutMillis(0);
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    final ServerServiceDefinition interceptService =
            ServerInterceptors.intercept(
                    new TestServiceImpl(Executors.newSingleThreadScheduledExecutor()),
                    new ServerInterceptor() {
                        @Override
                        public <REQ, RESP> Listener<REQ> interceptCall(
                                ServerCall<REQ, RESP> call,
                                Metadata requestHeaders,
                                ServerCallHandler<REQ, RESP> next) {
                            final HttpHeadersBuilder fromClient = HttpHeaders.builder();
                            MetadataUtil.fillHeaders(requestHeaders, fromClient);
                            CLIENT_HEADERS_CAPTURE.set(fromClient.build());
                            return next.startCall(
                                    new SimpleForwardingServerCall<REQ, RESP>(call) {
                                        @Override
                                        public void close(Status status, Metadata trailers) {
                                            trailers.merge(requestHeaders);
                                            super.close(status, trailers);
                                        }
                                    }, requestHeaders);
                        }
                    });

    sb.serviceUnder("/",
                    GrpcService.builder()
                               .addService(interceptService)
                               .setMaxInboundMessageSizeBytes(MAX_MESSAGE_SIZE)
                               .setMaxOutboundMessageSizeBytes(MAX_MESSAGE_SIZE)
                               .useClientTimeoutHeader(false)
                               .build()
                               .decorate((client, ctx, req) -> {
                                   final HttpResponse res = client.serve(ctx, req);
                                   return new FilteredHttpResponse(res) {
                                       private boolean headersReceived;

                                       @Override
                                       protected HttpObject filter(HttpObject obj) {
                                           if (obj instanceof HttpHeaders) {
                                               if (!headersReceived) {
                                                   headersReceived = true;
                                               } else {
                                                   SERVER_TRAILERS_CAPTURE.set((HttpHeaders) obj);
                                               }
                                           }
                                           return obj;
                                       }
                                   };
                               }));
}
 
Example 9
Source File: ThriftDocServiceTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    if (TestUtil.isDocServiceDemoMode()) {
        sb.http(8080);
    }
    final THttpService helloAndSleepService =
            THttpService.builder()
                        .addService("hello", HELLO_SERVICE_HANDLER)
                        .addService("sleep", SLEEP_SERVICE_HANDLER)
                        .build();
    final THttpService fooService =
            THttpService.ofFormats(mock(FooService.AsyncIface.class), COMPACT);
    final THttpService cassandraService =
            THttpService.ofFormats(mock(Cassandra.AsyncIface.class), BINARY);
    final THttpService cassandraServiceDebug =
            THttpService.ofFormats(mock(Cassandra.AsyncIface.class), TEXT);
    final THttpService hbaseService =
            THttpService.of(mock(Hbase.AsyncIface.class));
    final THttpService onewayHelloService =
            THttpService.of(mock(OnewayHelloService.AsyncIface.class));

    sb.service("/", helloAndSleepService);
    sb.service("/foo", fooService);
    // Add a service with serviceUnder() to test whether prefix mapping is detected.
    sb.serviceUnder("/foo", fooService);
    sb.service("/cassandra", cassandraService);
    sb.service("/cassandra/debug", cassandraServiceDebug);
    sb.service("/hbase", hbaseService);
    sb.service("/oneway", onewayHelloService);

    sb.serviceUnder("/docs/",
            DocService.builder()
                      .exampleHttpHeaders(EXAMPLE_HEADERS_ALL)
                      .exampleHttpHeaders(HelloService.class, EXAMPLE_HEADERS_HELLO)
                      .exampleHttpHeaders(FooService.class, EXAMPLE_HEADERS_FOO)
                      .exampleHttpHeaders(FooService.class, "bar1", EXAMPLE_HEADERS_FOO_BAR1)
                      .exampleRequest(EXAMPLE_HELLO)
                      .build());
    sb.serviceUnder("/excludeAll/",
            DocService.builder()
                      .exclude(DocServiceFilter.ofThrift())
                      .build());
}
 
Example 10
Source File: Server.java    From rpc-benchmark with Apache License 2.0 3 votes vote down vote up
public static void main(String[] args) throws Exception {
	ServerBuilder sb = new ServerBuilder();

	// Configure an HTTP port.
	sb.http(new InetSocketAddress("benchmark-server", 8080));

	// Using an annotated service object:
	sb.annotatedService(new ArmeriaUserServiceServerImpl());

	sb.build().start().join();

}