Skip to content

Commit

Permalink
remove/update deprecated HTTPClient code, adding missing ciphers for SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed May 24, 2017
1 parent 121660c commit eb059bc
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/main/java/org/opentripplanner/util/HttpUtils.java
Expand Up @@ -16,6 +16,7 @@ the License, or (at your option) any later version.
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
Expand All @@ -24,14 +25,12 @@ the License, or (at your option) any later version.
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.HttpClientBuilder;

public class HttpUtils {

private static final int TIMEOUT_CONNECTION = 5000;
private static final long TIMEOUT_CONNECTION = 5000;
private static final int TIMEOUT_SOCKET = 5000;

public static InputStream getData(String url) throws IOException {
Expand Down Expand Up @@ -72,12 +71,11 @@ public static void testUrl(String url) throws IOException {
}

private static HttpClient getClient() {
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_CONNECTION);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_SOCKET);

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.setParams(httpParams);
return httpclient;
HttpClient httpClient = HttpClientBuilder.create()
.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT_SOCKET).build())
.setConnectionTimeToLive(TIMEOUT_CONNECTION, TimeUnit.MILLISECONDS)
.build();

return httpClient;
}
}

0 comments on commit eb059bc

Please sign in to comment.