Skip to content

Commit

Permalink
Java: Using CloseableHttpClient instead HttpClient to get rid of depr…
Browse files Browse the repository at this point in the history
…ecated method calls
  • Loading branch information
barancev committed Apr 7, 2016
1 parent 7d8e205 commit a01061a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
Expand All @@ -46,17 +47,16 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class ApacheHttpClient implements org.openqa.selenium.remote.http.HttpClient {

private static final int MAX_REDIRECTS = 10;

private final URL url;
private final HttpHost targetHost;
private final HttpClient client;
private final CloseableHttpClient client;

public ApacheHttpClient(HttpClient client, URL url) {
public ApacheHttpClient(CloseableHttpClient client, URL url) {
this.client = checkNotNull(client, "null HttpClient");
this.url = checkNotNull(url, "null URL");

Expand Down Expand Up @@ -234,7 +234,7 @@ public Factory(HttpClientFactory clientFactory) {
@Override
public org.openqa.selenium.remote.http.HttpClient createClient(URL url) {
checkNotNull(url, "null URL");
HttpClient client;
CloseableHttpClient client;
if (url.getUserInfo() != null) {
UsernamePasswordCredentials credentials =
new UsernamePasswordCredentials(url.getUserInfo());
Expand All @@ -252,10 +252,10 @@ private static synchronized HttpClientFactory getDefaultHttpClientFactory() {
return defaultClientFactory;
}
}

@Override
public void close() throws IOException {
client.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS);
client.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected static HttpClientConnectionManager getClientConnectionManager() {
return cm;
}

public HttpClient getHttpClient() {
public CloseableHttpClient getHttpClient() {
return httpClient;
}

Expand Down

0 comments on commit a01061a

Please sign in to comment.