Solved Unable to loop HTTP connection.

Discussion in 'Plugin Development' started by TopGear93, Aug 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    TopGear93

    I know, why would I be trying to loop through a HTTP connection? Basically I have an arraylist that keeps track of specific urls and I need to loop through all those but for some reason my loop stops at the first item on the array list. I've been able to trigger a loop on the same list in other areas without issue.

    The code may look familiar: I'm trying to do some work to the TwitchSub plugin.

    Code:java
    1. for (String slist : plugin.uniqueID) {
    2. String urlString = "[url]http://whitelist.twitchapps.com/list.php?id=[/url]" + slist + "&header=CHECK";
    3. plugin.getLogger().info(urlString);
    4. try {
    5. plugin.getLogger().info("Getting whitelist from " + urlString);
    6. URL url = new URL(urlString);
    7. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    8. try {
    9. BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    10. int lineNumber = 1;
    11. String inputLine;
    12. while ((inputLine = in.readLine()) != null) {
    13. inputLine = inputLine.trim();
    14. if (lineNumber == 1 && !inputLine.equals("CHECK")) {
    15. throw new IOException();
    16. }
    17. plugin.temp.add(inputLine.toLowerCase());
    18. lineNumber++;
    19. }
    20. in.close();
    21. for (String player : plugin.temp) {
    22. plugin.whitelist.add(player);
    23. }
    24. } catch (IOException exerr) {
    25. String errorIn = "";
    26. InputStream errorStream = conn.getErrorStream();
    27. if (errorStream != null) {
    28. BufferedReader inE = new BufferedReader(new InputStreamReader(errorStream));
    29. String inputLine;
    30. while ((inputLine = inE.readLine()) != null) {
    31. errorIn = errorIn + inputLine;
    32. }
    33. inE.close();
    34. }
    35. plugin.getLogger().info("Error getting list: " + errorIn);
    36. }
    37. return true;
    38. } catch (Exception ex) {
    39. ex.printStackTrace();
    40. }
    41. }
    42. return false;
    43. }
    44. }
     
  2. Offline

    stormneo7

    I don't believe there is a "{url}"before the actual url. Nor a "{url}" at the end.
     
  3. Offline

    adam753

    Code:
    plugin.getLogger().info(urlString);}
    Look closely.
     
  4. Offline

    TopGear93

    Yea, i know about that issue so i removed it from the code I posted above. Even with removing this, the loop doesn't continue and go through the whole list.

    showed up automatically when I posted the code on the forum. Ill try to correct that.

    Ok, I fixed it. I should of just experimented more on my own before posting. The problem was that the method was on a trigger and would only allow it to be used once. I set the method to be normal "void" and now its' looping just fine. It ended up messing up a bunch of other pieces of my code but I fixed those too.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page