URLConnection 超时错误在本地工作正常,但在开发服务器上则不然



出于某种原因,我从下面的代码中收到了java.net.ConnectException: Connection timed out。它在我的本地计算机上运行良好,我可以通过本地和开发服务器上的浏览器访问它,但是在开发服务器上,我在尝试读取它时收到此错误。

public List<NodeMap> downloadFile(String fileUrl) {
    InputStream inputStream = null;
    try {
        URL url = new URL(fileUrl);
        URLConnection con = url.openConnection();
        con.setConnectTimeout(60000);
        con.setReadTimeout(60000);
        inputStream = con.getInputStream();
        CSVReader csvReader = new CSVReader(new InputStreamReader(inputStream),',','"');
        return iterateRows(csvReader);
    }
    catch (IOException e) {
        LOG.error("Node mapping file", e);
    }
    finally {
        IOUtils.closeQuietly(inputStream);
    }
    return null;
}

全栈

java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.7.0_21]
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) ~[na:1.7.0_21]
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) ~[na:1.7.0_21]
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) ~[na:1.7.0_21]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) ~[na:1.7.0_21]
        at java.net.Socket.connect(Socket.java:579) ~[na:1.7.0_21]
        at sun.net.NetworkClient.doConnect(NetworkClient.java:175) ~[na:1.7.0_21]
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:378) ~[na:1.7.0_21]
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:473) ~[na:1.7.0_21]
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:203) ~[na:1.7.0_21]
        at sun.net.www.http.HttpClient.New(HttpClient.java:290) ~[na:1.7.0_21]
        at sun.net.www.http.HttpClient.New(HttpClient.java:306) ~[na:1.7.0_21]
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995) ~[na:1.7.0_21]
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931) ~[na:1.7.0_21]
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849) ~[na:1.7.0_21]
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1299) ~[na:1.7.0_21]

看起来这是一个 DNS 问题。 我使用了网址的内部 IP,它奏效了!

相关内容

  • 没有找到相关文章

最新更新