| 419 |
rajveer |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
| 17646 |
amit.gupta |
3 |
import java.io.BufferedReader;
|
| 20180 |
aman.kumar |
4 |
import java.io.DataOutputStream;
|
| 17646 |
amit.gupta |
5 |
import java.io.InputStreamReader;
|
| 20180 |
aman.kumar |
6 |
import java.net.HttpURLConnection;
|
|
|
7 |
import java.net.URL;
|
| 3209 |
vikas |
8 |
import java.util.ArrayList;
|
| 6603 |
anupam.sin |
9 |
import java.util.Arrays;
|
| 6998 |
amit.gupta |
10 |
import java.util.Collections;
|
| 12620 |
amit.gupta |
11 |
import java.util.Date;
|
| 6178 |
anupam.sin |
12 |
import java.util.HashMap;
|
| 3209 |
vikas |
13 |
import java.util.List;
|
| 6135 |
anupam.sin |
14 |
import java.util.Map;
|
| 20180 |
aman.kumar |
15 |
import java.util.Map.Entry;
|
| 3209 |
vikas |
16 |
|
| 4891 |
varun.gupt |
17 |
import javax.mail.internet.AddressException;
|
|
|
18 |
import javax.mail.internet.InternetAddress;
|
| 20180 |
aman.kumar |
19 |
import javax.net.ssl.HttpsURLConnection;
|
| 4891 |
varun.gupt |
20 |
|
| 3209 |
vikas |
21 |
import org.apache.commons.lang.StringUtils;
|
| 17646 |
amit.gupta |
22 |
import org.apache.http.HttpResponse;
|
|
|
23 |
import org.apache.http.client.HttpClient;
|
|
|
24 |
import org.apache.http.client.methods.HttpGet;
|
|
|
25 |
import org.apache.http.impl.client.DefaultHttpClient;
|
| 3209 |
vikas |
26 |
import org.apache.log4j.Logger;
|
|
|
27 |
|
| 20180 |
aman.kumar |
28 |
import in.shop2020.config.ConfigException;
|
|
|
29 |
import in.shop2020.model.v1.catalog.ExclusiveAffiliateItemInfo;
|
|
|
30 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
31 |
import in.shop2020.model.v1.order.Order;
|
|
|
32 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
33 |
import in.shop2020.model.v1.order.RechargePlan;
|
|
|
34 |
import in.shop2020.model.v1.order.RechargeType;
|
|
|
35 |
import in.shop2020.model.v1.user.Cart;
|
|
|
36 |
import in.shop2020.model.v1.user.Line;
|
|
|
37 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
38 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
39 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
40 |
|
| 419 |
rajveer |
41 |
public class Utils {
|
| 2942 |
chandransh |
42 |
private static Logger logger = Logger.getLogger(Utils.class);
|
|
|
43 |
|
| 4892 |
varun.gupt |
44 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
| 5084 |
phani.kuma |
45 |
public static final String EXPORT_JAVASCRIPT_CONTENT_PATH = "/var/lib/tomcat6/webapps/export/javascripts/";
|
| 2306 |
vikas |
46 |
public static final long ROOT_CATEGORY = 10000;
|
|
|
47 |
public static final long MOBILE_PHONES_CATEGORY = 10001;
|
|
|
48 |
public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
|
| 3656 |
mandeep.dh |
49 |
public static final long TABLETS_CATEGORY = 10010;
|
|
|
50 |
public static final long LAPTOPS_CATEGORY = 10050;
|
| 5873 |
amit.gupta |
51 |
public static final long CAMERAS_CATEGORY = 11001;
|
| 6135 |
anupam.sin |
52 |
|
|
|
53 |
static Map<Long, String> providersMap;
|
| 6178 |
anupam.sin |
54 |
static Map<Long, String> mobileProvidersMap;
|
|
|
55 |
static Map<Long, String> dthProvidersMap;
|
| 12620 |
amit.gupta |
56 |
static Map<Long, ExclusiveAffiliateItemInfo> exclusiveAffiliateItems = null;
|
| 6178 |
anupam.sin |
57 |
static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
|
| 6204 |
rajveer |
58 |
private static Map<String, Map<String, String>> uriOperatorMap = new HashMap<String, Map<String,String>>();
|
| 12620 |
amit.gupta |
59 |
static long fifteenMinsCounter = 0l;
|
| 6204 |
rajveer |
60 |
|
| 6603 |
anupam.sin |
61 |
public static final List<RechargeOrderStatus> refundableRechargeStatusList = new ArrayList<RechargeOrderStatus>(Arrays.asList(new RechargeOrderStatus[]
|
|
|
62 |
{RechargeOrderStatus.RECHARGE_FAILED,
|
| 8932 |
anupam.sin |
63 |
RechargeOrderStatus.RECHARGE_FAILED_REFUNDED}));
|
| 6603 |
anupam.sin |
64 |
|
|
|
65 |
public static Map<RechargeOrderStatus, String> statusMap = new HashMap<RechargeOrderStatus, String>();
|
|
|
66 |
|
| 6998 |
amit.gupta |
67 |
//public static final List<String> multiValuedFacet = Arrays.asList("F_50006");
|
| 6887 |
amit.gupta |
68 |
|
| 6998 |
amit.gupta |
69 |
public static final List<String>rootfacetDefIDs = Arrays.asList("F_50010","F_50011","F_50002", "F_50001", "F_50028");
|
| 8878 |
amit.gupta |
70 |
public static final String availabilityFacet = "F_50028";
|
| 13425 |
amit.gupta |
71 |
@SuppressWarnings("serial")
|
|
|
72 |
public static final Map<String, String> NET_BANKING_CODES_MAP = Collections.unmodifiableMap(
|
|
|
73 |
new HashMap<String, String>(){
|
|
|
74 |
{
|
|
|
75 |
put("1004","AXIB");
|
|
|
76 |
put("1135","CRPB");
|
|
|
77 |
put("1029","FEDB");
|
|
|
78 |
put("1007","HDFB");
|
|
|
79 |
put("1016","ICIB");
|
| 13432 |
amit.gupta |
80 |
put("1032","SBIB");
|
|
|
81 |
put("1034","SBHB");
|
|
|
82 |
put("1038","SBMB");
|
| 17646 |
amit.gupta |
83 |
put("1035","SBMB");
|
| 13432 |
amit.gupta |
84 |
put("1039","SBTB");
|
| 17646 |
amit.gupta |
85 |
put("1127","CITNB");
|
| 13460 |
amit.gupta |
86 |
put("1033","SBBJB");
|
| 13432 |
amit.gupta |
87 |
//Oriental Bank of Commerce
|
|
|
88 |
//put("1154","");
|
| 13425 |
amit.gupta |
89 |
put("1147","CBIB");
|
|
|
90 |
put("1146","YESB");
|
|
|
91 |
put("1214","BOIB");
|
|
|
92 |
put("1215","CUBB");
|
| 13436 |
amit.gupta |
93 |
put("1212","UNIB");
|
| 13425 |
amit.gupta |
94 |
put("1224","CABB");
|
| 13432 |
amit.gupta |
95 |
put("1210","INGB");
|
|
|
96 |
put("1148","162B");
|
|
|
97 |
put("1273","DLSB");
|
| 13425 |
amit.gupta |
98 |
put("1015","JAKB");
|
|
|
99 |
put("1133","KRKB");
|
|
|
100 |
put("1143","INDB");
|
| 13436 |
amit.gupta |
101 |
put("1216","UBIB");
|
| 13425 |
amit.gupta |
102 |
put("1213","INOB");
|
|
|
103 |
put("1229","BOMB");
|
| 13432 |
amit.gupta |
104 |
put("1601","CSBN");
|
|
|
105 |
put("1602","DCBB");
|
|
|
106 |
put("1603","DSHB");
|
|
|
107 |
put("1604","IDBB");
|
|
|
108 |
put("1605","INIB");
|
|
|
109 |
put("1606","KRVB");
|
|
|
110 |
put("1607","PNBB");
|
|
|
111 |
put("1608","SOIB");
|
|
|
112 |
put("1609","SRSWT");
|
|
|
113 |
put("1610","VJYB");
|
| 17646 |
amit.gupta |
114 |
put("1611","DCBCORP");
|
|
|
115 |
put("1612","UBIBC");
|
|
|
116 |
put("1613","CPNB");
|
| 13425 |
amit.gupta |
117 |
}
|
|
|
118 |
});
|
| 6998 |
amit.gupta |
119 |
public static final Map<String, String> FACET_LABEL_MAP = Collections.unmodifiableMap(
|
|
|
120 |
new HashMap<String, String>(){
|
|
|
121 |
/**
|
|
|
122 |
*
|
|
|
123 |
*/
|
|
|
124 |
private static final long serialVersionUID = 1L;
|
|
|
125 |
|
|
|
126 |
{
|
|
|
127 |
put("F_50010","Category");
|
|
|
128 |
put("F_50011","Sub Category");
|
|
|
129 |
put("F_50002","Price");
|
|
|
130 |
put("F_50001","Brand");
|
|
|
131 |
put("F_50006","Data Connectivity");
|
|
|
132 |
put("F_50007","Camera Resolution");
|
| 12111 |
amit.gupta |
133 |
put("F_50039","");
|
| 6998 |
amit.gupta |
134 |
put("F_50012","Display");
|
|
|
135 |
put("F_50013","Operating System");
|
|
|
136 |
put("F_50014","RAM");
|
|
|
137 |
put("F_50015","Storage Capacity");
|
|
|
138 |
put("F_50017","Processor");
|
|
|
139 |
put("F_50018","Capacity");
|
|
|
140 |
put("F_50019","Class");
|
|
|
141 |
put("F_50020","Capacity");
|
|
|
142 |
put("F_50021","Capacity");
|
|
|
143 |
put("F_50022","Type");
|
|
|
144 |
put("F_50023","Interface");
|
|
|
145 |
//Resolution for Composite
|
|
|
146 |
put("F_50024","Resolution");
|
|
|
147 |
put("F_50025","Optical Zoom");
|
|
|
148 |
put("F_50026","Display Size");
|
|
|
149 |
//Resolution for DSLR
|
|
|
150 |
put("F_50027","Resolution");
|
|
|
151 |
put("F_50028","Availability");
|
|
|
152 |
put("F_50031","Operating System");
|
|
|
153 |
put("F_50032","Screen Size"); //Screen size for mobiles
|
|
|
154 |
put("F_50033","Screen Size"); //Screen size for laptop
|
|
|
155 |
put("F_50034","Screen Size"); //Screen size for tablets
|
| 7132 |
amit.gupta |
156 |
put("F_50035","Operating System"); //Screen size for tablets
|
|
|
157 |
put("F_50036","Camera Resolution"); //Screen size for tablets
|
| 8880 |
amit.gupta |
158 |
put("F_50037","Voice Call Facility"); //Screen size for tablets
|
| 9472 |
amit.gupta |
159 |
put("F_50038","Mobile Type"); //Mobile Type
|
| 8880 |
amit.gupta |
160 |
put("F_50028","Availability");
|
| 6998 |
amit.gupta |
161 |
}
|
|
|
162 |
});
|
| 6135 |
anupam.sin |
163 |
|
|
|
164 |
static {
|
| 6603 |
anupam.sin |
165 |
statusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
|
|
|
166 |
statusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
|
|
|
167 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
|
|
|
168 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed");
|
|
|
169 |
statusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
|
|
|
170 |
statusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
|
|
|
171 |
statusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
|
|
|
172 |
|
| 6135 |
anupam.sin |
173 |
TransactionClient tcl;
|
|
|
174 |
try {
|
|
|
175 |
tcl = new TransactionClient();
|
| 6206 |
rajveer |
176 |
mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
|
|
|
177 |
dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
|
| 6178 |
anupam.sin |
178 |
// providersMap.putAll(mobileProvidersMap);
|
|
|
179 |
// providersMap.putAll(dthProvidersMap);
|
|
|
180 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
181 |
List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
|
|
|
182 |
if (!plans.isEmpty()) {
|
|
|
183 |
operatorPlanMap.put(operatorId, plans);
|
|
|
184 |
}
|
|
|
185 |
}
|
| 6204 |
rajveer |
186 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
187 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
188 |
valueMap.put("Id", operatorId+"");
|
|
|
189 |
valueMap.put("Name", mobileProvidersMap.get(operatorId)+"");
|
|
|
190 |
valueMap.put("ServiceType", "1");
|
|
|
191 |
valueMap.put("ServiceName", "Prepaid Mobile");
|
|
|
192 |
uriOperatorMap.put(mobileProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
193 |
}
|
|
|
194 |
for (Long operatorId : dthProvidersMap.keySet()) {
|
|
|
195 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
196 |
valueMap.put("Id", operatorId+"");
|
|
|
197 |
valueMap.put("Name", dthProvidersMap.get(operatorId)+"");
|
|
|
198 |
valueMap.put("ServiceType", "2");
|
|
|
199 |
valueMap.put("ServiceName", "DTH TV");
|
|
|
200 |
uriOperatorMap.put(dthProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
201 |
}
|
| 6603 |
anupam.sin |
202 |
|
| 6204 |
rajveer |
203 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
204 |
valueMap.put("Id", "0");
|
|
|
205 |
valueMap.put("Name", "Mobile and DTH");
|
|
|
206 |
valueMap.put("ServiceType", "1");
|
|
|
207 |
valueMap.put("ServiceName", "");
|
|
|
208 |
uriOperatorMap.put("recharge", valueMap);
|
| 6178 |
anupam.sin |
209 |
// providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH));
|
| 6603 |
anupam.sin |
210 |
|
|
|
211 |
|
| 6135 |
anupam.sin |
212 |
} catch (Exception e) {
|
|
|
213 |
logger.error("Could not get providers", e);
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
| 1453 |
chandransh |
219 |
private static String getExportPath(){
|
| 1457 |
chandransh |
220 |
String exportPath=null;
|
| 1453 |
chandransh |
221 |
ConfigClient client = ConfigClient.getClient();
|
|
|
222 |
try{
|
|
|
223 |
exportPath = client.get("export_entities_path");
|
|
|
224 |
}catch(ConfigException ce){
|
| 2942 |
chandransh |
225 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
226 |
logger.warn("Setting the default export path");
|
| 1475 |
chandransh |
227 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
228 |
}
|
|
|
229 |
return exportPath;
|
|
|
230 |
}
|
|
|
231 |
|
| 12620 |
amit.gupta |
232 |
|
|
|
233 |
public static Map<Long, ExclusiveAffiliateItemInfo> getExclusiveAffiliateItems(){
|
|
|
234 |
try{
|
|
|
235 |
CatalogClient client = new CatalogClient();
|
| 12626 |
amit.gupta |
236 |
Long currentTime = new Date().getTime();
|
|
|
237 |
if(exclusiveAffiliateItems == null || fifteenMinsCounter < currentTime) {
|
| 12620 |
amit.gupta |
238 |
exclusiveAffiliateItems = client.getClient().getExAffiliateItemInfo();
|
|
|
239 |
fifteenMinsCounter = new Date().getTime() + 15*60000;
|
|
|
240 |
}
|
|
|
241 |
}catch(Exception ce){
|
|
|
242 |
logger.error("Unable to fetch exclusive items from catalog", ce);
|
|
|
243 |
}
|
|
|
244 |
return exclusiveAffiliateItems;
|
|
|
245 |
}
|
|
|
246 |
|
| 822 |
vikas |
247 |
public static boolean validatePin(String pincode) {
|
|
|
248 |
int pin;
|
|
|
249 |
try {
|
|
|
250 |
pin = Integer.parseInt(pincode);
|
|
|
251 |
}
|
|
|
252 |
catch (NumberFormatException e) {
|
|
|
253 |
return false;
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
if (pin < 100000 || pin > 999999) {
|
|
|
257 |
return false;
|
|
|
258 |
}
|
|
|
259 |
return true;
|
|
|
260 |
}
|
| 4891 |
varun.gupt |
261 |
|
|
|
262 |
public static boolean isValidEmail(String emailAddress) {
|
|
|
263 |
|
|
|
264 |
if(emailAddress == null || emailAddress.isEmpty()) {
|
|
|
265 |
return false;
|
|
|
266 |
}
|
|
|
267 |
try {
|
|
|
268 |
InternetAddress address = new InternetAddress(emailAddress, true);
|
|
|
269 |
address.validate();
|
|
|
270 |
return true;
|
|
|
271 |
|
|
|
272 |
} catch (AddressException e) {
|
|
|
273 |
logger.error(emailAddress + " is not valid email address ", e);
|
|
|
274 |
return false;
|
|
|
275 |
}
|
|
|
276 |
}
|
| 822 |
vikas |
277 |
|
|
|
278 |
public static boolean validatePhone(String phone) {
|
| 839 |
vikas |
279 |
long iPhone;
|
| 822 |
vikas |
280 |
try {
|
| 839 |
vikas |
281 |
iPhone = Long.parseLong(phone);
|
| 822 |
vikas |
282 |
}
|
|
|
283 |
catch (NumberFormatException e) {
|
|
|
284 |
return false;
|
|
|
285 |
}
|
| 839 |
vikas |
286 |
|
|
|
287 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
288 |
return false;
|
|
|
289 |
}
|
| 822 |
vikas |
290 |
return true;
|
|
|
291 |
}
|
| 3209 |
vikas |
292 |
|
|
|
293 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
294 |
List<String> itemIds = new ArrayList<String>();
|
|
|
295 |
for (Line line : cart.getLines()) {
|
|
|
296 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
297 |
}
|
|
|
298 |
return StringUtils.join(itemIds, '_');
|
|
|
299 |
}
|
|
|
300 |
|
| 17646 |
amit.gupta |
301 |
public static String fetchUrl(String url) throws Exception{
|
|
|
302 |
HttpClient client = new DefaultHttpClient();
|
|
|
303 |
HttpGet request = new HttpGet(url);
|
|
|
304 |
HttpResponse response = client.execute(request);
|
|
|
305 |
StringBuffer textView = new StringBuffer();
|
|
|
306 |
|
|
|
307 |
// Get the response
|
|
|
308 |
BufferedReader rd = new BufferedReader
|
|
|
309 |
(new InputStreamReader(response.getEntity().getContent()));
|
|
|
310 |
|
|
|
311 |
String line = "";
|
|
|
312 |
while ((line = rd.readLine()) != null) {
|
|
|
313 |
textView.append(line);
|
|
|
314 |
}
|
|
|
315 |
return textView.toString();
|
|
|
316 |
}
|
|
|
317 |
|
| 3209 |
vikas |
318 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
319 |
List<String> itemIds = new ArrayList<String>();
|
|
|
320 |
if (orders != null) {
|
|
|
321 |
for (Order order : orders) {
|
|
|
322 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
323 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
}
|
|
|
327 |
return StringUtils.join(itemIds, '_');
|
| 6135 |
anupam.sin |
328 |
}
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
public static String getRechargeProviderName(long providerId) {
|
|
|
333 |
return providersMap.get(providerId);
|
|
|
334 |
}
|
| 6178 |
anupam.sin |
335 |
|
|
|
336 |
public static Map<Long, String> getMobileProvidersMap() {
|
|
|
337 |
return mobileProvidersMap;
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
public static Map<Long, String> getDthProvidersMap() {
|
|
|
341 |
return dthProvidersMap;
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
public static Map<Long, List<RechargePlan>> getOperatorPlanMap() {
|
|
|
345 |
return operatorPlanMap;
|
|
|
346 |
}
|
| 6204 |
rajveer |
347 |
|
| 6208 |
rajveer |
348 |
public static Map<String, Map<String, String>> getUriOperatorMap(){
|
|
|
349 |
return uriOperatorMap;
|
|
|
350 |
}
|
|
|
351 |
|
| 6204 |
rajveer |
352 |
public static Map<String, String> getOperatorByUri(String uri){
|
|
|
353 |
return uriOperatorMap.get(uri);
|
|
|
354 |
}
|
| 20180 |
aman.kumar |
355 |
|
|
|
356 |
private final String USER_AGENT = "Mozilla/5.0";
|
|
|
357 |
public final static String METHOD_POST = "POST";
|
|
|
358 |
public final static String METHOD_GET = "GET";
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
public String callRestApi(String apiUrl,String method,Map<String, String> paramsMap, Map<String, String> requestProperty){
|
|
|
362 |
StringBuffer response = new StringBuffer();
|
| 20185 |
aman.kumar |
363 |
StringBuffer urlParameters= new StringBuffer("");
|
| 20180 |
aman.kumar |
364 |
try{
|
|
|
365 |
|
|
|
366 |
if (paramsMap != null) {
|
|
|
367 |
for (Entry<String, String> entry : paramsMap.entrySet()) {
|
|
|
368 |
urlParameters.append(entry.getKey() + "=" + entry.getValue() + "&");
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
if (METHOD_GET.equalsIgnoreCase(method)) {
|
|
|
372 |
apiUrl += "?"+urlParameters.toString();
|
|
|
373 |
}
|
|
|
374 |
URL obj = new URL(apiUrl);
|
|
|
375 |
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
|
|
376 |
if (apiUrl.startsWith("https")) {
|
|
|
377 |
con = (HttpsURLConnection) obj.openConnection();
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
// add reuqest header
|
|
|
381 |
con.setRequestMethod(method);
|
|
|
382 |
con.setRequestProperty("User-Agent", USER_AGENT);
|
|
|
383 |
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
|
|
|
384 |
|
|
|
385 |
if (requestProperty != null) {
|
|
|
386 |
for (Entry<String, String> entry : requestProperty.entrySet()) {
|
|
|
387 |
con.setRequestProperty(entry.getKey(), entry.getValue());
|
|
|
388 |
}
|
|
|
389 |
}
|
|
|
390 |
// Send Post request
|
|
|
391 |
if (METHOD_POST.equalsIgnoreCase(method)) {
|
|
|
392 |
con.setDoOutput(true);
|
|
|
393 |
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
|
|
|
394 |
wr.writeBytes(urlParameters.toString());
|
|
|
395 |
wr.flush();
|
|
|
396 |
wr.close();
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
int responseCode = con.getResponseCode();
|
|
|
400 |
System.out.println("\nSending request to URL : " + apiUrl);
|
|
|
401 |
System.out.println("Post parameters : " + urlParameters);
|
|
|
402 |
System.out.println("Response Code : " + responseCode);
|
|
|
403 |
|
|
|
404 |
if(responseCode==200){
|
|
|
405 |
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
|
406 |
String inputLine;
|
|
|
407 |
|
|
|
408 |
while ((inputLine = in.readLine()) != null) {
|
|
|
409 |
response.append(inputLine);
|
|
|
410 |
}
|
|
|
411 |
in.close();
|
|
|
412 |
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
// print result
|
|
|
416 |
System.out.println(response.toString());
|
|
|
417 |
}catch(Exception e){
|
|
|
418 |
|
|
|
419 |
}
|
|
|
420 |
return response.toString();
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
public static void main(String args[]){
|
|
|
424 |
|
|
|
425 |
//new Utils().callRestApi("https://graph.facebook.com/debug_token", Utils.METHOD_GET, paramsMap, null);
|
|
|
426 |
}
|
| 4891 |
varun.gupt |
427 |
}
|