kontent-ai / java-packages

Delivery Java SDK for Kontent.ai including examples for Spring, Gradle, Kotlin and Java Android app
https://kontent.ai/learn/tutorials/develop-apps/overview/?tech=java
MIT License
14 stars 28 forks source link

UnknownHostException when behind a proxy #81

Closed SmootherSpike closed 4 years ago

SmootherSpike commented 5 years ago

Brief bug description

I am trying to make a call with the DeliveryClient, but because i am behind a company proxy i am not able to reach the kentico cloud

Repro steps

  1. Be behind a company proxy
  2. Execute the DeliveryClient.getItems method
  3. See this error

Caused by: java.net.UnknownHostException: preview-deliver.kenticocloud.com at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797) ~[na:na] at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505) ~[na:na] at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364) ~[na:na] at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298) ~[na:na] at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:112) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.8.jar:4.5.8] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) ~[httpclient-4.5.8.jar:4.5.8] at com.kenticocloud.delivery.DeliveryClient.lambda$executeRequest$1(DeliveryClient.java:795) ~[delivery-2.0.2.jar:na] at com.kenticocloud.delivery.DeliveryClient.lambda$new$0(DeliveryClient.java:104) ~[delivery-2.0.2.jar:na] at com.kenticocloud.delivery.DeliveryClient.executeRequest(DeliveryClient.java:794) ~[delivery-2.0.2.jar:na] at com.kenticocloud.delivery.DeliveryClient.executeRequest(DeliveryClient.java:825) ~[delivery-2.0.2.jar:na] at com.kenticocloud.delivery.DeliveryClient.executeRequest(DeliveryClient.java:825) ~[delivery-2.0.2.jar:na] at com.kenticocloud.delivery.DeliveryClient.executeRequest(DeliveryClient.java:825) ~[delivery-2.0.2.jar:na] at com.kenticocloud.delivery.DeliveryClient.executeRequest(DeliveryClient.java:783) ~[delivery-2.0.2.jar:na]

Expected behavior

Retrieve the response from the kentico could

Solution

The DeliveryClient should be able to set the system proxy of the jvm arguments, which is indeed the http client from the org.apache.httpcomponents lib

aweigold commented 4 years ago

@SmootherSpike sorry for the delay on this one. The main cause for the delay was due to the master branch swapping out apache httpcomponents for org.asynchttpclient from another PR.

I've exposed setting that library's ProxyServer via DeliveryOptions, which will be available in the upcoming 3.0.0 release.

Note, this isn't tested. Please reach out if it does not work as desired.