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         * Do nothing constructor
018         */
019        public ExampleApplicationStart() {
020        }
021
022        /**
023         * Main method entrypoint for the application. If no args are passed we assume that
024         * "<code>server</code>" is the desired mode.
025         * @param args if empty <code>["server"]</code> will be used.
026         * @throws Exception if the application fails to start
027         */
028        public static void main(String[] args) throws Exception {
029                String[] resolved = args;
030                if (resolved.length == 0) {
031                        resolved = new String[] { "server" };
032                }
033                new ExampleApplicationStart().run(resolved);
034        }
035
036        @Override
037        public void run(ExampleConfiguration configuration, @SuppressWarnings("exports") Environment environment)
038                        throws Exception {
039                /*
040                 * This health check is just to make dropwizard happy
041                 */
042                environment.healthChecks().register("template", new TemplateHealthCheck("JSTACHIO"));
043                environment.jersey().register(new ExampleResource());
044        }
045
046        @Override
047        public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
048                /*
049                 * We could explicitly add JStachioViewRenderer here but it will be picked up by
050                 * the sevice loader.
051                 */
052                bootstrap.addBundle(new ViewBundle<>());
053        }
054
055}