001package io.jstach.opt.dropwizard.example;
002
003import io.dropwizard.core.Application;
004import io.dropwizard.core.setup.Bootstrap;
005import io.dropwizard.core.setup.Environment;
006import io.dropwizard.views.common.ViewBundle;
007
008/**
009 * Dropwizard example application entry point.
010 *
011 * @author agentgt
012 *
013 */
014public class ExampleApplicationStart extends Application<ExampleConfiguration> {
015
016        /**
017         * Main method entrypoint for the application. If no args are passed we assume that
018         * "<code>server</code>" is the desired mode.
019         * @param args if empty <code>["server"]</code> will be used.
020         * @throws Exception if the application fails to start
021         */
022        public static void main(String[] args) throws Exception {
023                String[] resolved = args;
024                if (resolved.length == 0) {
025                        resolved = new String[] { "server" };
026                }
027                new ExampleApplicationStart().run(resolved);
028        }
029
030        @Override
031        public void run(ExampleConfiguration configuration, @SuppressWarnings("exports") Environment environment)
032                        throws Exception {
033                /*
034                 * This health check is just to make dropwizard happy
035                 */
036                environment.healthChecks().register("template", new TemplateHealthCheck("JSTACHIO"));
037                environment.jersey().register(new ExampleResource());
038        }
039
040        @Override
041        public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
042                /*
043                 * We could explicitly add JStachioViewRenderer here but it will be picked up by
044                 * the sevice loader.
045                 */
046                bootstrap.addBundle(new ViewBundle<>());
047        }
048
049}