Playing with Dropwizard framework.
A sample application shows how Dropwizard seamlessly integrates and instantiates - Jetty server, jersey framework for RESTful webservices, Jackson for JSON, metrics library.
Introduction
Dropwizard is a bit of both - framework and a library. It consists of below modules.
Jetty HTTP Library and embedded HTTP server. Dropwizard uses Jetty HTTP library and uses an embedded HTTP server. Dropwizard is reponsible for spinning and starting that HTTP webserver for you.
Jersey framework (RESTful web framework). JAX-RS reference implementation. JAX-RS is a Java API for RESTful webservices. Supports creating webservices according to RESTful architectural principles.
Jersey is very useful in building RESTful web applications. HTTP requests map to Java Objects.
Jackson for JSON - Object mapper from JSON to Java objects.
Metrics library - Library to get metric insights into your application. Get insights into your code and how it is invoked in staging and production environment.
Guava
Logback (along with slf4j) - logging framework
Hibernate Validator - Reference implementation of Java Bean validation standard.
Project structure -
project-api (should contain ‘Representations’).
project-client (consumer of the above representation classes).
project-application (actual application implementation).
Representation class - The class that is responsible for payload JSON structure.
Resources class - This class models the resources exposed in your RESTful API using Jersey which is a RESTful web framework.
How to run this application?
Step 1 - Go to Maven and run package lifecycle on your root maven pom. This will generate the necessary jar.
Step 2 - Assume your config file is 'config folder'. Go to directory where root pom file is saved and run the following command -
java -jar dropwizard-project-application/target/dropwizard-project-application-1.0-SNAPSHOT.jar server config/config.yml
This should start your Jetty server and you can now issue GET REST requests by going to the browser or run wget from command line.