dl.bukkit.org feed is not readable with Java

Discussion in 'Plugin Development' started by Th3Shad0wOfDeath, Jun 1, 2014.

Thread Status:
Not open for further replies.
  1. I am developing a desktop application for managing Bukkit-versions and plugins.
    The site "http://dl.bukkit.org/api/1.0/downloads/projects/craftbukkit/artifacts/" is not readable. The XMLparser throws an exception:
    org.xml.sax.SAXParseException:Content is not allowed in prolog.

    Please offer me some help :)
    Or maybe something is wrong with the server.
     
  2. Offline

    Lolmewn

    Please show us some code. Java retrieves the exact same version as the browser, so it's likely the problem lies in your code.
     
  3. Offline

    mactown21

    Th3Shad0wOfDeath As was said on that craftbukkit servers was down i think 5/25 that could be the reason why
     
  4. Offline

    JaguarJo

    Moved to a more appropriate section.
     

  5. Code:java
    1. public static void getCraftbukkitVersions()
    2. {
    3. try
    4. {
    5. URL url = new URL("[url]http://dl.bukkit.org/api/1.0/downloads/projects/craftbukkit/artifacts/[/url]");
    6. DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    7. DocumentBuilder builder = builderFactory.newDocumentBuilder();
    8. builder.parse(url.openStream());
    9. }
    10. {
    11. ex.printStackTrace();
    12. }
    13. catch (ParserConfigurationException ex)
    14. {
    15. ex.printStackTrace();
    16. }
    17. catch (SAXException ex)
    18. {
    19. ex.printStackTrace();
    20. }
    21. catch (IOException ex)
    22. {
    23. ex.printStackTrace();
    24. }
    25. }


    An SAXException is thrown:
    [Fatal Error] :1:1: Content is not allowed in prolog.
    org.xml.sax.SAXParseException: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at org.marius.bc.BukkitControllerMain.getCraftbukkitVersions(BukkitControllerMain.java:143)
    at org.marius.bc.BukkitControllerMain.main(BukkitControllerMain.java:35)


    Line 143 is:
    builder.parse(url.openStream());
     
  6. Offline

    AmShaegar

    Look at the first 255 bytes you get from the server when using url.openStream():
    Code:
    {"results": [{"broken_reason": "", "build_number": 3095, "created": "2014-06-02 23:22:13Z", "url": "http://dl.bukkit.org/api/1.0/downloads/projects/craftbukkit/view/02633_1.7.9-R0.3/", "is_broken": false, "html_url": "http://dl.bukkit.org/downloads/craftb
    
    So either you parse JSON or you tell the server that your client accepts XML. THis should do the trick:
    Code:java
    1.  
    2. URL url = new URL("[url]http://dl.bukkit.org/api/1.0/downloads/projects/craftbukkit/artifacts/[/url]");
    3. URLConnection connection = url.openConnection();
    4. connection.setRequestProperty("Accept", "application/xml");
    5. DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    6. DocumentBuilder builder = builderFactory.newDocumentBuilder();
    7. builder.parse(connection.getInputStream());
     
    Th3Shad0wOfDeath likes this.
  7. Thanks... It works perfectly fine now!
     
Thread Status:
Not open for further replies.

Share This Page