コード例 #1
0
  public static void server(int port, ActorSystem system) {
    /* */
    final Materializer materializer = ActorMaterializer.create(system);

    Http
        /* */
        .get(system)
        /* */
        .bind("localhost", port, materializer)
        /* */
        .to(
            Sink
                /* */
                .foreach(
                connection ->
                    /* */
                    connection.handleWith(
                        /* */
                        Flow.of(HttpRequest.class)
                            /* */
                            .map(
                                request -> {
                                  /* */
                                  if (request.method() == HttpMethods.GET
                                      && request.getUri().path().equals("/")) {
                                    /* */
                                    return HttpResponse.create()
                                        .withEntity(
                                            MediaTypes.TEXT_HTML.toContentType(), "Hello world!");
                                  }
                                  /* */
                                  return HttpResponse.create().withStatus(404);
                                }),
                        materializer)))
        /* */
        .run(materializer);
  }
コード例 #2
0
  public static void client(int port, ActorSystem system) {
    final ActorMaterializer materializer = ActorMaterializer.create(system);

    // Todo display in logger
    Http.get(system).singleRequest(HttpRequest.create("localhost:" + port), materializer);
  }