Ejemplo n.º 1
0
  public static void main(String... args) throws Exception {

    final AdminBuilder adminBuilder = AdminBuilder.adminBuilder();

    final ServiceEndpointServer adminServer = adminBuilder.build();

    adminServer.startServer();

    final HealthServiceAsync healthService = adminBuilder.getHealthService();
    healthService.register("foo", 1, TimeUnit.DAYS);
    healthService.checkInOk("foo");
    healthService.register("bar", 1, TimeUnit.DAYS);
    healthService.checkInOk("bar");

    healthService.clientProxyFlush();

    Sys.sleep(100);
    final HttpClient client =
        HttpClientBuilder.httpClientBuilder().setPort(adminBuilder.getPort()).buildAndStart();

    final HttpResponse httpResponse = client.get("/services/qbit-admin/ok");

    puts(httpResponse.body());

    final HttpResponse httpResponsePage = client.get("/qbit/admin.html");

    puts(httpResponsePage.body());
  }
Ejemplo n.º 2
0
  @Test
  public void test() throws Exception {

    final int openPortStartAt = PortUtils.findOpenPortStartAt(7777);
    HttpServer server = HttpServerBuilder.httpServerBuilder().setPort(openPortStartAt).build();

    server.setHttpRequestConsumer(
        serverRequest -> {
          final MultiMap<String, String> headers = MultiMap.multiMap();

          headers.add("foo", "bar").add("foo", "baz");
          serverRequest.getReceiver().response(200, "application/json", "true", headers);
        });

    server.startServer();

    HttpClient client =
        HttpClientBuilder.httpClientBuilder().setPort(openPortStartAt).setHost("localhost").build();

    client.start();

    final HttpTextResponse httpResponse = client.get("/hi");

    Sys.sleep(1000);
    puts(httpResponse.headers());

    boolean foundFoo = httpResponse.headers().keySet().contains("foo");
    assertTrue(foundFoo);
  }