|
@@ -1,47 +1,48 @@
|
|
|
|
|
|
package com.example.helloworld;
|
|
package com.example.helloworld;
|
|
|
|
|
|
-import java.net.UnknownHostException;
|
|
|
|
-
|
|
|
|
-import org.mongojack.JacksonDBCollection;
|
|
|
|
-
|
|
|
|
-import com.example.helloworld.core.World;
|
|
|
|
|
|
+import com.example.helloworld.config.HelloWorldConfiguration;
|
|
|
|
+import com.example.helloworld.db.FortuneDAO;
|
|
import com.example.helloworld.db.MongoHealthCheck;
|
|
import com.example.helloworld.db.MongoHealthCheck;
|
|
import com.example.helloworld.db.MongoManaged;
|
|
import com.example.helloworld.db.MongoManaged;
|
|
|
|
+import com.example.helloworld.db.WorldDAO;
|
|
|
|
+import com.example.helloworld.resources.FortuneResource;
|
|
import com.example.helloworld.resources.JsonResource;
|
|
import com.example.helloworld.resources.JsonResource;
|
|
|
|
+import com.example.helloworld.resources.TextResource;
|
|
import com.example.helloworld.resources.WorldResource;
|
|
import com.example.helloworld.resources.WorldResource;
|
|
import com.mongodb.DB;
|
|
import com.mongodb.DB;
|
|
-import com.mongodb.Mongo;
|
|
|
|
-import com.yammer.dropwizard.Service;
|
|
|
|
-import com.yammer.dropwizard.config.Bootstrap;
|
|
|
|
-import com.yammer.dropwizard.config.Environment;
|
|
|
|
|
|
+import com.mongodb.MongoClient;
|
|
|
|
+import io.dropwizard.Application;
|
|
|
|
+import io.dropwizard.setup.Bootstrap;
|
|
|
|
+import io.dropwizard.setup.Environment;
|
|
|
|
+
|
|
|
|
+import java.net.UnknownHostException;
|
|
|
|
|
|
public class HelloWorldService
|
|
public class HelloWorldService
|
|
- extends Service<HelloWorldConfiguration>
|
|
|
|
-{
|
|
|
|
-
|
|
|
|
- public static void main(String[] args) throws Exception
|
|
|
|
- {
|
|
|
|
- new HelloWorldService().run(args);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap)
|
|
|
|
- {
|
|
|
|
- bootstrap.setName("hello-world");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void run(HelloWorldConfiguration config, Environment environment) throws UnknownHostException
|
|
|
|
- {
|
|
|
|
- Mongo mongo = new Mongo(config.mongohost, config.mongoport);
|
|
|
|
- MongoManaged mongoManaged = new MongoManaged(mongo);
|
|
|
|
- environment.manage(mongoManaged);
|
|
|
|
- environment.addHealthCheck(new MongoHealthCheck(mongo));
|
|
|
|
- DB db = mongo.getDB(config.mongodb);
|
|
|
|
- JacksonDBCollection<World, String> worlds = JacksonDBCollection.wrap(db.getCollection("world"), World.class, String.class);
|
|
|
|
- environment.addResource(new WorldResource(worlds));
|
|
|
|
- environment.addResource(new JsonResource());
|
|
|
|
- }
|
|
|
|
|
|
+ extends Application<HelloWorldConfiguration> {
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
|
+ new HelloWorldService().run(args);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void run(HelloWorldConfiguration config, Environment environment) throws UnknownHostException {
|
|
|
|
+ MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
|
|
|
|
+ environment.lifecycle().manage(new MongoManaged(mongoClient));
|
|
|
|
+ environment.healthChecks().register("mongo", new MongoHealthCheck(mongoClient));
|
|
|
|
+
|
|
|
|
+ DB db = mongoClient.getDB(config.mongo.db);
|
|
|
|
+ WorldDAO worldDAO = new WorldDAO(db);
|
|
|
|
+ FortuneDAO fortuneDAO = new FortuneDAO(db);
|
|
|
|
+
|
|
|
|
+ environment.jersey().register(new JsonResource());
|
|
|
|
+ environment.jersey().register(new WorldResource(worldDAO));
|
|
|
|
+ environment.jersey().register(new FortuneResource(fortuneDAO));
|
|
|
|
+ environment.jersey().register(new TextResource());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
|
|
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|