Пример #1
0
  protected void putContent(String path, String content) throws Exception {
    String url = formatUrl(CONTENT_MGMT_PATH, path);
    HttpPut put = new HttpPut(url);
    put.setEntity(new StringEntity(content));

    CloseableHttpClient client = null;
    try {
      client = factory.createClient();
      CloseableHttpResponse response = client.execute(put);
      int code = response.getStatusLine().getStatusCode();
      if (code != 200 && code != 201) {
        String extra = "";
        if (response.getEntity() != null) {
          String body = IOUtils.toString(response.getEntity().getContent());
          extra = "\nBody:\n\n" + body;
        }

        Assert.fail(
            "Failed to put content to: "
                + path
                + ".\nURL: "
                + url
                + "\nStatus: "
                + response.getStatusLine()
                + extra);
      }
    } finally {
      IOUtils.closeQuietly(client);
    }
  }
Пример #2
0
 protected void withNewClient(Consumer<CloseableHttpClient> consumer) {
   CloseableHttpClient client = null;
   FileOutputStream stream = null;
   try {
     client = factory.createClient();
     consumer.accept(client);
   } catch (Exception err) {
     System.out.println("Failed to retrieve server logs after error. Reason: " + err.getMessage());
     err.printStackTrace();
   } finally {
     IOUtils.closeQuietly(client);
   }
 }
Пример #3
0
  @After
  public void teardown() throws Exception {
    if (downloadContainerConfigs()) {
      System.out.println("Downloading httpd logs to: " + downloadDir);

      List<String> paths =
          Arrays.asList(
              "clients/%s/serverca.crt",
              "clients/%s/clientca.crt",
              "clients/%s/client.crt",
              "clients/%s/client.pem",
              "httpd/conf/httpd.conf",
              "httpd/conf.d/kojihub.conf",
              "httpd/conf.d/test-accessories.conf",
              "logs/httpd/error_log",
              "logs/httpd/ssl_error_log",
              "logs/httpd/access_log",
              "logs/httpd/ssl_access_log",
              "logs/httpd/ssl_request_log");

      withNewClient(
          (client) -> {
            paths.forEach(
                (path) -> {
                  if (path.contains("%s")) {
                    path = String.format(path, getKojiUser());
                  }

                  downloadFile(path, client);
                });
          });
    }

    factory.close();
    System.out.println("\n\n #### END: " + name.getMethodName() + "#### \n\n");
  }