Subversion Repositories SmartDukaan

Rev

Rev 10190 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10190 Rev 11964
Line 1... Line 1...
1
package in.shop2020.serving.services;
1
package in.shop2020.serving.services;
2
 
2
 
-
 
3
import java.io.BufferedReader;
3
import java.io.File;
4
import java.io.File;
4
import java.io.IOException;
5
import java.io.IOException;
-
 
6
import java.io.InputStreamReader;
-
 
7
import java.net.URL;
-
 
8
import java.net.URLConnection;
-
 
9
 
5
import org.apache.commons.io.FileUtils;
10
import org.apache.commons.io.FileUtils;
6
import org.apache.log4j.Logger;
11
import org.apache.log4j.Logger;
7
 
12
 
8
import in.shop2020.serving.utils.Utils;
13
import in.shop2020.serving.utils.Utils;
9
import in.shop2020.serving.utils.SnippetType;
14
import in.shop2020.serving.utils.SnippetType;
Line 25... Line 30...
25
		} catch (IOException e) {
30
		} catch (IOException e) {
26
			log.warn("Snippet of type " + type + " for entity " + entityId + " not found. ");
31
			log.warn("Snippet of type " + type + " for entity " + entityId + " not found. ");
27
		}
32
		}
28
		return htmlString;
33
		return htmlString;
29
	}
34
	}
-
 
35
	
-
 
36
	public static String getJSON(String entityId){
-
 
37
		String endPoint = "http://localhost:8080/mobileapi/items/" + entityId;
-
 
38
		return sendGetRequest(endPoint, null);
-
 
39
	}
-
 
40
	
-
 
41
	/**
-
 
42
	 * 
-
 
43
	 * @param endpoint
-
 
44
	 * @param requestParameters
-
 
45
	 * @return
-
 
46
	 */
-
 
47
	 public static String sendGetRequest(String endpoint, String requestParameters)
-
 
48
     {
-
 
49
             String result = null;
-
 
50
             try
-
 
51
             {
-
 
52
                     String urlStr = endpoint;
-
 
53
                     if (requestParameters != null && requestParameters.length () > 0){
-
 
54
                             urlStr += "?" + requestParameters;
-
 
55
                     }
-
 
56
                     URL url = new URL(urlStr);
-
 
57
                     URLConnection conn = url.openConnection ();
-
 
58
 
-
 
59
                     // Get the response
-
 
60
                     BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
-
 
61
                     StringBuffer sb = new StringBuffer();
-
 
62
                     String line;
-
 
63
                     while ((line = rd.readLine()) != null)
-
 
64
                     {
-
 
65
                             sb.append(line);
-
 
66
                     }
-
 
67
                     rd.close();
-
 
68
                     result = sb.toString();
-
 
69
             } catch (Exception e){
-
 
70
                     log.info("Could not get results from api locally");
-
 
71
             }
-
 
72
             return result;
-
 
73
     }
30
}
74
}