Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable proxy for HttpClient #12

Merged
merged 1 commit into from
May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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