码迷,mamicode.com
首页 > 其他好文 > 详细

Connection timed out: connect Nested exception

时间:2015-01-15 20:07:52      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

使用dom4j解析自定义的.xml文件.

大致内容如下:

Xml代码  

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>items</key>
  <array>
    <dict>
      <key>assets</key>
      <array>
        <dict>
          <key>kind</key>
          <string>software-package</string>
          <key>url</key>
          <string>appPath</string>
        </dict>
      </array>
      <key>metadata</key>
      <dict>
        <key>bundle-identifier</key>
        <string>appIdentifier</string>
        <key>bundle-version</key>
        <string>appVersion</string>
        <key>kind</key>
        <string>software</string>
        <key>title</key>
        <string>appName</string>
      </dict>
    </dict>
  </array>
</dict>
</plist>

 

居然报了一个 连接超时的错误:
org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
 at org.dom4j.io.SAXReader.read(SAXReader.java:484)
 at org.dom4j.io.SAXReader.read(SAXReader.java:321)
 at com.util.ReadXmlDataUtil.getLanguageXMLData(ReadXmlDataUtil.java:28)
 at com.admin.util.ReadXmlDataUtil.main(ReadXmlDataUtil.java:50)
Nested exception: 
java.net.ConnectException: Connection timed out: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
 at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
 at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
 at java.net.Socket.connect(Socket.java:519)
 at java.net.Socket.connect(Socket.java:469)
 at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
 at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
 at org.dom4j.io.SAXReader.read(SAXReader.java:465)
 at org.dom4j.io.SAXReader.read(SAXReader.java:321)
 at com.huawei.ngbss.admin.util.ReadXmlDataUtil.getLanguageXMLData(ReadXmlDataUtil.java:28)
 at com.huawei.ngbss.admin.util.ReadXmlDataUtil.main(ReadXmlDataUtil.java:50)
Nested exception: java.net.ConnectException: Connection timed out: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)

解决方案:
后面找到了其中的原因:
是网络的问题.因为DOCTYPE的连接不同造成的.
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
使用了saxreader解析器的时候,会自动解析DOCTYPE里面的内容.如果连接不上网络,则会报连接超时的异常.

所以为了,不然解析DOCTYPE,则reader.setFeature(不加载dtd文件,false); 就不会去解析DOCTYPE了.

即可.

SAXReader reader = new  SAXReader();

reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",   false);  

Connection timed out: connect Nested exception

标签:

原文地址:http://www.cnblogs.com/vipwolf/p/4227007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!