我正在尝试打开与Java Enterprise应用程序(部署在Wildfly 8.2应用程序服务器上)中的网站的HTTP连接。我使用一个相当标准的工具-Jsoup库。 大部分时间,打开连接没有问题,我可以读取和解析网站内容(以进行进一步处理)。
但是,如果打开失败(超时)-再也不会成功,请直到应用程序完全重启。任何尝试打开与同一网站的连接的尝试都将失败,并再次出现相同的异常。好像该应用程序记住了网站的不可访问状态,并坚持这一假设,而无需再次尝试。 (我相当有信心,即使可以访问该网站,该应用程序仍会一次又一次抛出此异常。)
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:]
答案 0 :(得分:1)
您可能会遇到DNS兑现jdk确实存在的问题,而与Wildfly本身无关。
尝试设置networkaddress.cache.ttl或networkaddress.cache.negative.ttl系统属性来控制dns缓存的行为。
有关更多详细信息o。参见https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
答案 1 :(得分:0)
原来,(在这种情况下)网络配置不正确。不仅是JVM,还有其他一些程序也遇到了网络问题。