Subversion Repositories SmartDukaan

Rev

Rev 15594 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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