| 15590 |
kshitij.so |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import java.net.UnknownHostException;
|
|
|
4 |
|
|
|
5 |
import org.apache.log4j.Logger;
|
|
|
6 |
|
|
|
7 |
import com.mongodb.DB;
|
|
|
8 |
import com.mongodb.DBCollection;
|
|
|
9 |
import com.mongodb.DBObject;
|
|
|
10 |
import com.mongodb.MongoClient;
|
|
|
11 |
|
|
|
12 |
import in.shop2020.config.ConfigException;
|
|
|
13 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
14 |
|
|
|
15 |
public class SnapdealSessionCookie{
|
|
|
16 |
|
|
|
17 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
18 |
private static MongoClient mongo;
|
|
|
19 |
private static final String SNAPDEAL_DB = "Snapdeal";
|
|
|
20 |
private static final String COOKIE_COLLECTION = "Cookies";
|
|
|
21 |
|
|
|
22 |
static{
|
|
|
23 |
String mongoHost = "localhost";
|
|
|
24 |
try {
|
|
|
25 |
mongoHost = ConfigClient.getClient().get("support_backup_host");
|
|
|
26 |
} catch (ConfigException e) {
|
|
|
27 |
log.error("Unable to get mongo host using localhost", e);
|
|
|
28 |
}
|
|
|
29 |
try {
|
|
|
30 |
mongo = new MongoClient( mongoHost , 27017 );
|
|
|
31 |
} catch (UnknownHostException e) {
|
|
|
32 |
e.printStackTrace();
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public String getCookies() throws Exception{
|
|
|
37 |
DB db = mongo.getDB(SNAPDEAL_DB);
|
|
|
38 |
DBCollection collection = db.getCollection(COOKIE_COLLECTION);
|
|
|
39 |
DBObject result = collection.findOne();
|
|
|
40 |
if (result==null){
|
|
|
41 |
throw new Exception();
|
|
|
42 |
}
|
|
|
43 |
return result.toString();
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public static void main(String[] args) throws Exception{
|
|
|
47 |
SnapdealSessionCookie sc = new SnapdealSessionCookie();
|
|
|
48 |
sc.getCookies();
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
}
|