2010-10-13 28 views
0

Je vais avoir le code ci-dessous ..problème avec 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"))); 
      } 

Ce code fonctionne si je remplace avec http://deadlock.netbeans.org/hudson/api/xml, mais il ne fonctionne pas avec http://in8301782d:8080/api/xml. Enfait Si je tape le samething dans le navigateur, il fonctionne .. Si je remplace le nom d'hôte avec l'adresse Ip ne fonctionne pas non plus.

L'exception que j'obtiens est ci-dessous.

*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) 

Répondre

1

Cela ne semble pas être un problème avec votre code.

Dans la première exception, SAX vous indique qu'il ne peut pas trouver http://in8301782d:8080/api/xml - il ne peut pas atteindre cette URL. Si l'URL fonctionne dans votre navigateur, alors la configuration du proxy est peut-être en cause.

Dans la deuxième exception, SAX signale que si le serveur renvoie un code d'état HTTP non succès de 503, which (according to the HTTP specification) means:

Le serveur est actuellement incapable de traiter la demande en raison d'une surcharge temporaire ou maintenance du serveur. L'implication est qu'il s'agit d'une condition temporaire qui sera atténuée après un certain temps.

Bien entendu, l'application installée à cette adresse URL peut également vous envoyer un HTTP 503 pour une raison non standard.