Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnknownHostException from Java but host resolves with Ping/nslookup/curl

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]

like image 356
Sandip Dhummad Avatar asked Jun 12 '14 16:06

Sandip Dhummad


1 Answers

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:

  • DNS and Java
  • Java doesn't pick up system's DNS settings change until restarted
  • Java and /etc/resolv.conf DNS server failover
  • Java networking properties
like image 196
Stephen C Avatar answered Nov 15 '22 11:11

Stephen C