Source:
private boolean post(final JSONObject payload, final String type) { if(this.isDefaultIntakeConnectionBroken()){ logger.severe("Your client is not initialized properly"); return false; } String urlParameters = "?api_key=" + Secret.toString(this.getApiKey()); HttpURLConnection conn = null; boolean status = true; try { logger.fine("Setting up HttpURLConnection..."); conn = getHttpURLConnection(new URL(this.getUrl() + type + urlParameters)); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream(), "utf-8"); logger.fine("Writing to OutputStreamWriter..."); wr.write(payload.toString()); wr.close(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); JSONObject json = (JSONObject) JSONSerializer.toJSON(result.toString()); if ("ok".equals(json.getString("status"))) { logger.fine(String.format("API call of type '%s' was sent successfully!", type)); logger.fine(String.format("Payload: %s", payload)); } else { logger.severe(String.format("API call of type '%s' failed!", type)); logger.severe(String.format("Payload: %s", payload)); status = false; } } catch (Exception e) { try { if (conn != null && conn.getResponseCode() == HTTP_FORBIDDEN) { logger.severe("Hmmm, your API key may be invalid. We received a 403 error."); DatadogUtilities.severe(logger, e, null); } else { DatadogUtilities.severe(logger, e, "Client error"); } } catch (IOException ex) { DatadogUtilities.severe(logger, e, null); } status = false; } finally { if (conn != null) { conn.disconnect(); } } return status; }

Target:
private boolean post(final JSONObject payload, final String type) { if(this.isDefaultIntakeConnectionBroken()){ logger.severe("Your client is not initialized properly"); return false; } String urlParameters = "?api_key=" + Secret.toString(this.getApiKey()); HttpURLConnection conn = null; boolean status = true; try { logger.fine("Setting up HttpURLConnection..."); conn = getHttpURLConnection(new URL(this.getUrl() + type + urlParameters)); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream(), "utf-8"); logger.fine("Writing to OutputStreamWriter..."); wr.write(payload.toString()); wr.close(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); JSONObject json = (JSONObject) JSONSerializer.toJSON(result.toString()); if ("ok".equals(json.getString("status"))) { logger.fine(String.format("API call of type '%s' was sent successfully!", type)); logger.fine(String.format("Payload: %s", payload)); } else { logger.severe(String.format("API call of type '%s' failed!", type)); logger.fine(String.format("Payload: %s", payload)); status = false; } } catch (Exception e) { try { if (conn != null && conn.getResponseCode() == HTTP_FORBIDDEN) { logger.severe("Hmmm, your API key may be invalid. We received a 403 error."); DatadogUtilities.severe(logger, e, null); } else { DatadogUtilities.severe(logger, e, "Client error"); } } catch (IOException ex) { DatadogUtilities.severe(logger, e, null); } status = false; } finally { if (conn != null) { conn.disconnect(); } } return status; }