private String postRequest()

in src/main/java/com/cisco/gerrit/plugins/slack/client/WebhookClient.java [96:127]


  private String postRequest(String message, String webhookUrl) {
    String response;

    HttpURLConnection connection;
    connection = null;
    try {
      connection = openConnection(webhookUrl);
      try {
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("charset", "utf-8");

        connection.setDoInput(true);
        connection.setDoOutput(true);

        try (DataOutputStream request = new DataOutputStream(connection.getOutputStream())) {
          request.write(message.getBytes(StandardCharsets.UTF_8));
          request.flush();
        }
      } catch (IOException e) {
        throw new RuntimeException("Error posting message to Slack: [" + e.getMessage() + "].", e);
      }

      response = getResponse(connection);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }

    return response;
  }