Skip to content

Added Code in HttpService.java to make connection via proxy #140

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion splunk/com/splunk/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class HttpService {
private static SSLSocketFactory sslSocketFactory = createSSLFactory();
private static String HTTPS_SCHEME = "https";
private static String HTTP_SCHEME = "http";
private static String HTTP_PROXY_HOST= System.getenv("httpProxyHost");
private static String HTTP_PROXY_PORT= System.getenv("httpProxyPort");


private static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() {
public boolean verify(String s, SSLSession sslSession) {
Expand Down Expand Up @@ -402,7 +405,13 @@ public ResponseMessage send(String path, RequestMessage request) {
// Create and initialize the connection object
HttpURLConnection cn;
try {
cn = (HttpURLConnection) url.openConnection();
System.out.println("Proxy Host: " + HTTP_PROXY_HOST + "Proxy Port: " + HTTP_PROXY_PORT );
if( HTTP_PROXY_HOST !=null && HTTP_PROXY_HOST!="" && HTTP_PROXY_PORT !=null && HTTP_PROXY_PORT !="") {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(HTTP_PROXY_HOST, Integer.parseInt(HTTP_PROXY_PORT)));
cn = (HttpURLConnection) url.openConnection(proxy);
}else {
cn = (HttpURLConnection) url.openConnection();
}
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
Expand Down