codahale/dropwizard — pull request #31 by tinkerware (2012-02-14 16:48:50+00:00)
Title: Allow services to customize the Jersey servlet container implementation

This change allows services to replace Jersey's `ServletContainer` with another implementation and customize the resource config directly. I found this necessary when integrating a service that used Guice and Jersey along with Jersey's Guice integration.

The nice thing about this is that it's a simple change but allows wholesale customization of Jersey while still keeping Dropwizard-specific features like instrumented resource methods. On the other hand, `getJerseyContainer` does get called before the service has a chance to initialize and that might make for some awkward init code on the service side. In my specific case that motivated this patch, the container implementation was being instantiated by Guice so all I had to do was to save the config for later injection to a custom `GuiceContainer` class (that comes with Jersey's Guice integration library). I think inverting the logic between `Environment` and `ServerFactory` and use a two-step configure/apply scheme to initialize the `ServerFactory` would make service initialization cleaner, but that seemed like too much surgery for what I wanted to accomplish.