1

I'm not very experienced with web development, so this is probably beginner problem. I have a small project with two Java web applications on two separate machines on Tomcats, one facing the user (frontend, FE app) and communicating to the other (backend, BE app). BE communicates with the DB through TCP and with FE through REST API. Problem is that Apache HttpGet used in the FE app reaches BE app only sometimes, but usually on the FE I get UnknownHostException. BE communication with DB or directly targeting BE REST API from the browser always works.

Which logs should I be looking at, and what should I do setting the Tomcats? Default Tomcat logging doesn't give me a lot of info, but I suppose it's a Tomcat configuration problem, since firewalls are down and all other TCP communication is working without issues. Below is my (very Vanilla) usage of Apache HttpGet:

...
    String url = String.format("http://%s/AutoexcludedDBService/nacionalidades", properties.getProperty("dbWebService"));
    CloseableHttpClient client = HttpClients.createDefault();
    CloseableHttpResponse response = null;
    String json = null;
    StatusLine statusLine = null;

    try {
        HttpGet request = new HttpGet(url);
        //request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
        request.addHeader("accept", "application/json");
        request.addHeader("User-Agent", HTTP.USER_AGENT);
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectionRequestTimeout(10000).setConnectTimeout(10000).setSocketTimeout(10000).build();
        request.setConfig(requestConfig);
        response = client.execute(request);

...

2 Answers2

0

According to your question, your error message is "java.net.UnknownHostException".

From the documentation: https://docs.oracle.com/javase/7/docs/api/java/net/UnknownHostException.html

Thrown to indicate that the IP address of a host could not be determined.

This error message indicates the problem is with name resolution for the host %s.

So it looks like your question should be "why host %a cannot resolve the name of the host %s" (in xy% percentage of the time).

With all additional relevant details of your operating system, that question is not suitable for stackoverflow, but rather for serverfault.com.

But prior to posting there, you should check google result for your OS: "os_name_here host cannot resolve the name"

If you are not convinced that the problem is due to OS, but rather due to HttpClient, you can add source for Apache HttpComponents to your project and at the line where UnknownHostException is thrown, print full stack trace and than add more logging to that line.

There is another thread to figure out how to get more details about UnknownHostException:

How to know the cause of UnknownHostException?

Mladen Adamovic
  • 3,071
  • 2
  • 29
  • 44
0

Turned out the issue was about notepad saving UTF-8 properties file with the BOM. What happened then is that property identifying host wasn't found, so resolving host "null" resulted in an exception.