Skip to content

Commit 27bc952

Browse files
committed
Fixing #353
1 parent 0a3fb69 commit 27bc952

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/LoadableHttpResource.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.io.IOException;
2626
import java.io.InputStream;
2727
import java.lang.ref.SoftReference;
28+
import java.net.InetSocketAddress;
29+
import java.net.Proxy;
2830
import java.net.URI;
2931
import java.util.*;
3032
import java.util.concurrent.TimeUnit;
@@ -314,6 +316,18 @@ protected boolean load(URI itemToLoad, boolean fallbackLoad) {
314316
try {
315317
OkHttpClient.Builder builder = new OkHttpClient.Builder();
316318

319+
String proxyPort = this.properties.get("proxy.port");
320+
String proxyHost = this.properties.get("proxy.host");
321+
String proxyType = this.properties.get("proxy.type");
322+
if(proxyPort != null && proxyHost != null) {
323+
if (proxyType == null) {
324+
proxyType = Proxy.Type.HTTP.name();
325+
}
326+
Proxy proxy = new Proxy(Proxy.Type.valueOf(proxyType.toUpperCase()),
327+
InetSocketAddress.createUnresolved(proxyHost, Integer.parseInt(proxyPort)));
328+
builder = builder.proxy(proxy);
329+
}
330+
317331
String connectTimeout = this.properties.get("connection.connect.timeout");
318332
if(connectTimeout != null) {
319333
int seconds = Integer.parseInt(connectTimeout);
@@ -346,23 +360,11 @@ protected boolean load(URI itemToLoad, boolean fallbackLoad) {
346360
final Request request = requestBuilder
347361
.url(itemToLoad.toString())
348362
.build();
349-
350-
// String proxyPort = this.properties.get("proxy.port");
351-
// String proxyHost = this.properties.get("proxy.host");
352-
// String proxyType = this.properties.get("proxy.type");
353-
// if(proxyType!=null){
354-
// Proxy proxy = new Proxy(Proxy.Type.valueOf(proxyType.toUpperCase()),
355-
// InetSocketAddress.createUnresolved(proxyHost, Integer.parseInt(proxyPort)));
356-
// conn = itemToLoad.toURL().openConnection(proxy);
357-
// }else{
358-
// conn = itemToLoad.toURL().openConnection();
359-
// }
360-
//
361363

362364
// conn.setRequestProperty("Accept", "application/xhtml+xml");
363365
// conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
364366
// conn.setRequestProperty("Accept-Language", "en-US,en;q=0.9");
365-
//
367+
// TODO check if any of those are necessary?
366368

367369
final Call call = client.newCall(request);
368370

0 commit comments

Comments
 (0)