Marc Rufer bio photo

Marc Rufer

Software engineer
@d-fens GmbH

Twitter Google+ LinkedIn Github Stackoverflow
RSS Feed

First steps with Dropwizard

Marc Rufer 06 Jun 2015 RESTful Dropwizard Java development

Once at work a friend asked me, if I know dropwizard. I have never heard about it before, so I decided to have a look at it and try it out. Dropwizard is a Java framework for development of high-performance RESTful web services.

To get in touch with dropwizard I went through the getting started guide. I created a new repository at GitHub, where I checked in the source code I wrote while going through the getting started guide.

Under the hood

The Dropwizard framework uses the Jetty HTTP library for embedding a HTTP server directly into the project. Dropwizard applications are usually delivered as a FAT-jar, which contain a main method to spin up the embedded HTTP server. The RESTful services developed with Dropwizard are based on jersey and for JSON serialization and deserialization the framework uses the Jackson JSON library. Dropwizard applications support operation tools for metrics, thread dumps, ping and health checks out of the box and are capable of doing 30’000-50’000 requests per second.

Project setup

The setup of a Dropwizard project was quite easy. Such an application consists out of the following parts:

  • Configuration class In the configuration class the environment specific parameters are defined. In this case the template message template and the default name. The values of these parameters are defined in a YAML-file (example.yml).

  • Configuration file (YAML) This file contains the values of the parameters defined in the configuration class.

  • Application class Similar to spring boot you have to define an application class, which has to extend the Application class from Dropwizard parametrized with the configuration class. It contains the main method, which runs the HTTP server. In the run method you have to define and register the health checks and resources (Examples of health check and resource classes can be found below).

  • Representation class This class is optional, but was added to wrap the REST responses into a common top level object, which always contains an id and a data object.

  • Resource class The resource class describes the REST resource and is associated with an URI template. The getExample method defines a GET endpoint, which serves a response wrapper object containing some data in the content JSON object. The @Timed annotation on the getExample method causes that the duration and rate of its invocations is automatically recorded as a Metrics Timer.

There is a possibility to create custom health check classes, which expose health check data to the operation tools.

It’s recommended to build Dropwizard application as FAT-jars. How to do that using Maven is described in the getting started guide.

For more details have a look at my example project @GitHub and into the getting started guide.

Conclusion

Throughout this short dive into Dropwizard I noticed that the framework is easy to use and works very well. The getting started guide is well illustrated and contains good descriptions of every part of the application. Especially impressive was the out of the box operational tools (metrics, thread dump, ping and health check). I didn’t do some load test, so I can’t place any statement about performance, but as written in the documentation Dropwizard applications should be able to handle 30’000-50’000 requests per second. I think the framework is a good option for implementing RESTful web service i.e. microservices. As well for creating demonstrations or PoC it would be a straight forward approach using Dropwizard.

comments powered by Disqus

Posts

HOWTO Access Azure File Share in PowerShell Script executed by a Scheduled Task BUG "Task Scheduler service is not available" Error, if specifying Network Connection Condition HOWTO Sync OneDrive on Server even if Windows User not logged in HOWTO Access Microsoft Access Database with PowerShell Get NetworkCredential from PSCredential splits Username into Username and Domain HOWTO Create LocalDB File (.mdf) manually in Visual Studio 2015 HOWTO Set Cookie Header on DefaultRequestHeaders of HttpClient HOWTO Set up PowerShell Remote Session Configuration HOWTO Analyze PowerShell Scripts with PSScriptAnalyzer HOWTO Sign PDF with SuisseID NoBrainer PUT/PATCH/MERGE with OData Service Client Apply Commit from one Repository to another GitHub Repository creation with PowerShell HOWTO Sign PowerShell Script with SuisseID Swissunihockey game schedule PDF generator HOWTO Maven Release on JetBrains TeamCity Limitations when running Activiti in H2 Embedded Mode HOWTO Pylint Integration in IntelliJ 14 HOWTO Install Windows 10 IoT Core on Raspberry PI 2 from a VM First steps with Dropwizard Allman code style for IntelliJ First steps with Flyway IntelliJ - Setup custom inspection profiles Configuration properties meta-data support in IntelliJ AMQP Integration with spring integration OCA Java SE 7 Programmer I Certification Guide Swissunihockey key matcher Swisscom SMS-API-Client Some hints concerning logging with Log4j IFTTT A brilliant service Run deltacloud on a VirtualBox-VM Project specific maven settings in IntelliJ AngularJS Javascript for beginners Liferay in Action