SAX 的问题
我有下面的代码。
System.setProperty("http.proxyHost","176.6.129.25") ;
System.setProperty("http.proxyPort", "8080") ;
Authenticator.setDefault(new MyAuthenticator());
//http://deadlock.netbeans.org/hudson/api/xml
*URL url = new URL("http://in8301782d:8080/api/xml");*
Document dom = new SAXReader().read(url);
for( Element job : (List<Element>)dom.getRootElement().elements("job")) {
System.out.println(String.format("Name:%s\tStatus:%s",
job.elementText("name"), job.elementText("color")));
}
如果我替换为 http://deadlock,则此代码可以正常工作。 netbeans.org/hudson/api/xml ,但它不适用于 http://in8301782d:8080 /api/xml。事实上,如果我在浏览器中输入相同的内容,它就可以工作。如果我用 IP 地址替换主机名,它也不起作用。
我得到的例外如下。
*With in8301782d (machine name)* :
xception in thread "main" org.dom4j.DocumentException: http://in8301782d:8080/api/xml Nested exception: http://in8301782d:8080/api/xml
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
Nested exception:
java.io.FileNotFoundException: http://in8301782d:8080/api/xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1243)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(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 org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
*With Ip (http://176.6.55.55:8080/api/xml):*
Exception in thread "main" org.dom4j.DocumentException: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml Nested exception: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
Nested exception:
java.io.IOException: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(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 org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
I'm having the code below..
System.setProperty("http.proxyHost","176.6.129.25") ;
System.setProperty("http.proxyPort", "8080") ;
Authenticator.setDefault(new MyAuthenticator());
//http://deadlock.netbeans.org/hudson/api/xml
*URL url = new URL("http://in8301782d:8080/api/xml");*
Document dom = new SAXReader().read(url);
for( Element job : (List<Element>)dom.getRootElement().elements("job")) {
System.out.println(String.format("Name:%s\tStatus:%s",
job.elementText("name"), job.elementText("color")));
}
This code is working if I replace with http://deadlock.netbeans.org/hudson/api/xml , but it is not working with http://in8301782d:8080/api/xml. Infact If I type the samething in browser it is working.. If I replace the hostname with Ip address also not working.
The exception I'm getting is below.
*With in8301782d (machine name)* :
xception in thread "main" org.dom4j.DocumentException: http://in8301782d:8080/api/xml Nested exception: http://in8301782d:8080/api/xml
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
Nested exception:
java.io.FileNotFoundException: http://in8301782d:8080/api/xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1243)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(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 org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
*With Ip (http://176.6.55.55:8080/api/xml):*
Exception in thread "main" org.dom4j.DocumentException: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml Nested exception: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
Nested exception:
java.io.IOException: Server returned HTTP response code: 503 for URL: http://176.6.66.156:8080/api/xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(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 org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:291)
at com.sg.hudson.ci.Main.main(Main.java:140)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎不是您的代码的问题。
在第一个例外中,SAX 告诉您它找不到 http://in8301782d:8080/api/xml - 无法到达此 URL。如果该 URL 在您的浏览器中有效,则代理设置可能有问题。
在第二个异常中,SAX 报告服务器返回不成功的 HTTP 状态代码 503,(根据 HTTP 规范)意味着:
当然,位于此 URL 的应用程序也可能会出于某种非标准原因向您发送 HTTP 503。
This doesn't appear to be a problem with your code.
In the first exception, SAX is telling you that it cannot find http://in8301782d:8080/api/xml - it cannot reach this URL. If the URL works in your browser, then perhaps the proxy setup is at fault.
In the second exception, SAX is reporting that the server is returning a non-success HTTP status code of 503, which (according to the HTTP specification) means:
Of course, the application sitting at this URL may be sending you a HTTP 503 for some non-standard reason as well.