Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.net.ConnectException with org.jdom.input.SAXBuilder .build(File)

843834Nov 1 2006
It sounds that this problem is common and it must not be that mysterious. However, It is. Simply because I have an operation to do on a set of XML files, so, for a given directory I loop over the files there. Sometimes I get the exception
Exception in thread "main" 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.Socket.connect(Socket.java:507)
	at java.net.Socket.connect(Socket.java:457)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
	at sun.net.www.http.HttpClient.New(HttpClient.java:287)
	at sun.net.www.http.HttpClient.New(HttpClient.java:299)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:973)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:905)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:872)
	at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:282)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1021)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:810)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:789)
	at com.hicx.util.HBMsSequenceUtil.getDoc(HBMsSequenceUtil.java:30)
	at com.hicx.util.HBMsSequenceUtil.performAlterations(HBMsSequenceUtil.java:68)
	at com.hicx.util.HBMsSequenceUtil.main(HBMsSequenceUtil.java:57)
for some files. I didn't get why i just get this exception for only a few files, and for the second execution i get it for ANOTHER TOTTALLY DIFFERRENT few other files!!!
I wrote the following code to avoid that time out thing
    private org.jdom.Document getDoc(String fname) throws JDOMException, IOException {
    	org.jdom.Document doc = null;
    	try{
    		doc = sxb.build(new File(fname));
        }catch( java.net.ConnectException ex){
        	System.err.println("retry to parse file: "+fname);
        	return getDoc(fname);
        }
        return doc;
    }
surprisingly it worked out well, and i didn't get infinite execution as i was expecting cause the system now can parse the document if not from the first try, then from the second one. I know this is a bad programming practice, but at least it does work out well.
I tried several tens of tests over the files i have, for the first two tens i did not even get a single exception, after that I started getting these exceptions. It may take about 5 minutes to parse an xml, and i don't get an exception then, but the exception may get thrown only after 30 seconds or less. I simply couldn't conclude any anticipated reason other than blaming my Windows operating system

Thanks in advance for help
bye
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 29 2006
Added on Nov 1 2006
0 comments
578 views