Search code examples
jakarta-eewildflyjca

What could be the root cause of this java.net.ConnectException, and how to resolve it?


The context

I'm trying to open an HTTP connection to a web site in a Java Enterprise application (deployed on a Wildfly 8.2 application server). I use a fairly standard tool to do this - the Jsoup library. Most of the time, the connection is opened without a problem, and I can read and parse the web site content (for further processing).

However, if once the open fails (times out) - it will never again succeed, until the full restart of the application. Any attempt to open a connection to the same website will fail with the same exception again. As if the application memorized the inaccessible status of the web site, and stuck to this hypothesis, without trying again. (I am fairly confident, that even when the web site is accessible, the application still throws this exception again and again.)

The Exception

Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method) [rt.jar:1.8.0_31]
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) [rt.jar:1.8.0_31]
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) [rt.jar:1.8.0_31]
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) [rt.jar:1.8.0_31]
    at java.net.PlainSocketImpl.connect(Unknown Source) [rt.jar:1.8.0_31]
    at java.net.SocksSocketImpl.connect(Unknown Source) [rt.jar:1.8.0_31]
    at java.net.Socket.connect(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.NetworkClient.doConnect(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.http.HttpClient.openServer(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.http.HttpClient.openServer(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.http.HttpClient.<init>(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.http.HttpClient.New(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.http.HttpClient.New(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) [rt.jar:1.8.0_31]
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) [rt.jar:1.8.0_31]
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449) [jsoup-1.8.1.jar:]
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434) [jsoup-1.8.1.jar:]
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181) [jsoup-1.8.1.jar:]
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170) [jsoup-1.8.1.jar:]

The questions

  • Can this be a Wildfly bug?
  • Can this problem be solved inside the application server? For instance, tuning configuration parameters, setting up a HTTP connection pool (does such thing exist?)
  • Is it correct at all to open an HTTP connection (that is: use a non-managed, non-transactional resource) in a Java Enterprise application?
  • How else could I access something available only over HTTP? (besides opening a connection)
  • Could developing a JCA adapter resolve this issue?
  • Does such JCA adapter exist already? (I can't be the only one with this problem ...)

Solution

  • It turned out, that (in this specific case) the network was configured incorrectly. Not only JVM, several other programs experienced network issues.