Esempio n. 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);
    }
  }
Esempio n. 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);
   }
 }