Subversion Repositories SmartDukaan

Rev

Rev 15595 | 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";
15597 kshitij.so 22
	private static final String VOI_COOKIE_COLLECTION = "VoiCookies";
15590 kshitij.so 23
 
15597 kshitij.so 24
 
15590 kshitij.so 25
	static{
26
		String mongoHost = "localhost";
27
		try {
28
			mongoHost = ConfigClient.getClient().get("support_backup_host");
29
		} catch (ConfigException e) {
30
		    log.error("Unable to get mongo host using localhost", e);
31
		}
32
		try {
33
			mongo = new MongoClient( mongoHost , 27017 );
34
		} catch (UnknownHostException e) {
35
			e.printStackTrace();
36
		}
37
	}
38
 
39
	public String getCookies() throws Exception{
40
		DB db = mongo.getDB(SNAPDEAL_DB);
41
		DBCollection collection = db.getCollection(COOKIE_COLLECTION);
42
		DBObject result = collection.findOne();
43
		if (result==null){
44
			throw new Exception();
45
		}
46
		return result.toString();
47
	}
48
 
15597 kshitij.so 49
	public String getVoiCookies() throws Exception{
50
		DB db = mongo.getDB(SNAPDEAL_DB);
51
		DBCollection collection = db.getCollection(VOI_COOKIE_COLLECTION);
52
		DBObject result = collection.findOne();
53
		if (result==null){
54
			throw new Exception();
55
		}
56
		return result.toString();
57
	}
58
 
15590 kshitij.so 59
	public static void main(String[] args) throws Exception{
60
		SnapdealSessionCookie sc = new SnapdealSessionCookie();
61
		sc.getCookies();
62
	}
63
 
64
}