11

We are getting the following exception when a Java EE server tries to resolve a host name from one of the services. We were able to resolve that host name on the box manually with ping/nslookup command. We were also able to fire that external service using curl with same parameters what server is trying to use. So it seems like this issue happens only when we try to make a request to a external host from a Java/Java EE application.

To resolve this issue, we manually added an entry in /etc/hosts file and it solved the problem but we want a permanent solution so we don't have to keep changing the IP. It was working before without adding that entry but all of a sudden it stopped working.

Detail of our environment:

OS: Cent OS 6.3

Java : JDK 1.6.0_24

Java EE Server : JBoss AS 7.1.1

Http Client library : httpclient-4.0.jar

Thanks in advance for the help!!

Error while checking salesforce license|: java.net.UnknownHostException: na15.salesforce.com at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:175) [rt.jar:1.6.0_24] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384) [rt.jar:1.6.0_24] at java.net.Socket.connect(Socket.java:546) [rt.jar:1.6.0_24] at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:584) [jsse.jar:1.6.0_24] at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:333) [httpclient-4.0.jar:4.0] at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123) [httpclient-4.0.jar:4.0] at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147) [httpclient-4.0.jar:4.0] at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:101) [httpclient-4.0.jar:4.0] at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381) [httpclient-4.0.jar:4.0] at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) [httpclient-4.0.jar:4.0] at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) [httpclient-4.0.jar:4.0]

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Sandip Dhummad
  • 993
  • 1
  • 7
  • 10

2 Answers2

6

This is most likely a network management, change / configuration management or general system administration problem rather than a programming problem.

It was working before without adding that entry but all of a sudden it stopped working.

One approach is to try to figure out what changed to cause it to stop working. This is not the kind of thing that would happen spontaneously. Someone or something has changed some software or configurations to make this happen. Start with when it stopped (or when you noticed) and work back through your change logs.

It sounds like it is an issue with the Java DNS resolution procedure. It appears that the resolver is either not trying to talk to the normal DNS servers, or it is trying and failing.

We can't debug it for you, but I found these resources that help to explain what should be happening when you do a name lookup in Java, and offer some ideas on trouble-shooting.

Resources:

Germán Faller
  • 546
  • 7
  • 15
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks for your answer!! We thought the same that it should be an issue how Java tries to resolve DNS name vs. how OS does it. You pointers would be definitely be helpful. – Sandip Dhummad Jun 16 '14 at 13:48
  • We found the issue. The issue was with changes in DNS server configuration. Thanks for your help!! – Sandip Dhummad Jun 17 '14 at 14:15
0

I found that these same symptoms can happen when IPv6 is disabled on your networking. You can see this by running a simple Java program:

import java.net.InetAddress;
public class NameTest
{
  public static void main(String[] args) throws Exception
  {
    System.out.println(InetAddress.getByName("google.com"));
  }
}

If IPv6 is an issue, then running the program with java -cp . NameTest will fail with a line like "at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)" in the stack trace (notice the Inet6 in the class name), and running the program with java -cp . -Djava.net.preferIPv4Stack=true NameTest will succeed (this is from the above answer Java networking properties reference).

To work past this, I followed suggestions from this question.

An OS-wide disabling of IPv6 works well, as the system doesn't have IPv6. On some Linux varieties, this can be disabled by first adding this line to the end of the file /etc/sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 1

followed by running sudo sysctl -p to immediately disable IPv6.

Groboclown
  • 119
  • 1
  • 3