2010-10-13 31 views
0

我有下面的代码..问题与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工作。 Infact如果我在浏览器中键入相同的东西,它正在工作..如果我用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

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

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

在第二个例外,SAX正在报告该服务器返回的503非成功的HTTP状态代码,which (according to the HTTP specification) means:由于暂时超载或

服务器目前无法处理该请求维护服务器。这意味着这是暂时的情况,经过一段时间后会缓解。

当然,坐在这个URL的应用程序也可能会因为某些非标准原因而向您发送HTTP 503。