package org.certificatetransparency.ctlog.comm;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;

/**
 * Simple delegator to HttpClient, so it can be mocked
 */
public class HttpPostInvoker {
  /**
   * Make an HTTP POST method call to the given URL with the provided JSON payload.
   * @param url URL for POST method
   * @param jsonPayload Serialized JSON payload.
   * @return Server's response body.
   */
  public String makePostRequest(String url, String jsonPayload) {
    HttpClient httpClient = new DefaultHttpClient();
    try {
      HttpPost post = new HttpPost(url);
      post.setEntity(new StringEntity(jsonPayload, "utf-8"));
      post.addHeader("Content-Type", "application/json; charset=utf-8");

      return httpClient.execute(post, new BasicResponseHandler());
    } catch (IOException e) {
      throw new LogCommunicationException("Error making POST request to " + url, e);
    } finally {
      httpClient.getConnectionManager().shutdown();
    }
  }
}

@@ -46,50 +46,8 @@
 m;%0A%0A
-import org.apache.http.client.HttpClient;%0A
 impo
@@ -90,16 +90,16 @@
 tpPost;%0A
+
 import o
@@ -226,23 +226,72 @@
 .client.
-Default
+CloseableHttpClient;%0Aimport org.apache.http.impl.client.
 HttpClie
@@ -292,16 +292,23 @@
 tpClient
+Builder
 ;%0A%0Aimpor
@@ -709,24 +709,38 @@
 load) %7B%0A    
+try (Closeable
 HttpClient h
@@ -755,40 +755,43 @@
 t = 
-new DefaultHttpClient();%0A    try
+HttpClientBuilder.create().build())
  %7B%0A 
@@ -1059,24 +1059,24 @@
 eption e) %7B%0A
+
       throw 
@@ -1152,76 +1152,8 @@
 e);%0A
-    %7D finally %7B%0A      httpClient.getConnectionManager().shutdown();%0A
     

Move away from deprecated HTTP client API after libraries update.