Skip to content

Commit

Permalink
Merge pull request #12 from jsteltze/master
Browse files Browse the repository at this point in the history
enable proxy for HttpClient
  • Loading branch information
FriedrichFroebel authored May 27, 2020
2 parents e8a0c16 + 20fa9bc commit 3f17999
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/cmanager/network/ApacheHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,29 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;

public class ApacheHttp {

private final CloseableHttpClient httpClient = HttpClients.createDefault();
private final CloseableHttpClient httpClient;

public ApacheHttp() {
if (System.getProperty("https.proxyHost") != null) {
HttpHost httpsProxy = new HttpHost(System.getProperty("https.proxyHost"), Integer.parseInt(System.getProperty("https.proxyPort")));
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(httpsProxy);
httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build();
} else {
httpClient = HttpClients.createDefault();
}
}

public static class HttpResponse {

Expand Down

0 comments on commit 3f17999

Please sign in to comment.