Dropwizard is a Java framework that provides tools for building RESTful web services. It bundles several popular Java libraries - like Jersey for JAX-RS, Jetty as an embedded HTTP server, Jackson for JSON processing, Metrics for monitoring, and Hibernate Validator - into an easy to use package. Dropwizard makes it simple to build robust, production-ready REST APIs without needing a separate application server. The framework also makes it easy to integrate with Spring for dependency injection. Overall, Dropwizard provides a best-of-breed toolkit for building RESTful services in Java.
2. Welcome to Houston TechFest
Thank you for being a part of the
7th Annual Houston TechFest!
Please turn off all electronic devices or set them to vibrate.
If you must take a phone call, please do so in the lobby so
as not to disturb others.
Thanks to our Diamond Sponsors:
2
3. Information
Speaker presentation slides will be available at www.houstontechfest.org within a
week
Don’t forget to complete the Bingo card to be eligible for door prizes
3
6. Dropwizard
Best-of-breed Java libraries integrated into one
embedded application package
●
Embedded Jetty (no WAR, no external servlet container)
●
JAX-RS (Jersey) for REST APIs
●
JSON (Jackson)
●
Logging (Logback and SLF4J)
●
Hibernate Validators
●
Metrics (application SLA and performance)
6
7. Dropwizard
Embedded Jetty
●
Restart your code in seconds. Run your code from the IDE.
●
No WAR to recompile (ever!)
●
No WAR to redeploy (ever!)
●
No servlet container (Tomcat, Websphere, Weblogic, etc) to install
●
●
●
Debug from your IDE (you have a main()), no need to attach to a separate
process
No need to share heap and GC issues with other apps running in the same
servlet container
Total process isolation (one misbehaving WAR (e.g. OutOfMemoryException)
cannot bring down the entire server process)
7
8. Dropwizard
Anatomy of a Dropwizard application
Jetty
Jersey
YOUR CODE
(business logic, DAO,
Spring, JPA, etc.)
8
9. Dropwizard
Multiple apps on the same server
pid 1843
Jetty
Jersey
APP 1
Own JVM
4 GB heap
Jersey
APP 2
Own JVM
4 GB heap
Jersey
APP 3
Own JVM
4 GB heap
pid 1407
Jetty
pid 1976
Jetty
9
10. Dropwizard
Operations-friendly and ready for deployment
●
Opens 2 HTTP ports: one for public APIs (i.e. your REST services), one for
admin APIs (e.g. run GC, refresh internal caches, etc)
●
Admin port can be closed off on the firewall and inaccessible to outside world
●
Health Check APIs to allow easy monitoring from external tools like Nagios
●
@Timed annotation on any single REST API allows to track its SLA using Metrics
library
10
11. Dropwizard
Ease of deployment
●
●
Dropwizard apps can be easily compiled into a single JAR with all dependencies
(e.g. using Maven Shade or Gradle Shadow plugins)
Your entire app consists of two files:
YAML config file
JAR application file
●
Trivial to run from command line:
java -server myapp.jar server myapp.yml
11
12. Dropwizard
Ease of deployment – part 2
●
Can be wrapped in an RPM or DEB to install on Linux clusters
●
Can be registered as a Linux daemon, e.g.
sudo start myapp
sudo stop myapp
12
13. Dropwizard
Embedding HTML resources
●
●
●
Dropwizard provides the concept of AssetBundle, which allows to bundle
HTML/JS/CSS assets directly in the app (via your src/main/resources folder)
Perfect for creating a modern HTML5 Javascript UI (Backbone.js, Ember.js,
Angular.js, etc) powered by rock-solid super fast Java REST APIs – the best of
both worlds
In 2013, you should not be using any Java (or .Net or Python or Ruby) serverside web frameworks.
HTML5 and Javascript have won and are the future of web development.
Java is best at providing REST APIs to power them with top reliability and
performance.
13
15. Dropwizard and Spring
Integrating Spring DI
●
●
●
●
Start up parent Spring context (AnnotationConfigWebApplicationContext)
Inject Dropwizard Configuration object into it (so that it is available as a Spring
bean)
Start a child context (with the parent in it), also of type
AnnotationConfigWebApplicationContext
Extract all the Spring beans that Dropwizard cares about from the context and
register them within Dropwizard:
–
–
●
JAX-RS @Path resources and @Provider classes
Dropwizard Task and HealthCheck objects
Link Spring with the embedded Jetty instance, so that it behaves just as if it were
running in a regular servlet container
15
16. Dropwizard and Spring
Integrating Spring DI – part 2
Sample app with a full example:
https://github.com/jacek99/dropwizard-spring-di-security-onejar-example
In particular this class has all the low-level details:
MyAppService.java
16
18. Dropwizard and Spring Security
●
@ImportResource Spring Security XML config file into your root Spring
@Configuration class
●
Activate Spring Security filter
●
Provides both HTTP and method level (@Secured) support
●
Present in github sample app covered previously
18
20. Dropwizard
●
●
Dropwizard is a godsend for all those of us who just need to get stuff DONE.
Dropwizard changed the rules of the game completely. We have dramatically
changed the way of working and increased the speed of whole development
process. Dropwizard is being considered as a Restful Application Framework but
this is totally unfair and limiting its potential. We have just added a few classes
without forking it to operate Spring Framework and it is working wonderfully. That
is to say, Dropwizard can be also considered as a "embedded application
development framework" and we are using in this way
20
22. Please Leave Feedback During Q&A
If you leave
session feedback
and provide
contact
information, you
will be qualified for
a prize
Scan the QR code
to the right or go
to bit.ly/htf130514
22