List of usage examples for com.mongodb MongoCredential createMongoCRCredential
@SuppressWarnings("deprecation") @Deprecated public static MongoCredential createMongoCRCredential(final String userName, final String database, final char[] password)
From source file:santandersensors_server.CollectThread.java
License:Open Source License
public CollectThread(JsonFile conf) { try {//from w w w.j a v a2s . co m this.cred = MongoCredential.createMongoCRCredential(conf.getJson().get("username").toString(), conf.getJson().get("userdatabase").toString(), conf.getJson().get("password").toString().toCharArray()); this.address = new ServerAddress(conf.getJson().get("IP").toString()); this.db = conf.getJson().get("maindatabase").toString(); this.collection = conf.getJson().get("maincollection").toString(); this.discardColl = conf.getJson().get("discardcollection").toString(); this.typeColl = conf.getJson().get("typecollection").toString(); this.lastdataColl = conf.getJson().get("lastdatacollection").toString(); this.tagsColl = conf.getJson().get("tagscollection").toString(); this.URL = conf.getJson().get("URL").toString(); this.lapse = Integer.parseInt(conf.getJson().get("lapse").toString()); //Creo la connessione a MongoDB this.client = new MongoTools(this.address, Arrays.asList(this.cred)); this.client.setDatabase(this.db); this.dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); this.cal = new GregorianCalendar(); } catch (Exception e) { System.out.print("(" + new GregorianCalendar().getTime() + ") -> "); System.out.print("error: " + e + "\n"); } }
From source file:santandersensors_server.ConsoleThread.java
License:Open Source License
public ConsoleThread(JsonFile conf, Socket s) { try {//from ww w.ja v a2s . co m this.cred = MongoCredential.createMongoCRCredential(conf.getJson().get("username").toString(), conf.getJson().get("userdatabase").toString(), conf.getJson().get("password").toString().toCharArray()); this.address = new ServerAddress(conf.getJson().get("IP").toString()); this.db = conf.getJson().get("maindatabase").toString(); ; this.collection = conf.getJson().get("maincollection").toString(); this.discardColl = conf.getJson().get("discardcollection").toString(); this.typeColl = conf.getJson().get("typecollection").toString(); this.tagsColl = conf.getJson().get("tagscollection").toString(); //Creo la connessione a MongoDB this.client = new MongoTools(this.address, Arrays.asList(this.cred)); this.client.setDatabase(this.db); this.mapReduceOBJ = new MapReduce(this.client, this.collection); this.S = s; } catch (Exception e) { this.interrupt(); } }
From source file:Singletons.SharedMongoMorphiaInstance.java
License:Open Source License
public static void loadConfiguration() { try {// w ww .ja v a 2 s . c o m MongoCredential credential = MongoCredential.createMongoCRCredential("admin", "admin", "$$PASdefumee1984".toCharArray()); ServerAddress server = new ServerAddress(Admin.ipMongo(), 27017); mongoClient = new MongoClient(server, Arrays.asList(credential)); morphia = new Morphia(); dsAccessToken = morphia.createDatastore(mongoClient, "AccessToken"); dsJobsInfos = morphia.createDatastore(mongoClient, "JobInfo"); dsSessions = morphia.createDatastore(mongoClient, "Session"); dsTweets = morphia.createDatastore(mongoClient, "Tweet"); dsUsers = morphia.createDatastore(mongoClient, "User"); morphia.map(AccessTokenPlus.class); morphia.map(JobInfo.class); morphia.map(Session.class); morphia.map(Tweet.class); morphia.map(User.class); } catch (UnknownHostException ex) { Logger.getLogger(SharedMongoMorphiaInstance.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:xbdd.webapp.factory.ServletContextMongoClientFactory.java
License:Apache License
private MongoDBAccessor getMongoDBAccessor() throws UnknownHostException { final MongoClient mc; if (this.username != null) { MongoCredential credentials = MongoCredential.createMongoCRCredential(this.username, "admin", this.password); mc = new MongoClient(new ServerAddress(this.host, this.port), Arrays.asList(credentials)); } else {//from ww w .j av a2 s . c om mc = new MongoClient(this.host, this.port); } return new MongoDBAccessor(mc); }