Almost five years in the making, Dropwizard's Java RESTful Web Service framework version 1.0.0 offers a host of new features and the latest versions of supporting Java APIs.
Features in this milestone release include:
- Full Java 8 support
- Latest versions of supporting software such as:
The full list can be found in the release notes section of their website.
As defined in the website:
Dropwizard is a Java framework for developing ops-friendly, high-performance, RESTful web services.
Dropwizard is organized into a series of modules:
- Dropwizard Core (everything required for most applications)
- Dropwizard Client (Apache HttpClient and Jersey Client)
- Dropwizard JDBI (managed access to JDBI)
- Dropwizard Migrations (wrapper for Liquibase)
- Dropwizard Hibernate (managed access to Hibernate)
- Dropwizard Authentication (provides authentication using basic authentication or OAuth)
- Dropwizard Forms (supports multipart forms with Jersey)
- Dropwizard Validation (includes Hibernate Validator)
- Dropwizard Views (FreeMarker and Mustache)
There is also Scala support for Dropwizard.
Getting Started
The Getting Started guide provides an overview and step-by-step instructions to create a basic “hello, world!” application. The guide recommends Maven for building the application, but other build tools such as Ant, Gant, Gradle, or SBT may also be used.
The following Maven command generates a basic Dropwizard application in interactive mode:
mvn archetype:generate -DarchetypeGroupId=io.dropwizard.archetypes -DarchetypeArtifactId=java-simple -DarchetypeVersion=1.0.0
It’s important to answer the prompts correctly, for example:
- $groupId: used for source code packaging, e.g., com.example or io.dropwizard, and is used as a default value for $package.
- $artifactID: used to generate the root directory of the application, e.g., dropwizard-1.0.0.
- $version: 1.0-SNAPSHOT by default.
- $package: the default value is read from $groupId.
- $name: Camel case name, e.g., HelloWorld. This generates HelloWorldApplication.java and HelloWorldConfiguration.java which extend the base classes, Application.java and Configuration.java, respectively.
[Click on the image to enlarge it]
Once the remainder of the tutorial is completed, the example can be run on the user’s local machine with a URL such as http://localhost:8080/hello-world?name=Michael+Redlich which yields the following server response:
A database version of the “hello, world!” application can be found on GitHub.
A More Complex Example
A more complex example application was created by Al Scott, lead developer at Campspot, and time-honored contributor to Atomic Object’s blog, Atomic Spin. His three-part series on implementing authentication, authorization, and multitenancy demonstrates those particular features of Dropwizard. Since Scott’s series was written for Dropwizard 0.9.x, InfoQ spoke to him about this milestone release.
InfoQ: Why do you prefer Dropwizard?
Al Scott: Having worked with a lot of different web platforms in my career, I’ve never felt as productive as I do with Dropwizard. All of the components are rock solid and well thought out, so I can focus on getting stuff done. Whenever I need to dive into the framework code to figure out how something works, it's been a pleasure, because the Dropwizard source is some of the best and easiest to understand code I’ve ever worked with. I also appreciate the general stability of the framework. Updates are generally very feature-rich while also being easy to apply with minimum breakage. The underlying core libraries (Jersey, Jetty, Jackson, Hibernate) are all very stable as well, so there are rarely big surprises when there are version bumps.
InfoQ: What sets Dropwizard apart from other Java frameworks for developing RESTful web services?
Scott: I think the simplicity of building and running Dropwizard is the key thing that sets it apart. Having worked with various Spring MVC and Tomcat/Websphere setups in the past I appreciate being able to set up just a single pom file for the project and getting a jar that I can run directly in return. This has been huge for us on the operations side since it makes our service trivial to deploy and we don’t have to mess with WAR files and complex XML configurations. I also appreciate how little Dropwizard deviates from the underlying libraries. Is provides some nice abstractions where they help, but overall leaves the libraries as-is so that it is easy to apply things from the underlying documentation.
InfoQ: Would any part of your example application be adversely affected by upgrading to Dropwizard version 1.0?
Scott: I actually updated the Github repository for my posts to work with Dropwizard 1.0. It took about 10 minutes. There was one interface, `io.dropwizard.auth.Authenticator` That changes from using Guava’s optional class to the built in Java 8 Optional. I had a similar experience upgrading our production app which has a much bigger codebase. The only other issue I ran into in production was having to patch a logging appender we use that haven’t been transitioned to 1.0 yet. Overall the upgrade is very straightforward and I can’t think of any reason for most people not to do it ASAP.
InfoQ: Are there opportunities to enhance your example application by upgrading to Dropwizard version 1.0?
Scott: In our production app, we have been liking the resource method return value validation that was added. The enhanced Java 8 support is also great, there used to be a few edge cases where you had to use Guava Optionals and Joda time that now work with the Java 8 equivalents.
Organizations using Dropwizard in production include:
Dropwizard provides a user manual to learn more and developers are encouraged to contribute by visiting the Dropwizard GitHub repository.