private void listTagValues(final Message<JsonObject> message) {
   HttpClientRequest request =
       client.get(
           TAG_VALUES_URI,
           new Handler<HttpClientResponse>() {
             @Override
             public void handle(final HttpClientResponse response) {
               response.bodyHandler(
                   new Handler<Buffer>() {
                     public void handle(Buffer body) {
                       int responseCode = response.statusCode();
                       if (responseCode == 200) {
                         JsonObject responseObject = new JsonObject(body.toString());
                         sendOK(message, responseObject);
                       } else {
                         String errorMessage =
                             "error listing tag values: "
                                 + response.statusCode()
                                 + " "
                                 + response.statusMessage();
                         container.logger().error(errorMessage);
                         sendError(message, errorMessage);
                       }
                     }
                   });
             }
           });
   request.end();
 }
Exemple #2
0
  public Buffer getModule(final String moduleName) {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Buffer> mod = new AtomicReference<>();
    HttpClient client = vertx.createHttpClient();
    if (proxyHost != null) {
      client.setHost(proxyHost);
      if (proxyPort != 80) {
        client.setPort(proxyPort);
      } else {
        client.setPort(80);
      }
    } else {
      client.setHost(repoHost);
      client.setPort(repoPort);
    }
    client.exceptionHandler(
        new Handler<Exception>() {
          public void handle(Exception e) {
            log.error("Unable to connect to repository");
            latch.countDown();
          }
        });
    String uri = getRepoURI(moduleName);

    if (proxyHost != null) {
      // We use an absolute URI
      uri = new StringBuilder("http://").append(repoHost).append(uri).toString();
    }
    final String theURI = uri;
    HttpClientRequest req =
        client.get(
            uri,
            new Handler<HttpClientResponse>() {
              public void handle(HttpClientResponse resp) {
                if (resp.statusCode == 200) {
                  String msg =
                      "Downloading module "
                          + moduleName
                          + " from http://"
                          + repoHost
                          + ":"
                          + repoPort
                          + theURI;
                  if (proxyHost != null) {
                    msg += " Using proxy host " + proxyHost + ":" + proxyPort;
                  }
                  log.info(msg);
                  resp.bodyHandler(
                      new Handler<Buffer>() {
                        public void handle(Buffer buffer) {
                          mod.set(buffer);
                          latch.countDown();
                        }
                      });
                } else if (resp.statusCode == 404) {
                  latch.countDown();
                } else {
                  log.error("Failed to query repository: " + resp.statusCode);
                  latch.countDown();
                }
              }
            });
    if (proxyHost != null) {
      req.putHeader("host", proxyHost);
    } else {
      req.putHeader("host", repoHost);
    }
    req.putHeader("user-agent", "Vert.x Module Installer");
    req.end();
    while (true) {
      try {
        if (!latch.await(30, TimeUnit.SECONDS)) {
          throw new IllegalStateException("Timed out waiting to download module");
        }
        break;
      } catch (InterruptedException ignore) {
      }
    }
    return mod.get();
  }