SAX问题

时间:2010-10-13 13:25:47

标签: java continuous-integration hudson

我有以下代码..

         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)

1 个答案:

答案 0 :(得分:1)

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

在第一个例外中,SAX告诉您它无法找到http://in8301782d:8080/api/xml - 它无法访问此网址。如果URL在浏览器中有效,那么代理设置可能有问题。

在第二个例外中,SAX报告服务器返回的成功HTTP状态代码为503,which (according to the HTTP specification) means

  

由于服务器临时过载或维护,服务器当前无法处理请求。这意味着这是一个暂时的条件,经过一段时间的推迟后会得到缓解。

当然,由于某些非标准原因,位于此URL的应用程序可能会向您发送HTTP 503。