0

We have a private space and gave access to one of the internal API so that we could access it from the private space app. So, we've developed a demo Java app to test it. When we try to connect the service with an HTTP Get the stack trace ends like this.

java.net.UnknownHostException: [THE_VALID_URL] Name or service not known
java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1519)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1509)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1368)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1302)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)

When we ping the corresponding IP within the private space we can see that it's up. But when we try to access the service from the Java application it ends up like above.

The Java code is like this:

RequestConfig config = RequestConfig.DEFAULT;
HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();

HttpGet httpGet = new HttpGet("[THE_VALID_URL]");
httpGet.addHeader("Content-Type", "application/json; UTF-8");

HttpResponse resp = client.execute(httpGet);

Does anyone have any ideas to solve this?

Thank you.

[UPDATE]: Solved with this https://stackoverflow.com/a/35327982/7595094

Mshn
  • 1
  • 2
  • Should't you replace `THE_VALID_URL ` with the actual URL you want to invoke? – Beppe C Mar 23 '22 at 08:13
  • Yes, in the actual code it has the correct address. Since it's a private URL I just wanted to hide it when posting the question. But we made sure that the URL is valid, indeed. – Mshn Mar 23 '22 at 08:31

1 Answers1

0

Seems to be an issue with DNS name resolution. In the private space heroku documentation, it is mentioned

All dyno-to-dyno communication in Private Spaces takes places via the private network. 
To communicate via the private network, your process needs to bind to its dyno’s private IP address on a port between 1024 and 65535. 
The HEROKU_PRIVATE_IP environment variable contains your dyno’s private IP address.
After your process binds to the private IP address, it’s reachable on the chosen port via its DNS name and port. 
The above example would be available on this URL:

http://foo.[APP_NAME].app.localspace:5000/

So you could try binding your API to your private IP + static port, and use this http://foo.[APP_NAME].app.localspace:5000/ format as a URL to make the GET request from your java app

Nilay Shah
  • 106
  • 1
  • Hi Nilay, thank you for the reply. The thing here is my Java app is inside the private space and I'm trying to make the callout from this app. I'm not calling this Java app from anywhere out of the private space (like my local). So, the endpoint is outside of the private network. Our Java app is in the private space. We're trying to make HTTP call to this out-of-private-space endpoint. – Mshn Mar 23 '22 at 14:45