Skip to content

Commit

Permalink
Create a HTTP client with knowledge about possible proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Apr 17, 2020
1 parent 5f050ed commit f1a50ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions org.wikipathways.client/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<classpathentry kind="lib" path="lib/org.bridgedb.bio.jar"/>
<classpathentry kind="lib" path="lib/org.bridgedb.jar"/>
<classpathentry kind="lib" path="lib/org.pathvisio.core.jar"/>
<classpathentry kind="lib" path="lib/httpclient-4.5.12.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.4.13.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion org.wikipathways.client/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<javac srcdir="src"
includes="**"
destdir="${build.dir}"
debug="${debug.mode}" source="1.6" target="1.6">
debug="${debug.mode}" source="1.8" target="1.8">
<classpath refid="project.class.path"/>
</javac>
</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import java.util.Date;
import java.util.TimeZone;

import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.bridgedb.DataSource;
import org.bridgedb.Xref;
Expand Down Expand Up @@ -69,6 +72,21 @@ public class WikiPathwaysClient {
public WikiPathwaysClient(URL portAddress) {
MIMShapes.registerShapes();

HttpClientBuilder builder = HttpClientBuilder.create();
String proxyString = System.getenv("http_proxy");
try {
if (proxyString != null) {
URL proxyURL = new URL(proxyString);
HttpHost proxy = new HttpHost(proxyURL.getHost(), proxyURL.getPort());
builder.setProxy(proxy);
}
builder.setConnectionManagerShared(false);
try (CloseableHttpClient httpclient = builder.build()) {
port = new WikiPathwaysRESTBindingStub(httpclient, portAddress.toString());
}
} catch (Exception exception) {
System.out.println("ERROR while creating a HTTP client: " + exception.getMessage());
}
HttpClient httpclient = HttpClients.createDefault();
port = new WikiPathwaysRESTBindingStub(httpclient, portAddress.toString());
}
Expand Down

0 comments on commit f1a50ac

Please sign in to comment.