package awesomefb.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONException;
import org.json.JSONObject;

public class JsonReader {

    public static JSONObject readJsonFromUrl(String urlPath) throws IOException, JSONException {
        System.out.println("Waiting for HTTP response from " + urlPath);
        URL url = new URL(urlPath);
        URLConnection con = url.openConnection();
        con.setConnectTimeout(30000);
        con.setReadTimeout(10000);
        InputStream in = con.getInputStream();
        String jsonText = org.apache.commons.io.IOUtils.toString(in);
        System.out.println("Received HTTP response.");
        JSONObject json = new JSONObject(jsonText);
        return json;
    }
}

@@ -75,16 +75,89 @@
 Stream;%0A
+import java.net.SocketException;%0Aimport java.net.SocketTimeoutException;%0A
 import j
@@ -169,16 +169,16 @@
 et.URL;%0A
-
 import j
@@ -613,16 +613,34 @@
 out(
-1
+3
 0000);%0A
+        try %7B%0A    
     
@@ -690,16 +690,20 @@
         
+  
+  
 String j
@@ -756,16 +756,20 @@
 ng(in);%0A
+    
         
@@ -823,16 +823,20 @@
         
+    
 JSONObje
@@ -879,16 +879,20 @@
         
+ 
+   
 return j
@@ -896,16 +896,152 @@
 n json;%0A
+        %7D catch (SocketTimeoutException e) %7B%0A            System.out.println(%22Timed out for %22 + urlPath);%0A        %7D%0A        return null;%0A
     %7D%0A%7D%0A

Handle TimeOut exception