SAX 的问题

发布于 2024-09-27 10:34:54 字数 3536 浏览 1 评论 0原文

我有下面的代码。

         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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肥爪爪 2024-10-04 10:34:54

这似乎不是您的代码的问题。

在第一个例外中,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:

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay.

Of course, the application sitting at this URL may be sending you a HTTP 503 for some non-standard reason as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文