Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update src/main/java/com/heroku/test/Main.java

  • Loading branch information...
commit 151a60d22eba8255f115a4a1046724f01fb50c08 1 parent 39655b5
Martijn Dashorst authored November 28, 2011

Showing 1 changed file with 7 additions and 21 deletions. Show diff stats Hide diff stats

  1. 28  src/main/java/com/heroku/test/Main.java
28  src/main/java/com/heroku/test/Main.java
@@ -12,7 +12,7 @@
12 12
 import org.eclipse.jetty.webapp.WebAppContext;
13 13
 
14 14
 import com.mongodb.DB;
15  
-import com.mongodb.Mongo;
  15
+import com.mongodb.MongoURI;
16 16
 
17 17
 /**
18 18
  * 
@@ -40,27 +40,13 @@ public static void main(String[] args) throws Exception{
40 40
         Server server = new Server(Integer.valueOf(webPort));
41 41
         WebAppContext root = new WebAppContext();
42 42
         
43  
-        
44  
-        
45  
-        
46  
-        //Parse mango db URL
47  
-        String mongoDbURL = System.getenv("MONGOHQ_URL");
48  
-        
49  
-        System.out.println("mongo url: " + mongoDbURL);
50  
-        
51  
-        Matcher matcher = Pattern.compile("mongodb://(.*):(.*)@(.*):(.*)/(.*)").matcher(mongoDbURL);
52  
-        matcher.find();
53  
-        
54  
-        String mongoUser = matcher.group(1);
55  
-        String mongoPassword = matcher.group(2);
56  
-        String mongoHost = matcher.group(3);
57  
-        String mongoPort = matcher.group(4);
58  
-        String mongoDatabase = matcher.group(5);
  43
+        MongoURI mongoDbURI = new MongoURI(System.getenv("MONGOHQ_URL"));
  44
+        DB connectedDB = mongoURI.connectDB();
59 45
 
60  
-        
61  
-        Mongo mongo = new Mongo(mongoHost, Integer.valueOf(mongoPort));
62  
-        DB db = mongo.getDB(mongoDatabase);
63  
-        db.authenticate(mongoUser, mongoPassword.toCharArray());
  46
+        // allow for localhost, non-authenticated Mongo use
  47
+		if (mongoURI.getUsername() != null) {
  48
+			connectedDB.authenticate(mongoURI.getUsername(), mongoURI.getPassword());
  49
+		}
64 50
         
65 51
         //Set up session handling through MongoDb
66 52
         MongoSessionIdManager idMgr = new MongoSessionIdManager(server, db.getCollection("sessions"));

0 notes on commit 151a60d

Please sign in to comment.
Something went wrong with that request. Please try again.