SAXParser says:"java.net.SocketException: Network is unreachable" but xmlint or curl are OK
I can download the following URL: "http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20"
with xmllint :
xmllint "http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20"
<?xml version="1.0" standalone="no"?>
<!DOCTYPE DASDNA SYSTEM "http://www.biodas.org/dtd/dasdna.dtd">
<DASDNA>
<SEQUENCE id="chr1" start="10" stop="20" version="1.00">
<DNA length="11">
ccctaacccta
</DNA>
</SEQUENCE>
</DASDNA>
or curl
curl "http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20"
<?xml version="1.0" standalone="no"?>
<!DOCTYPE DASDNA SYSTEM "http://www.biodas.org/dtd/dasdna.dtd">
<DASDNA>
<SEQUENCE id="chr1" start="10" stop="20" version="1.00">
<DNA length="11">
ccctaacccta
</DNA>
</SEQUENCE>
</DASDNA>
But the following java program raised an exception:
import javax.xml.parsers.*;
public class Test
{
public static void main(String args[])
{
try
{
SAXParserFactory f=SAXParserFactory.newInstance();
f.setNamespaceAware(false);
f.setValidating(false);
f.newSAXParser().parse(
"http://genome.ucsc.edu/cgi-bin/das/hg18/dna?segment=chr1%3A10%2C20",
new org.xml.sax.helpers.DefaultHandler()
);
System.out.println("OK");
}
catch(Exception err)
{
err.printStackTrace();
}
}
}
error:
java Test
java.net.ConnectException: Connection timed out
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:525)
at java.net.Socket.connect(Socket.java:475)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.prot开发者_开发知识库ocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:277)
at Test.main(Test.java:11)
Why ?
PS: there is no proxy here.
(later) OK , I've got the anwser: The SAX parser tried to load this "http://www.biodas.org/dtd/dasdna.dtd" and this site is down.
But how can I prevent the SAX parser to load this URL ???
精彩评论