├── dropwizard-core └── src │ ├── test │ ├── resources │ │ ├── empty.yml │ │ ├── json │ │ │ └── string.json │ │ ├── yaml │ │ │ ├── string.yml │ │ │ ├── gzip.yml │ │ │ ├── requestLog.yml │ │ │ └── http.yml │ │ ├── factory-test-malformed.yml │ │ ├── factory-test-invalid.yml │ │ ├── factory-test-valid.yml │ │ └── logging.yml │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ ├── util │ │ └── tests │ │ │ ├── JarLocationTest.java │ │ │ └── ServletsTest.java │ │ ├── tasks │ │ └── tests │ │ │ ├── TaskTest.java │ │ │ └── GarbageCollectionTaskTest.java │ │ ├── config │ │ └── tests │ │ │ ├── RequestLogConfigurationTest.java │ │ │ ├── ConfigurationExceptionTest.java │ │ │ ├── ConfigurationTest.java │ │ │ ├── GzipConfigurationTest.java │ │ │ ├── FilterConfigurationTest.java │ │ │ └── ServletConfigurationTest.java │ │ ├── jetty │ │ └── tests │ │ │ ├── JettyManagedTest.java │ │ │ └── NonblockingServletHolderTest.java │ │ ├── jersey │ │ └── params │ │ │ └── tests │ │ │ ├── IntParamTest.java │ │ │ └── LongParamTest.java │ │ ├── cli │ │ └── tests │ │ │ ├── ConfiguredCommandTest.java │ │ │ └── CommandTest.java │ │ ├── bundles │ │ └── tests │ │ │ └── JavaBundleTest.java │ │ ├── validation │ │ └── tests │ │ │ ├── MethodValidatorTest.java │ │ │ └── ValidatorTest.java │ │ ├── servlets │ │ └── tests │ │ │ └── CacheBustingFilterTest.java │ │ └── tests │ │ └── ServiceTest.java │ └── main │ └── java │ └── com │ └── yammer │ └── dropwizard │ ├── Bundle.java │ ├── jersey │ ├── caching │ │ ├── CacheControlledResourceMethodDispatchAdapter.java │ │ ├── CacheControlledRequestDispatcher.java │ │ └── CacheControlledResourceMethodDispatchProvider.java │ ├── params │ │ ├── LongParam.java │ │ ├── IntParam.java │ │ └── BooleanParam.java │ ├── DropwizardResourceConfig.java │ ├── OptionalExtractor.java │ ├── OptionalQueryParamInjectableProvider.java │ ├── MultivaluedParameterExtractorQueryParamInjectable.java │ └── LoggingExceptionMapper.java │ ├── validation │ ├── MethodValidator.java │ ├── ValidationMethod.java │ └── Validator.java │ ├── ConfiguredBundle.java │ ├── json │ ├── JsonSnakeCase.java │ └── LogbackModule.java │ ├── logging │ ├── SyslogFormatter.java │ ├── LogFormatter.java │ └── LoggingBean.java │ ├── lifecycle │ ├── Managed.java │ └── ExecutorServiceManager.java │ ├── util │ ├── Servlets.java │ └── JarLocation.java │ ├── config │ ├── SslConfiguration.java │ ├── ConfigurationException.java │ ├── RequestLogConfiguration.java │ ├── GzipConfiguration.java │ └── Configuration.java │ ├── jetty │ ├── JettyManaged.java │ └── NonblockingServletHolder.java │ ├── bundles │ └── JavaBundle.java │ ├── servlets │ ├── CacheBustingFilter.java │ ├── ThreadNameFilter.java │ └── SlowRequestFilter.java │ ├── tasks │ ├── Task.java │ └── GarbageCollectionTask.java │ ├── Service.java │ └── cli │ └── UsagePrinter.java ├── dropwizard-testing ├── src │ ├── test │ │ ├── resources │ │ │ └── fixtures │ │ │ │ ├── fixture.txt │ │ │ │ └── person.json │ │ └── java │ │ │ └── com │ │ │ └── yammer │ │ │ └── dropwizard │ │ │ └── testing │ │ │ └── tests │ │ │ ├── service │ │ │ ├── PeopleStore.java │ │ │ ├── PersonResource.java │ │ │ └── PersonResourceTest.java │ │ │ ├── FixtureHelpersTest.java │ │ │ ├── JsonHelpersTest.java │ │ │ └── Person.java │ └── main │ │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── testing │ │ └── FixtureHelpers.java └── pom.xml ├── dropwizard-views ├── src │ ├── test │ │ ├── resources │ │ │ ├── example.yml │ │ │ ├── example.ftl │ │ │ ├── com │ │ │ │ └── yammer │ │ │ │ │ └── dropwizard │ │ │ │ │ └── views │ │ │ │ │ └── yay.ftl │ │ │ ├── hello-world.ftl │ │ │ └── hello-world_fr.ftl │ │ └── java │ │ │ └── com │ │ │ └── yammer │ │ │ └── dropwizard │ │ │ └── views │ │ │ ├── MyOtherView.java │ │ │ ├── example │ │ │ ├── BadView.java │ │ │ ├── BadResource.java │ │ │ ├── Person.java │ │ │ ├── HelloWorldResource.java │ │ │ ├── HelloWorldView.java │ │ │ ├── AnotherResource.java │ │ │ └── TemplateService.java │ │ │ ├── MyView.java │ │ │ └── tests │ │ │ ├── ViewTest.java │ │ │ └── ViewBundleTest.java │ └── main │ │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── views │ │ ├── View.java │ │ └── ViewBundle.java └── pom.xml ├── docs ├── dropwizard-hat.eps └── source │ ├── dropwizard-logo.png │ ├── _static │ └── dropwizard-hat.png │ ├── about │ ├── todos.rst │ ├── index.rst │ ├── faq.rst │ └── contributors.rst │ ├── _themes │ └── yammerdoc │ │ ├── less │ │ ├── grid.less │ │ ├── utilities.less │ │ ├── component-animations.less │ │ ├── patterns.less │ │ ├── close.less │ │ ├── wells.less │ │ ├── hero-unit.less │ │ ├── print.less │ │ ├── layouts.less │ │ ├── labels.less │ │ ├── breadcrumbs.less │ │ ├── pager.less │ │ ├── accordion.less │ │ ├── scaffolding.less │ │ ├── thumbnails.less │ │ ├── tooltip.less │ │ ├── code.less │ │ ├── pagination.less │ │ ├── popovers.less │ │ ├── alerts.less │ │ ├── bootstrap.less │ │ ├── modals.less │ │ └── progress-bars.less │ │ ├── page.html │ │ ├── theme.conf │ │ ├── search.html │ │ └── genindex.html │ ├── manual │ ├── index.rst │ └── scala.rst │ └── index.rst ├── dropwizard-example ├── src │ └── main │ │ ├── resources │ │ ├── assets │ │ │ └── example.txt │ │ ├── banner.txt │ │ └── com │ │ │ └── example │ │ │ └── helloworld │ │ │ └── db │ │ │ └── PeopleDAO.sql.stg │ │ └── java │ │ └── com │ │ └── example │ │ └── helloworld │ │ ├── core │ │ ├── User.java │ │ ├── Saying.java │ │ ├── Template.java │ │ └── Person.java │ │ ├── resources │ │ ├── ProtectedResource.java │ │ ├── PersonResource.java │ │ ├── PeopleResource.java │ │ └── HelloWorldResource.java │ │ ├── health │ │ └── TemplateHealthCheck.java │ │ ├── auth │ │ └── ExampleAuthenticator.java │ │ ├── db │ │ └── PeopleDAO.java │ │ ├── HelloWorldConfiguration.java │ │ └── cli │ │ ├── SetupDatabaseCommand.java │ │ └── RenderCommand.java ├── example.keystore └── README.md ├── NOTICE ├── .gitignore ├── dropwizard-scala_2.9.1 └── src │ ├── main │ ├── scala │ │ └── com │ │ │ └── yammer │ │ │ └── dropwizard │ │ │ ├── Logging.scala │ │ │ └── ScalaService.scala │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── bundles │ │ └── ScalaBundle.java │ └── test │ ├── scala │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── examples │ │ ├── SayingFactory.scala │ │ ├── DumbHealthCheck.scala │ │ ├── ExampleConfiguration.scala │ │ ├── UploadResource.scala │ │ ├── HelloWorldResource.scala │ │ ├── StartableObject.scala │ │ ├── ExampleService.scala │ │ ├── SplodyResource.scala │ │ ├── SayCommand.scala │ │ └── SplodyCommand.scala │ └── resources │ └── banner.txt ├── dropwizard-auth ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── yammer │ │ │ └── dropwizard │ │ │ └── auth │ │ │ ├── Auth.java │ │ │ ├── AuthenticationException.java │ │ │ ├── Authenticator.java │ │ │ ├── oauth │ │ │ └── OAuthProvider.java │ │ │ └── basic │ │ │ ├── BasicAuthProvider.java │ │ │ └── BasicCredentials.java │ └── test │ │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── auth │ │ ├── User.java │ │ ├── oauth │ │ └── tests │ │ │ └── OAuthProviderTest.java │ │ └── basic │ │ └── tests │ │ ├── BasicAuthProviderTest.java │ │ └── BasicCredentialsTest.java └── pom.xml ├── dropwizard-db ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── yammer │ │ │ └── dropwizard │ │ │ ├── db │ │ │ ├── DatabaseHealthCheck.java │ │ │ ├── args │ │ │ │ ├── OptionalArgumentFactory.java │ │ │ │ └── OptionalArgument.java │ │ │ ├── ImmutableListContainerFactory.java │ │ │ ├── NamePrependingStatementRewriter.java │ │ │ ├── logging │ │ │ │ └── LogbackLog.java │ │ │ └── Database.java │ │ │ ├── bundles │ │ │ └── DBIExceptionsBundle.java │ │ │ └── jersey │ │ │ ├── LoggingSQLExceptionMapper.java │ │ │ └── LoggingDBIExceptionMapper.java │ └── test │ │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── db │ │ └── tests │ │ └── PersonDAO.java └── pom.xml ├── README.md ├── dropwizard-client ├── src │ └── main │ │ └── java │ │ └── com │ │ └── yammer │ │ └── dropwizard │ │ └── client │ │ ├── JerseyClient.java │ │ ├── JerseyClientConfiguration.java │ │ ├── JerseyClientFactory.java │ │ └── HttpClientConfiguration.java └── pom.xml └── findbugs-exclude.xml /dropwizard-core/src/test/resources/empty.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/json/string.json: -------------------------------------------------------------------------------- 1 | "a string" 2 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/yaml/string.yml: -------------------------------------------------------------------------------- 1 | "a string" 2 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/factory-test-malformed.yml: -------------------------------------------------------------------------------- 1 | j&&&& 2 | -------------------------------------------------------------------------------- /dropwizard-testing/src/test/resources/fixtures/fixture.txt: -------------------------------------------------------------------------------- 1 | YAY FOR ME 2 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/factory-test-invalid.yml: -------------------------------------------------------------------------------- 1 | name: Boop 2 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/factory-test-valid.yml: -------------------------------------------------------------------------------- 1 | name: Coda Hale 2 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/resources/example.yml: -------------------------------------------------------------------------------- 1 | http: 2 | shutdownGracePeriod: 0s 3 | -------------------------------------------------------------------------------- /docs/dropwizard-hat.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/al3x/dropwizard/master/docs/dropwizard-hat.eps -------------------------------------------------------------------------------- /dropwizard-example/src/main/resources/assets/example.txt: -------------------------------------------------------------------------------- 1 | Hello, I'm an example static asset file. 2 | -------------------------------------------------------------------------------- /docs/source/dropwizard-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/al3x/dropwizard/master/docs/source/dropwizard-logo.png -------------------------------------------------------------------------------- /dropwizard-example/example.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/al3x/dropwizard/master/dropwizard-example/example.keystore -------------------------------------------------------------------------------- /docs/source/_static/dropwizard-hat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/al3x/dropwizard/master/docs/source/_static/dropwizard-hat.png -------------------------------------------------------------------------------- /dropwizard-testing/src/test/resources/fixtures/person.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Coda", 3 | "email": "coda@example.com" 4 | } 5 | -------------------------------------------------------------------------------- /docs/source/about/todos.rst: -------------------------------------------------------------------------------- 1 | .. _about-todos: 2 | 3 | ################### 4 | Documentation TODOs 5 | ################### 6 | 7 | .. todolist:: 8 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Dropwizard 2 | Copyright 2011-2012 Coda Hale and Yammer, Inc. 3 | 4 | This product includes software developed by Coda Hale and Yammer, Inc. 5 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/resources/example.ftl: -------------------------------------------------------------------------------- 1 | <#-- @ftlvariable name="" type="com.yammer.dropwizard.views.MyView" --> 2 | Woop woop. ${name?html} 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | target 3 | atlassian-ide-plugin.xml 4 | logs 5 | *.iml 6 | *.ipr 7 | #Eclipse-specific 8 | .settings/ 9 | .classpath 10 | .project -------------------------------------------------------------------------------- /dropwizard-views/src/test/resources/com/yammer/dropwizard/views/yay.ftl: -------------------------------------------------------------------------------- 1 | <#-- @ftlvariable name="" type="com.yammer.dropwizard.views.MyOtherView" --> 2 | Ok. 3 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/yaml/gzip.yml: -------------------------------------------------------------------------------- 1 | enabled: false 2 | minimumEntitySize: 12KB 3 | bufferSize: 32KB 4 | excludedUserAgents: ["IE"] 5 | compressedMimeTypes: ["text/plain"] 6 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/yaml/requestLog.yml: -------------------------------------------------------------------------------- 1 | enabled: true 2 | currentLogFilename: "/var/log/dingo/dingo.log" 3 | archivedLogFilenamePattern: "/var/log/dingo/dingo-%d.log.zip" 4 | archivedFileCount: 5 5 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/main/scala/com/yammer/dropwizard/Logging.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard 2 | 3 | import logging.Log 4 | 5 | trait Logging { 6 | protected lazy val log: Log = Log.forClass(getClass) 7 | } 8 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/MyOtherView.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views; 2 | 3 | public class MyOtherView extends View { 4 | public MyOtherView() { 5 | super("yay.ftl"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /docs/source/about/index.rst: -------------------------------------------------------------------------------- 1 | .. title:: About 2 | 3 | .. _about: 4 | 5 | ################ 6 | About Dropwizard 7 | ################ 8 | 9 | .. toctree:: 10 | 11 | contributors 12 | faq 13 | release-notes 14 | todos 15 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/SayingFactory.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | object SayingFactory { 4 | def buildSaying(implicit config: ExampleConfiguration) = config.saying 5 | } 6 | -------------------------------------------------------------------------------- /dropwizard-testing/src/test/java/com/yammer/dropwizard/testing/tests/service/PeopleStore.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.testing.tests.service; 2 | 3 | import com.yammer.dropwizard.testing.tests.Person; 4 | 5 | public interface PeopleStore { 6 | Person fetchPerson(String name); 7 | } 8 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/grid.less: -------------------------------------------------------------------------------- 1 | // GRID SYSTEM 2 | // ----------- 3 | 4 | // Fixed (940px) 5 | #gridSystem > .generate(@gridColumns, @gridColumnWidth, @gridGutterWidth); 6 | 7 | // Fluid (940px) 8 | #fluidGridSystem > .generate(@gridColumns, @fluidGridColumnWidth, @fluidGridGutterWidth); 9 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/BadView.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | import com.yammer.dropwizard.views.View; 4 | 5 | public class BadView extends View { 6 | public BadView() { 7 | super("/woo-oo-ahh.txt"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/DumbHealthCheck.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import com.yammer.metrics.core.HealthCheck 4 | import com.yammer.metrics.core.HealthCheck.Result 5 | 6 | class DumbHealthCheck extends HealthCheck("dumb") { 7 | def check = Result.healthy 8 | } 9 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/core/User.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.core; 2 | 3 | public class User { 4 | private final String name; 5 | 6 | public User(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/BadResource.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | import javax.ws.rs.GET; 4 | import javax.ws.rs.Path; 5 | 6 | @Path("/bad") 7 | public class BadResource { 8 | @GET 9 | public BadView messUp() { 10 | return new BadView(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/Person.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | public class Person { 4 | private final String name; 5 | 6 | public Person(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/page.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/page.html 3 | ~~~~~~~~~~~~~~~ 4 | 5 | Master template for simple pages. 6 | 7 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {% extends "layout.html" %} 11 | {% block body %} 12 | {{ body }} 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/resources/hello-world.ftl: -------------------------------------------------------------------------------- 1 | <#-- @ftlvariable name="" type="com.yammer.dropwizard.views.example.HelloWorldView" --> 2 | 3 | 4 | 5 | Hello World! 6 | 7 | 8 |

Hello!

9 | 10 |

Hello, ${person.name?html}!

11 | 12 |

How's it going?

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/ExampleConfiguration.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import com.yammer.dropwizard.config.Configuration 4 | import org.codehaus.jackson.annotate.JsonProperty 5 | 6 | class ExampleConfiguration extends Configuration { 7 | @JsonProperty 8 | var saying: String = "Hello, world!" 9 | } 10 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/resources/hello-world_fr.ftl: -------------------------------------------------------------------------------- 1 | <#-- @ftlvariable name="" type="com.yammer.dropwizard.views.example.HelloWorldView" --> 2 | 3 | 4 | 5 | Bonjour tout le monde! 6 | 7 | 8 |

Bonjour!

9 | 10 |

Bonjour, ${person.name?html}!

11 | 12 |

Comment ça va?

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/MyView.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views; 2 | 3 | public class MyView extends View { 4 | private final String name; 5 | 6 | public MyView(String name) { 7 | super("/example.ftl"); 8 | this.name = name; 9 | } 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/utilities.less: -------------------------------------------------------------------------------- 1 | // UTILITY CLASSES 2 | // --------------- 3 | 4 | // Quick floats 5 | .pull-right { 6 | float: right; 7 | } 8 | .pull-left { 9 | float: left; 10 | } 11 | 12 | // Toggling content 13 | .hide { 14 | display: none; 15 | } 16 | .show { 17 | display: block; 18 | } 19 | 20 | // Visibility 21 | .invisible { 22 | visibility: hidden; 23 | } 24 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/component-animations.less: -------------------------------------------------------------------------------- 1 | // COMPONENT ANIMATIONS 2 | // -------------------- 3 | 4 | .fade { 5 | .transition(opacity .15s linear); 6 | opacity: 0; 7 | &.in { 8 | opacity: 1; 9 | } 10 | } 11 | 12 | .collapse { 13 | .transition(height .35s ease); 14 | position:relative; 15 | overflow:hidden; 16 | height: 0; 17 | &.in { height: auto; } 18 | } 19 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/patterns.less: -------------------------------------------------------------------------------- 1 | // Patterns.less 2 | // Repeatable UI elements outside the base styles provided from the scaffolding 3 | // ---------------------------------------------------------------------------- 4 | 5 | 6 | // PAGE HEADERS 7 | // ------------ 8 | 9 | footer { 10 | padding-top: @baseLineHeight - 1; 11 | margin-top: @baseLineHeight - 1; 12 | border-top: 1px solid #eee; 13 | } 14 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/logging.yml: -------------------------------------------------------------------------------- 1 | level: INFO 2 | loggers: 3 | com.example.app: DEBUG 4 | console: 5 | enabled: true 6 | threshold: ALL 7 | file: 8 | enabled: false 9 | threshold: ALL 10 | currentLogFilename: ./logs/example.log 11 | archivedLogFilenamePattern: ./logs/example-%d.log.gz 12 | archivedFileCount: 5 13 | syslog: 14 | enabled: false 15 | host: localhost 16 | facility: local0 17 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/close.less: -------------------------------------------------------------------------------- 1 | // CLOSE ICONS 2 | // ----------- 3 | 4 | .close { 5 | float: right; 6 | font-size: 20px; 7 | font-weight: bold; 8 | line-height: @baseLineHeight; 9 | color: @black; 10 | text-shadow: 0 1px 0 rgba(255,255,255,1); 11 | .opacity(20); 12 | &:hover { 13 | color: @black; 14 | text-decoration: none; 15 | .opacity(40); 16 | cursor: pointer; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/wells.less: -------------------------------------------------------------------------------- 1 | // WELLS 2 | // ----- 3 | 4 | .well { 5 | min-height: 20px; 6 | padding: 19px; 7 | margin-bottom: 20px; 8 | background-color: #f5f5f5; 9 | border: 1px solid #eee; 10 | border: 1px solid rgba(0,0,0,.05); 11 | .border-radius(4px); 12 | .box-shadow(inset 0 1px 1px rgba(0,0,0,.05)); 13 | blockquote { 14 | border-color: #ddd; 15 | border-color: rgba(0,0,0,.15); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/hero-unit.less: -------------------------------------------------------------------------------- 1 | // HERO UNIT 2 | // --------- 3 | 4 | .hero-unit { 5 | padding: 60px; 6 | margin-bottom: 30px; 7 | background-color: #f5f5f5; 8 | .border-radius(6px); 9 | h1 { 10 | margin-bottom: 0; 11 | font-size: 60px; 12 | line-height: 1; 13 | letter-spacing: -1px; 14 | } 15 | p { 16 | font-size: 18px; 17 | font-weight: 200; 18 | line-height: @baseLineHeight * 1.5; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/print.less: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap @VERSION for Print 3 | * 4 | * Copyright 2012 Twitter, Inc 5 | * Licensed under the Apache License v2.0 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Designed and built with all the love in the world @twitter by @mdo and @fat. 9 | * Date: @DATE 10 | */ 11 | 12 | 13 | // HIDE UNECESSARY COMPONENTS 14 | // -------------------------- 15 | 16 | .navbar-fixed { 17 | display: none; 18 | } -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/layouts.less: -------------------------------------------------------------------------------- 1 | // 2 | // Layouts 3 | // Fixed-width and fluid (with sidebar) layouts 4 | // -------------------------------------------- 5 | 6 | 7 | // Container (centered, fixed-width layouts) 8 | .container { 9 | .container-fixed(); 10 | } 11 | 12 | // Fluid layouts (left aligned, with sidebar, min- & max-width content) 13 | .container-fluid { 14 | padding-left: @gridGutterWidth; 15 | padding-right: @gridGutterWidth; 16 | .clearfix(); 17 | } -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/HelloWorldResource.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | import javax.ws.rs.*; 4 | import javax.ws.rs.core.MediaType; 5 | 6 | @Path("/hello") 7 | @Produces(MediaType.TEXT_HTML) 8 | public class HelloWorldResource { 9 | @GET 10 | public HelloWorldView show(@QueryParam("name") @DefaultValue("Stranger") String name) { 11 | return new HelloWorldView(new Person(name)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/core/Saying.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.core; 2 | 3 | public class Saying { 4 | private final long id; 5 | private final String content; 6 | 7 | public Saying(long id, String content) { 8 | this.id = id; 9 | this.content = content; 10 | } 11 | 12 | public long getId() { 13 | return id; 14 | } 15 | 16 | public String getContent() { 17 | return content; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/HelloWorldView.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | import com.yammer.dropwizard.views.View; 4 | 5 | public class HelloWorldView extends View { 6 | private final Person person; 7 | 8 | public HelloWorldView(Person person) { 9 | super("/hello-world.ftl"); 10 | this.person = person; 11 | } 12 | 13 | public Person getPerson() { 14 | return person; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/Bundle.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard; 2 | 3 | import com.yammer.dropwizard.config.Environment; 4 | 5 | /** 6 | * A reusable bundle of functionality, used to define blocks of service behavior. 7 | */ 8 | public interface Bundle { 9 | /** 10 | * Initializes the environment. 11 | * 12 | * @param environment the service's {@link Environment} 13 | */ 14 | public void initialize(Environment environment); 15 | } 16 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/resources/banner.txt: -------------------------------------------------------------------------------- 1 | dP 2 | 88 3 | .d8888b. dP. .dP .d8888b. 88d8b.d8b. 88d888b. 88 .d8888b. 4 | 88ooood8 `8bd8' 88' `88 88'`88'`88 88' `88 88 88ooood8 5 | 88. ... .d88b. 88. .88 88 88 88 88. .88 88 88. ... 6 | `88888P' dP' `dP `88888P8 dP dP dP 88Y888P' dP `88888P' 7 | 88 8 | dP 9 | -------------------------------------------------------------------------------- /dropwizard-auth/src/main/java/com/yammer/dropwizard/auth/Auth.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * This annotation is used to inject authenticated principal objects into protected JAX-RS resource 7 | * methods. 8 | * 9 | * @see Authenticator 10 | */ 11 | @Documented 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ ElementType.PARAMETER, ElementType.FIELD }) 14 | public @interface Auth { 15 | boolean required() default true; 16 | } 17 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | web-scale hello world dP for the web 2 | 88 3 | .d8888b. dP. .dP .d8888b. 88d8b.d8b. 88d888b. 88 .d8888b. 4 | 88ooood8 `8bd8' 88' `88 88'`88'`88 88' `88 88 88ooood8 5 | 88. ... .d88b. 88. .88 88 88 88 88. .88 88 88. ... 6 | `88888P' dP' `dP `88888P8 dP dP dP 88Y888P' dP `88888P' 7 | 88 8 | dP 9 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = none 3 | stylesheet = yammerdoc.css 4 | pygments_style = trac 5 | 6 | [options] 7 | tagline = Your tagline here. 8 | gradient_start = #9b4853 9 | gradient_end = #5f0c17 10 | gradient_text = #ffffff 11 | gradient_bg = #7D2A35 12 | gradient_shadow = #fff 13 | landing_logo = logo.png 14 | landing_logo_width = 150px 15 | github_page = https://github.com/yay 16 | mailing_list = http://groups.google.com/yay 17 | maven_site = http://example.com/maven/yay 18 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/labels.less: -------------------------------------------------------------------------------- 1 | // LABELS 2 | // ------ 3 | 4 | .label { 5 | padding: 1px 3px 2px; 6 | font-size: @baseFontSize * .75; 7 | font-weight: bold; 8 | color: @white; 9 | text-transform: uppercase; 10 | background-color: @grayLight; 11 | .border-radius(3px); 12 | } 13 | .label-important { background-color: @errorText; } 14 | .label-warning { background-color: @orange; } 15 | .label-success { background-color: @successText; } 16 | .label-info { background-color: @infoText; } 17 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/resources/com/example/helloworld/db/PeopleDAO.sql.stg: -------------------------------------------------------------------------------- 1 | group PeopleDAO; 2 | 3 | createPeopleTable() ::= << 4 | create table people (id Serial primary key, fullName varchar(255), jobTitle varchar(100)) 5 | >> 6 | 7 | findById() ::= << 8 | select id, fullName, jobTitle from people where id = :id 9 | >> 10 | 11 | create() ::= << 12 | insert into people (fullName, jobTitle) values (:fullName, :jobTitle) 13 | >> 14 | 15 | findAll() ::= << 16 | select id, fullName, jobTitle from people 17 | >> -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/AnotherResource.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | import com.yammer.dropwizard.views.MyOtherView; 4 | 5 | import javax.ws.rs.GET; 6 | import javax.ws.rs.Path; 7 | import javax.ws.rs.Produces; 8 | import javax.ws.rs.core.MediaType; 9 | 10 | @Path("/yay") 11 | @Produces(MediaType.TEXT_HTML) 12 | public class AnotherResource { 13 | @GET 14 | public MyOtherView performYay() { 15 | return new MyOtherView(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/UploadResource.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import javax.ws.rs.core.MediaType 4 | import javax.ws.rs.{POST, Consumes, Path} 5 | import com.yammer.dropwizard.Logging 6 | import com.yammer.metrics.annotation.Timed 7 | 8 | @Path("/upload") 9 | @Consumes(Array(MediaType.WILDCARD)) 10 | class UploadResource extends Logging { 11 | @POST 12 | @Timed 13 | def upload(body: String) { 14 | log.info("New upload: %s", body) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/breadcrumbs.less: -------------------------------------------------------------------------------- 1 | // BREADCRUMBS 2 | // ----------- 3 | 4 | .breadcrumb { 5 | padding: 7px 14px; 6 | margin: 0 0 @baseLineHeight; 7 | #gradient > .vertical(@white, #f5f5f5); 8 | border: 1px solid #ddd; 9 | .border-radius(3px); 10 | .box-shadow(inset 0 1px 0 @white); 11 | li { 12 | display: inline; 13 | text-shadow: 0 1px 0 @white; 14 | } 15 | .divider { 16 | padding: 0 5px; 17 | color: @grayLight; 18 | } 19 | .active a { 20 | color: @grayDark; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/source/manual/index.rst: -------------------------------------------------------------------------------- 1 | .. _manual-index: 2 | 3 | ########### 4 | User Manual 5 | ########### 6 | 7 | .. rubric:: This goal of this document is to provide you with all the information required to build, 8 | organize, test, deploy, and maintain Dropwizard-based services. If you're new to 9 | Dropwizard, you should read the :ref:`getting-started` guide first. 10 | 11 | .. toctree:: 12 | :maxdepth: 1 13 | 14 | core 15 | client 16 | db 17 | auth 18 | views 19 | scala 20 | testing 21 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/util/tests/JarLocationTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.util.tests; 2 | 3 | import com.yammer.dropwizard.util.JarLocation; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.Matchers.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class JarLocationTest { 10 | @Test 11 | public void isHumanReadable() throws Exception { 12 | assertThat(new JarLocation(JarLocationTest.class).toString(), 13 | is("project.jar")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/tests/ViewTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.tests; 2 | 3 | import com.yammer.dropwizard.views.MyView; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.Matchers.*; 7 | import static org.junit.Assert.*; 8 | 9 | public class ViewTest { 10 | private final MyView view = new MyView("Wonk"); 11 | 12 | @Test 13 | public void hasATemplate() throws Exception { 14 | assertThat(view.getTemplateName(), 15 | is("/example.ftl")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dropwizard-testing/src/test/java/com/yammer/dropwizard/testing/tests/FixtureHelpersTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.testing.tests; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.yammer.dropwizard.testing.FixtureHelpers.fixture; 6 | import static org.hamcrest.Matchers.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class FixtureHelpersTest { 10 | @Test 11 | public void readsTheFileAsAString() throws Exception { 12 | assertThat(fixture("fixtures/fixture.txt"), 13 | is("YAY FOR ME")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/db/DatabaseHealthCheck.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.db; 2 | 3 | import com.yammer.metrics.core.HealthCheck; 4 | 5 | public class DatabaseHealthCheck extends HealthCheck { 6 | private final Database database; 7 | 8 | public DatabaseHealthCheck(Database database, String name) { 9 | super(name + "-db"); 10 | this.database = database; 11 | } 12 | 13 | @Override 14 | protected Result check() throws Exception { 15 | database.ping(); 16 | return Result.healthy(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/main/scala/com/yammer/dropwizard/ScalaService.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard 2 | 3 | import config.Configuration 4 | import bundles.ScalaBundle 5 | import com.codahale.jerkson.ScalaModule 6 | 7 | abstract class ScalaService[T <: Configuration](name: String) extends AbstractService[T](name) { 8 | addBundle(new ScalaBundle(this)) 9 | addJacksonModule(new ScalaModule(Thread.currentThread().getContextClassLoader)) 10 | override final def subclassServiceInsteadOfThis() {} 11 | 12 | final def main(args: Array[String]) { 13 | run(args) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dropwizard-db/src/test/java/com/yammer/dropwizard/db/tests/PersonDAO.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.db.tests; 2 | 3 | import com.google.common.base.Optional; 4 | import com.google.common.collect.ImmutableList; 5 | import org.skife.jdbi.v2.sqlobject.Bind; 6 | import org.skife.jdbi.v2.sqlobject.SqlQuery; 7 | 8 | public interface PersonDAO { 9 | @SqlQuery("SELECT name FROM people WHERE name = :name") 10 | public String findByName(@Bind("name") Optional name); 11 | 12 | @SqlQuery("SELECT name FROM people ORDER BY name ASC") 13 | public ImmutableList findAllNames(); 14 | } 15 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/core/Template.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.core; 2 | 3 | import com.google.common.base.Optional; 4 | 5 | import static java.lang.String.format; 6 | 7 | public class Template { 8 | private final String content; 9 | private final String defaultName; 10 | 11 | public Template(String content, String defaultName) { 12 | this.content = content; 13 | this.defaultName = defaultName; 14 | } 15 | 16 | public String render(Optional name) { 17 | return format(content, name.or(defaultName)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/caching/CacheControlledResourceMethodDispatchAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey.caching; 2 | 3 | import com.sun.jersey.spi.container.ResourceMethodDispatchAdapter; 4 | import com.sun.jersey.spi.container.ResourceMethodDispatchProvider; 5 | 6 | public class CacheControlledResourceMethodDispatchAdapter implements ResourceMethodDispatchAdapter { 7 | @Override 8 | public ResourceMethodDispatchProvider adapt(ResourceMethodDispatchProvider provider) { 9 | return new CacheControlledResourceMethodDispatchProvider(provider); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/pager.less: -------------------------------------------------------------------------------- 1 | // PAGER 2 | // ----- 3 | 4 | .pager { 5 | margin-left: 0; 6 | margin-bottom: @baseLineHeight; 7 | list-style: none; 8 | text-align: center; 9 | .clearfix(); 10 | } 11 | .pager li { 12 | display: inline; 13 | } 14 | .pager a { 15 | display: inline-block; 16 | padding: 5px 14px; 17 | background-color: #fff; 18 | border: 1px solid #ddd; 19 | .border-radius(15px); 20 | } 21 | .pager a:hover { 22 | text-decoration: none; 23 | background-color: #f5f5f5; 24 | } 25 | .pager .next a { 26 | float: right; 27 | } 28 | .pager .previous a { 29 | float: left; 30 | } 31 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/resources/ProtectedResource.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.resources; 2 | 3 | import com.example.helloworld.core.User; 4 | import com.yammer.dropwizard.auth.Auth; 5 | 6 | import javax.ws.rs.GET; 7 | import javax.ws.rs.Path; 8 | import javax.ws.rs.Produces; 9 | import javax.ws.rs.core.MediaType; 10 | 11 | @Path("/protected") 12 | @Produces(MediaType.TEXT_PLAIN) 13 | public class ProtectedResource { 14 | @GET 15 | public String showSecret(@Auth User user) { 16 | return String.format("Hey there, %s. You know the secret!", user.getName()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/accordion.less: -------------------------------------------------------------------------------- 1 | // ACCORDION 2 | // --------- 3 | 4 | 5 | // Parent container 6 | .accordion { 7 | margin-bottom: @baseLineHeight; 8 | } 9 | 10 | // Group == heading + body 11 | .accordion-group { 12 | margin-bottom: 2px; 13 | border: 1px solid #e5e5e5; 14 | .border-radius(4px); 15 | } 16 | .accordion-heading { 17 | border-bottom: 0; 18 | } 19 | .accordion-heading .accordion-toggle { 20 | display: block; 21 | padding: 8px 15px; 22 | } 23 | 24 | // Inner needs the styles because you can't animate properly with any styles on the element 25 | .accordion-inner { 26 | padding: 9px 15px; 27 | border-top: 1px solid #e5e5e5; 28 | } 29 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/HelloWorldResource.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import javax.ws.rs._ 4 | import core.Response.Status 5 | import core.{Response, MediaType} 6 | import com.yammer.metrics.annotation.Timed 7 | 8 | @Path("/hello-world") 9 | @Produces(Array(MediaType.APPLICATION_JSON)) 10 | class HelloWorldResource(saying: String) { 11 | @GET 12 | @Timed 13 | def sayHello(@QueryParam("opt") opt: Option[String]) = Seq(saying) 14 | 15 | @POST 16 | @Timed 17 | def intentionalError = Response.status(Status.BAD_REQUEST).build() 18 | 19 | @PUT 20 | @Timed 21 | def unintentionalError = None.get 22 | } 23 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/params/LongParam.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey.params; 2 | 3 | /** 4 | * A parameter encapsulating long values. All non-decimal values will return a {@code 400 Bad 5 | * Request} response. 6 | */ 7 | public class LongParam extends AbstractParam { 8 | public LongParam(String input) { 9 | super(input); 10 | } 11 | 12 | @Override 13 | protected String errorMessage(String input, Exception e) { 14 | return '"' + input + "\" is not a number."; 15 | } 16 | 17 | @Override 18 | protected Long parse(String input) { 19 | return Long.valueOf(input); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/validation/MethodValidator.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.validation; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | /** 7 | * A validator for {@link ValidationMethod}-annotated methods. 8 | */ 9 | public class MethodValidator implements ConstraintValidator { 10 | @Override 11 | public void initialize(ValidationMethod constraintAnnotation) { 12 | 13 | } 14 | 15 | @Override 16 | public boolean isValid(Boolean value, ConstraintValidatorContext context) { 17 | return (value == null) || value; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/params/IntParam.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey.params; 2 | 3 | /** 4 | * A parameter encapsulating integer values. All non-decimal values will return a 5 | * {@code 400 Bad Request} response. 6 | */ 7 | public class IntParam extends AbstractParam { 8 | public IntParam(String input) { 9 | super(input); 10 | } 11 | 12 | @Override 13 | protected String errorMessage(String input, Exception e) { 14 | return '"' + input + "\" is not a number."; 15 | } 16 | 17 | @Override 18 | protected Integer parse(String input) { 19 | return Integer.valueOf(input); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/ConfiguredBundle.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard; 2 | 3 | import com.yammer.dropwizard.config.Environment; 4 | 5 | /** 6 | * A reusable bundle of functionality, used to define blocks of service behavior that are 7 | * conditional on configuration parameters. 8 | * 9 | * @param the required configuration interface 10 | */ 11 | public interface ConfiguredBundle { 12 | /** 13 | * Initializes the environment. 14 | * 15 | * @param configuration the configuration object 16 | * @param environment the service's {@link Environment} 17 | */ 18 | public void initialize(T configuration, Environment environment); 19 | } 20 | -------------------------------------------------------------------------------- /dropwizard-auth/src/test/java/com/yammer/dropwizard/auth/User.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth; 2 | 3 | public class User { 4 | private final String token; 5 | 6 | public User(String token) { 7 | this.token = token; 8 | } 9 | 10 | public String getToken() { 11 | return token; 12 | } 13 | 14 | @Override 15 | public boolean equals(Object o) { 16 | if (this == o) { return true; } 17 | if ((o == null) || (getClass() != o.getClass())) { return false; } 18 | final User user = (User) o; 19 | return token.equals(user.token); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return token.hashCode(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/scaffolding.less: -------------------------------------------------------------------------------- 1 | // Scaffolding 2 | // Basic and global styles for generating a grid system, structural layout, and page templates 3 | // ------------------------------------------------------------------------------------------- 4 | 5 | 6 | // STRUCTURAL LAYOUT 7 | // ----------------- 8 | 9 | body { 10 | margin: 0; 11 | font-family: @baseFontFamily; 12 | font-size: @baseFontSize; 13 | line-height: @baseLineHeight; 14 | color: @textColor; 15 | background-color: @white; 16 | } 17 | 18 | 19 | // LINKS 20 | // ----- 21 | 22 | a { 23 | color: @linkColor; 24 | text-decoration: none; 25 | } 26 | a:hover { 27 | color: @linkColorHover; 28 | text-decoration: underline; 29 | } 30 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/json/JsonSnakeCase.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.json; 2 | 3 | import org.codehaus.jackson.annotate.JacksonAnnotation; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Marker annotation which indicates that the annotated case class should be 12 | * serialized and deserialized using {@code snake_case} JSON field names instead 13 | * of {@code camelCase} field names. 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @JacksonAnnotation 18 | public @interface JsonSnakeCase { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/logging/SyslogFormatter.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.logging; 2 | 3 | import ch.qos.logback.classic.LoggerContext; 4 | import ch.qos.logback.classic.PatternLayout; 5 | 6 | import java.util.TimeZone; 7 | 8 | public class SyslogFormatter extends PatternLayout { 9 | private final String name; 10 | 11 | public SyslogFormatter(LoggerContext context, TimeZone timeZone, String name) { 12 | super(); 13 | this.name = name; 14 | getDefaultConverterMap().put("ex", PrefixedThrowableProxyConverter.class.getName()); 15 | setPattern(name + ": %d{ISO8601," + timeZone.getID() + "}] %-5p [%t] %c{2} %X - %m\n"); 16 | setContext(context); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/health/TemplateHealthCheck.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.health; 2 | 3 | import com.example.helloworld.core.Template; 4 | import com.google.common.base.Optional; 5 | import com.yammer.metrics.core.HealthCheck; 6 | 7 | public class TemplateHealthCheck extends HealthCheck { 8 | private final Template template; 9 | 10 | public TemplateHealthCheck(Template template) { 11 | super("template"); 12 | this.template = template; 13 | } 14 | 15 | @Override 16 | protected Result check() throws Exception { 17 | template.render(Optional.of("woo")); 18 | template.render(Optional.absent()); 19 | return Result.healthy(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/db/args/OptionalArgumentFactory.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.db.args; 2 | 3 | import com.google.common.base.Optional; 4 | import org.skife.jdbi.v2.StatementContext; 5 | import org.skife.jdbi.v2.tweak.Argument; 6 | import org.skife.jdbi.v2.tweak.ArgumentFactory; 7 | 8 | public class OptionalArgumentFactory implements ArgumentFactory> { 9 | @Override 10 | public boolean accepts(Class expectedType, Object value, StatementContext ctx) { 11 | return value instanceof Optional; 12 | } 13 | 14 | @Override 15 | public Argument build(Class expectedType, Optional value, StatementContext ctx) { 16 | return new OptionalArgument(value); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/bundles/DBIExceptionsBundle.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.bundles; 2 | 3 | import com.yammer.dropwizard.Bundle; 4 | import com.yammer.dropwizard.config.Environment; 5 | import com.yammer.dropwizard.jersey.LoggingDBIExceptionMapper; 6 | import com.yammer.dropwizard.jersey.LoggingSQLExceptionMapper; 7 | 8 | /** 9 | * A bundle for logging SQLExceptions and DBIExceptions so that their actual causes aren't overlooked. 10 | */ 11 | public class DBIExceptionsBundle implements Bundle { 12 | @Override 13 | public void initialize(Environment environment) { 14 | environment.addProvider(new LoggingSQLExceptionMapper()); 15 | environment.addProvider(new LoggingDBIExceptionMapper()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/core/Person.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.core; 2 | 3 | public class Person { 4 | 5 | private long id; 6 | private String fullName; 7 | private String jobTitle; 8 | 9 | public long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(long id) { 14 | this.id = id; 15 | } 16 | 17 | public String getFullName() { 18 | return fullName; 19 | } 20 | 21 | public void setFullName(String fullName) { 22 | this.fullName = fullName; 23 | } 24 | 25 | public String getJobTitle() { 26 | return jobTitle; 27 | } 28 | 29 | public void setJobTitle(String jobTitle) { 30 | this.jobTitle = jobTitle; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/lifecycle/Managed.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.lifecycle; 2 | 3 | /** 4 | * An interface for objects which need to be started and stopped as the service is started or 5 | * stopped. 6 | */ 7 | public interface Managed { 8 | /** 9 | * Starts the object. Called before the service becomes available. 10 | * 11 | * @throws Exception if something goes wrong; this will halt the service startup. 12 | */ 13 | public void start() throws Exception; 14 | 15 | /** 16 | * Stops the object. Called after the service is no longer accepting requests. 17 | * 18 | * @throws Exception if something goes wrong. 19 | */ 20 | public void stop() throws Exception; 21 | } 22 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/StartableObject.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import com.yammer.dropwizard.Logging 4 | import com.yammer.dropwizard.lifecycle.Managed 5 | 6 | class StartableObject(template: String) extends Managed with Logging { 7 | override def start() { 8 | log.info("Starting: %s", template) 9 | } 10 | 11 | /** 12 | * N.B.: This actually gets called, but if you're running it through SBT 13 | * and you hit ^C you won't see the final set of log statements indicating 14 | * that it actually does the full shutdown. It does. kill -SIGINT the JVM 15 | * instead of hitting ^C and you'll see the log statements. 16 | */ 17 | override def stop() { 18 | log.info("Stopping") 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/tests/ViewBundleTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.tests; 2 | 3 | import com.yammer.dropwizard.config.Environment; 4 | import com.yammer.dropwizard.views.ViewBundle; 5 | import com.yammer.dropwizard.views.ViewMessageBodyWriter; 6 | import org.junit.Test; 7 | 8 | import static org.mockito.Mockito.mock; 9 | import static org.mockito.Mockito.verify; 10 | 11 | public class ViewBundleTest { 12 | private final Environment environment = mock(Environment.class); 13 | 14 | @Test 15 | public void addsTheViewMessageBodyWriterToTheEnvironment() throws Exception { 16 | new ViewBundle().initialize(environment); 17 | 18 | verify(environment).addProvider(ViewMessageBodyWriter.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/logging/LogFormatter.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.logging; 2 | 3 | // TODO: 10/12/11 -- test LogFormatter 4 | // TODO: 10/12/11 -- document LogFormatter 5 | 6 | import ch.qos.logback.classic.LoggerContext; 7 | import ch.qos.logback.classic.PatternLayout; 8 | 9 | import java.util.TimeZone; 10 | 11 | public class LogFormatter extends PatternLayout { 12 | public LogFormatter(LoggerContext context, TimeZone timeZone) { 13 | super(); 14 | setOutputPatternAsHeader(false); 15 | getDefaultConverterMap().put("ex", PrefixedThrowableProxyConverter.class.getName()); 16 | setPattern("%-5p [%d{ISO8601," + timeZone.getID() + "}] %c: %m\n%ex"); 17 | setContext(context); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/jersey/LoggingSQLExceptionMapper.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey; 2 | 3 | import com.yammer.dropwizard.logging.Log; 4 | 5 | import javax.ws.rs.ext.Provider; 6 | import java.sql.SQLException; 7 | 8 | /** 9 | * Iterates through SQLExceptions to log all causes 10 | */ 11 | @Provider 12 | public class LoggingSQLExceptionMapper extends LoggingExceptionMapper { 13 | private static final Log LOG = Log.forClass(LoggingSQLExceptionMapper.class); 14 | 15 | @Override 16 | protected void logException(long id, SQLException exception) { 17 | final String message = formatLogMessage(id, exception); 18 | for (Throwable throwable : exception) { 19 | LOG.error(throwable, message); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/auth/ExampleAuthenticator.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.auth; 2 | 3 | import com.example.helloworld.core.User; 4 | import com.google.common.base.Optional; 5 | import com.yammer.dropwizard.auth.AuthenticationException; 6 | import com.yammer.dropwizard.auth.Authenticator; 7 | import com.yammer.dropwizard.auth.basic.BasicCredentials; 8 | 9 | public class ExampleAuthenticator implements Authenticator { 10 | @Override 11 | public Optional authenticate(BasicCredentials credentials) throws AuthenticationException { 12 | if ("secret".equals(credentials.getPassword())) { 13 | return Optional.of(new User(credentials.getUsername())); 14 | } 15 | return Optional.absent(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/ExampleService.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import com.yammer.dropwizard.config.Environment 4 | import com.yammer.dropwizard.{Logging, ScalaService} 5 | 6 | object ExampleService extends ScalaService[ExampleConfiguration]("example") with Logging { 7 | addCommand(new SayCommand) 8 | addCommand(new SplodyCommand) 9 | 10 | def initialize(configuration: ExampleConfiguration, environment: Environment) { 11 | environment.addResource(new HelloWorldResource(configuration.saying)) 12 | environment.addResource(new UploadResource) 13 | environment.addResource(new SplodyResource) 14 | environment.addHealthCheck(new DumbHealthCheck) 15 | environment.manage(new StartableObject(configuration.saying)) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dropwizard-testing/src/test/java/com/yammer/dropwizard/testing/tests/service/PersonResource.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.testing.tests.service; 2 | 3 | import com.yammer.dropwizard.testing.tests.Person; 4 | import com.yammer.metrics.annotation.Timed; 5 | 6 | import javax.ws.rs.GET; 7 | import javax.ws.rs.Path; 8 | import javax.ws.rs.PathParam; 9 | import javax.ws.rs.Produces; 10 | import javax.ws.rs.core.MediaType; 11 | 12 | @Path("/person/{name}") 13 | @Produces(MediaType.APPLICATION_JSON) 14 | public class PersonResource { 15 | private final PeopleStore store; 16 | 17 | public PersonResource(PeopleStore store) { 18 | this.store = store; 19 | } 20 | 21 | @GET 22 | @Timed 23 | public Person getPerson(@PathParam("name") String name) { 24 | return store.fetchPerson(name); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/thumbnails.less: -------------------------------------------------------------------------------- 1 | // THUMBNAILS 2 | // ---------- 3 | 4 | .thumbnails { 5 | margin-left: -20px; 6 | list-style: none; 7 | .clearfix(); 8 | } 9 | .thumbnails > li { 10 | float: left; 11 | margin: 0 0 @baseLineHeight 20px; 12 | } 13 | .thumbnail { 14 | display: block; 15 | padding: 4px; 16 | line-height: 1; 17 | border: 1px solid #ddd; 18 | .border-radius(4px); 19 | .box-shadow(0 1px 1px rgba(0,0,0,.075)); 20 | } 21 | // Add a hover state for linked versions only 22 | a.thumbnail:hover { 23 | border-color: @linkColor; 24 | .box-shadow(0 1px 4px rgba(0,105,214,.25)); 25 | } 26 | // Images and captions 27 | .thumbnail > img { 28 | display: block; 29 | max-width: 100%; 30 | margin-left: auto; 31 | margin-right: auto; 32 | } 33 | .thumbnail .caption { 34 | padding: 9px; 35 | } 36 | -------------------------------------------------------------------------------- /docs/source/about/faq.rst: -------------------------------------------------------------------------------- 1 | .. title:: FAQ 2 | 3 | .. _faq: 4 | 5 | ########################## 6 | Frequently Asked Questions 7 | ########################## 8 | 9 | What's a Dropwizard? 10 | A character in a `K.C. Green web comic`__. 11 | 12 | .. __: http://gunshowcomic.com/316 13 | 14 | How is Dropwizard licensed? 15 | It's licensed under the `Apache License v2`__. 16 | 17 | .. __: http://www.apache.org/licenses/LICENSE-2.0.html 18 | 19 | How can I commit to Dropwizard? 20 | Go to the `GitHub project`__, fork it, and submit a pull request. We prefer small, single-purpose 21 | pull requests over large, multi-purpose ones. We reserve the right to turn down any proposed 22 | changes, but in general we're delighted when people want to make our projects better! 23 | 24 | .. __: https://github.com/codahale/dropwizard 25 | 26 | 27 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/tasks/tests/TaskTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.tasks.tests; 2 | 3 | import com.google.common.collect.ImmutableMultimap; 4 | import com.yammer.dropwizard.tasks.Task; 5 | import org.junit.Test; 6 | 7 | import java.io.PrintWriter; 8 | 9 | import static org.hamcrest.Matchers.is; 10 | import static org.junit.Assert.assertThat; 11 | 12 | public class TaskTest { 13 | private final Task task = new Task("test") { 14 | @Override 15 | public void execute(ImmutableMultimap parameters, 16 | PrintWriter output) throws Exception { 17 | 18 | } 19 | }; 20 | 21 | @Test 22 | public void hasAName() throws Exception { 23 | assertThat(task.getName(), 24 | is("test")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/SplodyResource.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import javax.ws.rs.core.StreamingOutput 4 | import javax.ws.rs.{POST, GET, Path} 5 | import java.io.OutputStream 6 | import com.yammer.metrics.annotation.Timed 7 | 8 | @Path("/splode") 9 | class SplodyResource { 10 | private val dumb: String = null 11 | 12 | /** 13 | * An error which happens inside a Jersey resource. 14 | */ 15 | @GET 16 | @Timed 17 | def splode() = dumb.toString 18 | 19 | /** 20 | * An error which happens outside of a Jersey resource. 21 | */ 22 | @POST 23 | @Timed 24 | def sneakySplode(): StreamingOutput = new StreamingOutput { 25 | def write(output: OutputStream) { 26 | throw new RuntimeException("OH SWEET GOD WHAT") 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/util/Servlets.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.util; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * Utility functions for dealing with servlets. 7 | */ 8 | public class Servlets { 9 | private Servlets() { /* singleton */ } 10 | 11 | /** 12 | * Returns the full URL of the given request. 13 | * 14 | * @param request an HTTP servlet request 15 | * @return the full URL, including the query string 16 | */ 17 | public static String getFullUrl(HttpServletRequest request) { 18 | final StringBuilder url = new StringBuilder(100).append(request.getRequestURI()); 19 | if (request.getQueryString() != null) { 20 | url.append('?').append(request.getQueryString()); 21 | } 22 | return url.toString(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests/RequestLogConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config.tests; 2 | 3 | import com.google.common.io.Resources; 4 | import com.yammer.dropwizard.config.ConfigurationFactory; 5 | import com.yammer.dropwizard.config.RequestLogConfiguration; 6 | import com.yammer.dropwizard.validation.Validator; 7 | import org.junit.Before; 8 | 9 | import java.io.File; 10 | 11 | public class RequestLogConfigurationTest { 12 | private RequestLogConfiguration requestLog; 13 | 14 | @Before 15 | public void setUp() throws Exception { 16 | this.requestLog = ConfigurationFactory.forClass(RequestLogConfiguration.class, 17 | new Validator()).build(new File(Resources.getResource("yaml/requestLog.yml").getFile())); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/jetty/tests/JettyManagedTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jetty.tests; 2 | 3 | import com.yammer.dropwizard.jetty.JettyManaged; 4 | import com.yammer.dropwizard.lifecycle.Managed; 5 | import org.junit.Test; 6 | import org.mockito.InOrder; 7 | 8 | import static org.mockito.Mockito.inOrder; 9 | import static org.mockito.Mockito.mock; 10 | 11 | public class JettyManagedTest { 12 | private final Managed managed = mock(Managed.class); 13 | private final JettyManaged jettyManaged = new JettyManaged(managed); 14 | 15 | @Test 16 | public void startsAndStops() throws Exception { 17 | jettyManaged.start(); 18 | jettyManaged.stop(); 19 | 20 | final InOrder inOrder = inOrder(managed); 21 | inOrder.verify(managed).start(); 22 | inOrder.verify(managed).stop(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dropwizard-auth/src/main/java/com/yammer/dropwizard/auth/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth; 2 | 3 | /** 4 | * An exception thrown to indicate that an {@link Authenticator} is unable to check the 5 | * validity of the given credentials. 6 | * 7 | *

DO NOT USE THIS TO INDICATE THAT THE CREDENTIALS ARE INVALID.

8 | */ 9 | @SuppressWarnings("UnusedDeclaration") 10 | public class AuthenticationException extends Exception { 11 | private static final long serialVersionUID = -5053567474138953905L; 12 | 13 | public AuthenticationException(String message) { 14 | super(message); 15 | } 16 | 17 | public AuthenticationException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public AuthenticationException(Throwable cause) { 22 | super(cause); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/config/SslConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config; 2 | 3 | import com.google.common.base.Optional; 4 | import org.codehaus.jackson.annotate.JsonProperty; 5 | 6 | public class SslConfiguration { 7 | @JsonProperty 8 | protected String keyStorePath = null; 9 | 10 | @JsonProperty 11 | protected String keyStorePassword = null; 12 | 13 | @JsonProperty 14 | protected String keyManagerPassword = null; 15 | 16 | public Optional getKeyStorePath() { 17 | return Optional.fromNullable(keyStorePath); 18 | } 19 | 20 | public Optional getKeyStorePassword() { 21 | return Optional.fromNullable(keyStorePassword); 22 | } 23 | 24 | public Optional getKeyManagerPassword() { 25 | return Optional.fromNullable(keyManagerPassword); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/resources/PersonResource.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.resources; 2 | 3 | import com.example.helloworld.core.Person; 4 | import com.example.helloworld.db.PeopleDAO; 5 | import com.yammer.dropwizard.jersey.params.LongParam; 6 | 7 | import javax.ws.rs.GET; 8 | import javax.ws.rs.Path; 9 | import javax.ws.rs.PathParam; 10 | import javax.ws.rs.Produces; 11 | import javax.ws.rs.core.MediaType; 12 | 13 | @Path("/person/{personId}") 14 | @Produces(MediaType.APPLICATION_JSON) 15 | public class PersonResource { 16 | 17 | private final PeopleDAO peopleDAO; 18 | 19 | public PersonResource(PeopleDAO peopleDAO) { 20 | this.peopleDAO = peopleDAO; 21 | } 22 | 23 | @GET 24 | public Person getPerson(@PathParam("personId") LongParam personId) { 25 | return peopleDAO.findById(personId.get()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/main/java/com/yammer/dropwizard/bundles/ScalaBundle.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.bundles; 2 | 3 | import com.codahale.jersey.inject.ScalaCollectionsQueryParamInjectableProvider; 4 | import com.yammer.dropwizard.Bundle; 5 | import com.yammer.dropwizard.ScalaService; 6 | import com.yammer.dropwizard.config.Environment; 7 | import com.yammer.dropwizard.jersey.JacksonMessageBodyProvider; 8 | 9 | public class ScalaBundle implements Bundle { 10 | private final ScalaService service; 11 | 12 | public ScalaBundle(ScalaService service) { 13 | this.service = service; 14 | } 15 | 16 | @Override 17 | public void initialize(Environment environment) { 18 | environment.addProvider(new JacksonMessageBodyProvider(service.getJson())); 19 | environment.addProvider(new ScalaCollectionsQueryParamInjectableProvider()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests/ConfigurationExceptionTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config.tests; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.yammer.dropwizard.config.ConfigurationException; 5 | import org.junit.Test; 6 | 7 | import java.io.File; 8 | 9 | import static org.hamcrest.Matchers.is; 10 | import static org.junit.Assert.assertThat; 11 | 12 | public class ConfigurationExceptionTest { 13 | @Test 14 | public void formatsTheViolationsIntoAHumanReadableMessage() throws Exception { 15 | final File file = new File("config.yml"); 16 | final ConfigurationException e = new ConfigurationException(file, ImmutableList.of("woo may not be null")); 17 | 18 | assertThat(e.getMessage(), 19 | is("config.yml has the following errors:\n" + 20 | " * woo may not be null\n")); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/DropwizardResourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey; 2 | 3 | import com.sun.jersey.api.core.DefaultResourceConfig; 4 | import com.sun.jersey.api.core.ResourceConfig; 5 | import com.yammer.dropwizard.jersey.caching.CacheControlledResourceMethodDispatchAdapter; 6 | import com.yammer.metrics.jersey.InstrumentedResourceMethodDispatchAdapter; 7 | 8 | public class DropwizardResourceConfig extends DefaultResourceConfig { 9 | public DropwizardResourceConfig() { 10 | super(); 11 | getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE); 12 | getSingletons().add(new LoggingExceptionMapper() { }); // create a subclass to pin it to Throwable 13 | getClasses().add(InstrumentedResourceMethodDispatchAdapter.class); 14 | getClasses().add(CacheControlledResourceMethodDispatchAdapter.class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/lifecycle/ExecutorServiceManager.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.lifecycle; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | public class ExecutorServiceManager implements Managed { 7 | private final ExecutorService executor; 8 | private final long shutdownPeriod; 9 | private final TimeUnit unit; 10 | 11 | public ExecutorServiceManager(ExecutorService executor, long shutdownPeriod, TimeUnit unit) { 12 | this.executor = executor; 13 | this.shutdownPeriod = shutdownPeriod; 14 | this.unit = unit; 15 | } 16 | 17 | @Override 18 | public void start() throws Exception { 19 | // OK BOSS 20 | } 21 | 22 | @Override 23 | public void stop() throws Exception { 24 | executor.shutdown(); 25 | executor.awaitTermination(shutdownPeriod, unit); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/SayCommand.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import com.yammer.dropwizard.cli.ConfiguredCommand 4 | import org.apache.commons.cli.{Options, CommandLine} 5 | import com.yammer.dropwizard.Logging 6 | import com.yammer.dropwizard.AbstractService 7 | 8 | class SayCommand extends ConfiguredCommand[ExampleConfiguration]("say", "Prints out the saying to console") with Logging { 9 | override def getOptions = { 10 | val options = new Options 11 | options.addOption("v", "verbose", false, "yell it a lot") 12 | options 13 | } 14 | 15 | protected def run(service: AbstractService[ExampleConfiguration], 16 | configuration: ExampleConfiguration, 17 | params: CommandLine) { 18 | for (i <- 1 to (if (params.hasOption("verbose")) 10 else 1)) { 19 | log.warn(configuration.saying) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/db/args/OptionalArgument.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.db.args; 2 | 3 | import com.google.common.base.Optional; 4 | import org.skife.jdbi.v2.StatementContext; 5 | import org.skife.jdbi.v2.tweak.Argument; 6 | 7 | import java.sql.PreparedStatement; 8 | import java.sql.SQLException; 9 | import java.sql.Types; 10 | 11 | public class OptionalArgument implements Argument { 12 | private final Optional value; 13 | 14 | public OptionalArgument(Optional value) { 15 | this.value = value; 16 | } 17 | 18 | @Override 19 | public void apply(int position, 20 | PreparedStatement statement, 21 | StatementContext ctx) throws SQLException { 22 | if (value.isPresent()) { 23 | statement.setObject(position, value.get()); 24 | } else { 25 | statement.setNull(position, Types.OTHER); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dropwizard-views/src/test/java/com/yammer/dropwizard/views/example/TemplateService.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views.example; 2 | 3 | import com.yammer.dropwizard.Service; 4 | import com.yammer.dropwizard.config.Configuration; 5 | import com.yammer.dropwizard.config.Environment; 6 | import com.yammer.dropwizard.views.ViewBundle; 7 | 8 | public class TemplateService extends Service { 9 | public static void main(String[] args) throws Exception { 10 | new TemplateService().run(args); 11 | } 12 | 13 | private TemplateService() { 14 | super("template"); 15 | addBundle(new ViewBundle()); 16 | } 17 | 18 | @Override 19 | protected void initialize(Configuration configuration, Environment environment) { 20 | environment.addResource(new HelloWorldResource()); 21 | environment.addResource(new BadResource()); 22 | environment.addResource(new AnotherResource()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/util/JarLocation.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.util; 2 | 3 | import java.io.File; 4 | import java.net.URL; 5 | 6 | /** 7 | * A class which encapsulates the location on the local filesystem of the JAR in which the current 8 | * code is executing. 9 | */ 10 | public class JarLocation { 11 | private final Class klass; 12 | 13 | public JarLocation(Class klass) { 14 | this.klass = klass; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | final URL location = klass.getProtectionDomain().getCodeSource().getLocation(); 20 | try { 21 | final String jar = new File(location.getFile()).getName(); 22 | if (jar.endsWith(".jar")) { 23 | return jar; 24 | } 25 | return "project.jar"; 26 | } catch (Exception ignored) { 27 | return "project.jar"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/caching/CacheControlledRequestDispatcher.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey.caching; 2 | 3 | import com.sun.jersey.api.core.HttpContext; 4 | import com.sun.jersey.spi.dispatch.RequestDispatcher; 5 | 6 | import javax.ws.rs.core.CacheControl; 7 | import javax.ws.rs.core.HttpHeaders; 8 | 9 | class CacheControlledRequestDispatcher implements RequestDispatcher { 10 | private final RequestDispatcher dispatcher; 11 | private final CacheControl cacheControl; 12 | 13 | CacheControlledRequestDispatcher(RequestDispatcher dispatcher, CacheControl cacheControl) { 14 | this.dispatcher = dispatcher; 15 | this.cacheControl = cacheControl; 16 | } 17 | 18 | @Override 19 | public void dispatch(Object resource, HttpContext context) { 20 | dispatcher.dispatch(resource, context); 21 | context.getResponse().getHttpHeaders().add(HttpHeaders.CACHE_CONTROL, cacheControl); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/tooltip.less: -------------------------------------------------------------------------------- 1 | // TOOLTIP 2 | // ------= 3 | 4 | .tooltip { 5 | position: absolute; 6 | z-index: @zindexTooltip; 7 | display: block; 8 | visibility: visible; 9 | padding: 5px; 10 | font-size: 11px; 11 | .opacity(0); 12 | &.in { .opacity(80); } 13 | &.top { margin-top: -2px; } 14 | &.right { margin-left: 2px; } 15 | &.bottom { margin-top: 2px; } 16 | &.left { margin-left: -2px; } 17 | &.top .tooltip-arrow { #popoverArrow > .top(); } 18 | &.left .tooltip-arrow { #popoverArrow > .left(); } 19 | &.bottom .tooltip-arrow { #popoverArrow > .bottom(); } 20 | &.right .tooltip-arrow { #popoverArrow > .right(); } 21 | } 22 | .tooltip-inner { 23 | max-width: 200px; 24 | padding: 3px 8px; 25 | color: @white; 26 | text-align: center; 27 | text-decoration: none; 28 | background-color: @black; 29 | .border-radius(4px); 30 | } 31 | .tooltip-arrow { 32 | position: absolute; 33 | width: 0; 34 | height: 0; 35 | } 36 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/resources/PeopleResource.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.resources; 2 | 3 | import com.example.helloworld.core.Person; 4 | import com.example.helloworld.db.PeopleDAO; 5 | 6 | import javax.ws.rs.GET; 7 | import javax.ws.rs.POST; 8 | import javax.ws.rs.Path; 9 | import javax.ws.rs.Produces; 10 | import javax.ws.rs.core.MediaType; 11 | import java.util.List; 12 | 13 | @Path("/people") 14 | @Produces(MediaType.APPLICATION_JSON) 15 | public class PeopleResource { 16 | 17 | private final PeopleDAO peopleDAO; 18 | 19 | public PeopleResource(PeopleDAO peopleDAO) { 20 | this.peopleDAO = peopleDAO; 21 | } 22 | 23 | @POST 24 | public Person createPerson(Person person) { 25 | final long personId = peopleDAO.create(person); 26 | return peopleDAO.findById(personId); 27 | } 28 | 29 | @GET 30 | public List listPeople() { 31 | return peopleDAO.findAll(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /dropwizard-scala_2.9.1/src/test/scala/com/yammer/dropwizard/examples/SplodyCommand.scala: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.examples 2 | 3 | import com.yammer.dropwizard.cli.Command 4 | import com.yammer.dropwizard.{AbstractService, Service} 5 | import org.apache.commons.cli.{CommandLine, OptionGroup, Options, Option => CliOption} 6 | 7 | class SplodyCommand extends Command("splody", "Explodes with an error") { 8 | override def getOptions = { 9 | val opts = new Options 10 | 11 | val group = new OptionGroup 12 | group.setRequired(true) 13 | group.addOption(new CliOption("r", "required", false, "a required option")) 14 | 15 | opts.addOptionGroup(group) 16 | opts.addOption("e", "exception", false, "throw an exception") 17 | 18 | opts 19 | } 20 | 21 | protected def run(service: AbstractService[_], params: CommandLine) { 22 | if (params.hasOption("exception")) { 23 | println("Throwing an exception") 24 | sys.error("EXPERIENCE BIJ") 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jetty/JettyManaged.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jetty; 2 | 3 | import com.yammer.dropwizard.lifecycle.Managed; 4 | import org.eclipse.jetty.util.component.AbstractLifeCycle; 5 | 6 | /** 7 | * A wrapper for {@link Managed} instances which ties them to a Jetty 8 | * {@link org.eclipse.jetty.util.component.LifeCycle}. 9 | */ 10 | public class JettyManaged extends AbstractLifeCycle implements Managed { 11 | private final Managed managed; 12 | 13 | /** 14 | * Creates a new {@link JettyManaged} wrapping {@code managed}. 15 | * 16 | * @param managed a {@link Managed} instance to be wrapped 17 | */ 18 | public JettyManaged(Managed managed) { 19 | this.managed = managed; 20 | } 21 | 22 | @Override 23 | protected void doStart() throws Exception { 24 | managed.start(); 25 | } 26 | 27 | @Override 28 | protected void doStop() throws Exception { 29 | managed.stop(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dropwizard-auth/src/test/java/com/yammer/dropwizard/auth/oauth/tests/OAuthProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth.oauth.tests; 2 | 3 | import com.sun.jersey.core.spi.component.ComponentScope; 4 | import com.yammer.dropwizard.auth.Authenticator; 5 | import com.yammer.dropwizard.auth.oauth.OAuthProvider; 6 | import org.junit.Test; 7 | 8 | import static org.hamcrest.Matchers.is; 9 | import static org.junit.Assert.assertThat; 10 | import static org.mockito.Mockito.mock; 11 | 12 | @SuppressWarnings("unchecked") 13 | public class OAuthProviderTest { 14 | private final Authenticator authenticator = mock(Authenticator.class); 15 | private final OAuthProvider provider = new OAuthProvider(authenticator, 16 | "realm"); 17 | 18 | @Test 19 | public void isPerRequest() throws Exception { 20 | assertThat(provider.getScope(), 21 | is(ComponentScope.PerRequest)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/validation/ValidationMethod.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.validation; 2 | 3 | import javax.validation.Constraint; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.Target; 7 | 8 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 9 | import static java.lang.annotation.ElementType.METHOD; 10 | import static java.lang.annotation.ElementType.TYPE; 11 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 12 | 13 | /** 14 | * Validates a bean predicate method as returning true. Bean predicates must be of the form 15 | * {@code isSomething} or they'll be silently ignored. 16 | */ 17 | @Target({TYPE, ANNOTATION_TYPE, METHOD}) 18 | @Retention(RUNTIME) 19 | @Constraint(validatedBy = MethodValidator.class) 20 | @Documented 21 | public @interface ValidationMethod { 22 | String message() default "is not valid"; 23 | 24 | Class[] groups() default {}; 25 | 26 | Class[] payload() default {}; 27 | } 28 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/jersey/LoggingDBIExceptionMapper.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey; 2 | 3 | import com.yammer.dropwizard.logging.Log; 4 | import org.skife.jdbi.v2.exceptions.DBIException; 5 | 6 | import javax.ws.rs.ext.Provider; 7 | import java.sql.SQLException; 8 | 9 | /** 10 | * Iterates through a DBIException's cause if it's a SQLException otherwise log as normal. 11 | */ 12 | @Provider 13 | public class LoggingDBIExceptionMapper extends LoggingExceptionMapper { 14 | private static final Log LOG = Log.forClass(LoggingDBIExceptionMapper.class); 15 | 16 | @Override 17 | protected void logException(long id, DBIException exception) { 18 | final Throwable cause = exception.getCause(); 19 | if (cause instanceof SQLException) { 20 | for (Throwable throwable : (SQLException)cause) { 21 | LOG.error(throwable, formatLogMessage(id, throwable)); 22 | } 23 | } else { 24 | LOG.error(exception, formatLogMessage(id, exception)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/db/PeopleDAO.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.db; 2 | 3 | import com.example.helloworld.core.Person; 4 | import com.google.common.collect.ImmutableList; 5 | import org.skife.jdbi.v2.sqlobject.Bind; 6 | import org.skife.jdbi.v2.sqlobject.BindBean; 7 | import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys; 8 | import org.skife.jdbi.v2.sqlobject.SqlQuery; 9 | import org.skife.jdbi.v2.sqlobject.SqlUpdate; 10 | import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapperFactory; 11 | import org.skife.jdbi.v2.sqlobject.stringtemplate.ExternalizedSqlViaStringTemplate3; 12 | import org.skife.jdbi.v2.tweak.BeanMapperFactory; 13 | 14 | @ExternalizedSqlViaStringTemplate3 15 | @RegisterMapperFactory(BeanMapperFactory.class) 16 | public interface PeopleDAO { 17 | 18 | @SqlUpdate 19 | void createPeopleTable(); 20 | 21 | @SqlQuery 22 | Person findById(@Bind("id") Long id); 23 | 24 | @SqlUpdate 25 | @GetGeneratedKeys 26 | long create(@BindBean Person person); 27 | 28 | @SqlQuery 29 | ImmutableList findAll(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Dropwizard 2 | ========== 3 | 4 | *Dropwizard is a sneaky way of making fast Java or Scala web services.* 5 | 6 | It's a little bit of opinionated glue code which bangs together a set of libraries which have 7 | historically not sucked: 8 | 9 | * [Jetty](http://www.eclipse.org/jetty/) for HTTP servin'. 10 | * [Jersey](http://jersey.java.net/) for REST modelin'. 11 | * [Jackson](http://jackson.codehaus.org) for JSON parsin' and generatin'. 12 | * [Logback](http://logback.qos.ch/) for loggin'. 13 | * [Hibernate Validator](http://www.hibernate.org/subprojects/validator.html) for validatin'. 14 | * [Metrics](https://github.com/codahale/metrics) for figurin' out what your service is doing in 15 | production. 16 | * [SnakeYAML](http://code.google.com/p/snakeyaml/) for YAML parsin' and configuratin'. 17 | 18 | [Yammer](https://www.yammer.com)'s high-performance, low-latency, Java and Scala services all use 19 | Dropwizard. In fact, Dropwizard is really just a simple extraction of 20 | [Yammer](https://www.yammer.com)'s glue code. 21 | 22 | Read more at [dropwizard.codahale.com](http://dropwizard.codahale.com). 23 | -------------------------------------------------------------------------------- /dropwizard-auth/src/test/java/com/yammer/dropwizard/auth/basic/tests/BasicAuthProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth.basic.tests; 2 | 3 | import com.sun.jersey.core.spi.component.ComponentScope; 4 | import com.yammer.dropwizard.auth.Authenticator; 5 | import com.yammer.dropwizard.auth.basic.BasicAuthProvider; 6 | import com.yammer.dropwizard.auth.basic.BasicCredentials; 7 | import org.junit.Test; 8 | 9 | import static org.hamcrest.Matchers.is; 10 | import static org.junit.Assert.assertThat; 11 | import static org.mockito.Mockito.mock; 12 | 13 | @SuppressWarnings("unchecked") 14 | public class BasicAuthProviderTest { 15 | private final Authenticator authenticator = mock(Authenticator.class); 16 | private final BasicAuthProvider provider = new BasicAuthProvider(authenticator, 17 | "realm"); 18 | 19 | @Test 20 | public void isPerRequest() throws Exception { 21 | assertThat(provider.getScope(), 22 | is(ComponentScope.PerRequest)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dropwizard-views/src/main/java/com/yammer/dropwizard/views/View.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views; 2 | 3 | import com.yammer.metrics.Metrics; 4 | import com.yammer.metrics.core.Timer; 5 | import org.codehaus.jackson.annotate.JsonIgnore; 6 | 7 | public abstract class View { 8 | private final String templateName; 9 | private final Timer renderingTimer; 10 | 11 | protected View(String templateName) { 12 | 13 | this.templateName = resolveName(templateName); 14 | this.renderingTimer = Metrics.newTimer(getClass(), "rendering"); 15 | } 16 | 17 | private String resolveName(String templateName) { 18 | if (templateName.startsWith("/")) { 19 | return templateName; 20 | } 21 | final String packagePath = getClass().getPackage().getName().replace('.', '/'); 22 | return String.format("/%s/%s", packagePath, templateName); 23 | } 24 | 25 | @JsonIgnore 26 | public String getTemplateName() { 27 | return templateName; 28 | } 29 | 30 | @JsonIgnore 31 | Timer getRenderingTimer() { 32 | return renderingTimer; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. title:: Home 2 | 3 | .. raw:: html 4 | 5 |
6 | 7 | ################################################################################################### 8 | Dropwizard is a Java framework for developing ops-friendly, high-performance, RESTful web services. 9 | ################################################################################################### 10 | 11 | Developed by Yammer__ to power their JVM-based backend services, Dropwizard pulls together 12 | **stable**, **mature** libraries from the Java ecosystem into a **simple**, **light-weight** package 13 | that lets you focus on *getting things done*. 14 | 15 | .. __: https://www.yammer.com 16 | 17 | Dropwizard has *out-of-the-box* support for sophisticated **configuration**, 18 | **application metrics**, **logging**, **operational tools**, and much more, allowing you and your 19 | team to ship a *production-quality* HTTP+JSON web service in the shortest time possible. 20 | 21 | .. toctree:: 22 | :maxdepth: 1 23 | 24 | getting-started 25 | manual/index 26 | about/index 27 | 28 | .. raw:: html 29 | 30 |
31 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/config/ConfigurationException.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * An exception thrown where there is an error parsing a configuration object. 7 | */ 8 | public class ConfigurationException extends Exception { 9 | private static final long serialVersionUID = 5325162099634227047L; 10 | 11 | /** 12 | * Creates a new {@link ConfigurationException} for the given file with the given errors. 13 | * 14 | * @param file the bad configuration file 15 | * @param errors the errors in the file 16 | */ 17 | public ConfigurationException(File file, Iterable errors) { 18 | super(formatMessage(file, errors)); 19 | } 20 | 21 | private static String formatMessage(File file, Iterable errors) { 22 | final StringBuilder msg = new StringBuilder(file.toString()) 23 | .append(" has the following errors:\n"); 24 | for (String error : errors) { 25 | msg.append(" * ").append(error).append('\n'); 26 | } 27 | return msg.toString(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/params/BooleanParam.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey.params; 2 | 3 | /** 4 | * A parameter encapsulating boolean values. If the query parameter value is {@code "true"}, 5 | * regardless of case, the returned value is {@link Boolean#TRUE}. If the query parameter value is 6 | * {@code "false"}, regardless of case, the returned value is {@link Boolean#FALSE}. All other 7 | * values will return a {@code 400 Bad Request} response. 8 | */ 9 | public class BooleanParam extends AbstractParam { 10 | public BooleanParam(String input) { 11 | super(input); 12 | } 13 | 14 | @Override 15 | protected String errorMessage(String input, Exception e) { 16 | return '"' + input + "\" must be \"true\" or \"false\"."; 17 | } 18 | 19 | @Override 20 | protected Boolean parse(String input) throws Exception { 21 | if ("true".equalsIgnoreCase(input)) { 22 | return Boolean.TRUE; 23 | } 24 | if ("false".equalsIgnoreCase(input)) { 25 | return Boolean.FALSE; 26 | } 27 | throw new Exception(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/resources/yaml/http.yml: -------------------------------------------------------------------------------- 1 | requestLog: 2 | console: 3 | enabled: true 4 | file: 5 | enabled: true 6 | currentLogFilename: ./logs/requests.log 7 | archivedLogFilenamePattern: ./logs/requests-%d.log.gz 8 | archivedFileCount: 5 9 | syslog: 10 | enabled: false 11 | host: localhost 12 | facility: local0 13 | gzip: 14 | enabled: false 15 | port: 9080 16 | adminPort: 9081 17 | maxThreads: 101 18 | minThreads: 89 19 | rootPath: "/services/*" 20 | connectorType: legacy 21 | maxIdleTime: 2s 22 | acceptorThreadCount: 2 23 | acceptorThreadPriorityOffset: -3 24 | acceptQueueSize: 100 25 | maxBufferCount: 512 26 | requestBufferSize: 16KB 27 | requestHeaderBufferSize: 17KB 28 | responseBufferSize: 18KB 29 | responseHeaderBufferSize: 19KB 30 | reuseAddress: false 31 | soLingerTime: 2s 32 | lowResourcesConnectionThreshold: 1000 33 | lowResourcesMaxIdleTime: 1s 34 | shutdownGracePeriod: 5s 35 | useServerHeader: true 36 | useDateHeader: false 37 | useForwardedHeaders: false 38 | useDirectBuffers: false 39 | bindHost: "localhost" 40 | contextParameters: 41 | param: value 42 | adminUsername: admin 43 | adminPassword: password 44 | -------------------------------------------------------------------------------- /docs/source/about/contributors.rst: -------------------------------------------------------------------------------- 1 | .. _about-contributors: 2 | 3 | ############ 4 | Contributors 5 | ############ 6 | 7 | Many, many thanks to: 8 | 9 | * `Adam Marcus `_ 10 | * `Brian McCallister `_ 11 | * `Brian O'Neill `_ 12 | * `Cagatay Kavukcuoglu `_ 13 | * `Chris Gray `_ 14 | * `Christopher Elkins `_ 15 | * `Collin VanDyck `_ 16 | * `Eric Tschetter `_ 17 | * `Fredrik Sundberg `_ 18 | * `James Ward `_ 19 | * `Joshua Spiewak `_ 20 | * `Michael Fairley `_ 21 | * `Nick Telford `_ 22 | * `Sam Perman `_ 23 | * `Tatu Saloranta `_ 24 | * `Ted Nyman `_ 25 | * `Tom Crayford `_ 26 | * `Tom Morris `_ 27 | * `Vidit Drolia `_ 28 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/bundles/JavaBundle.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.bundles; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.yammer.dropwizard.Bundle; 5 | import com.yammer.dropwizard.Service; 6 | import com.yammer.dropwizard.config.Environment; 7 | import com.yammer.dropwizard.jersey.JacksonMessageBodyProvider; 8 | import com.yammer.dropwizard.jersey.OptionalQueryParamInjectableProvider; 9 | 10 | /** 11 | * Initializes the service with support for Java classes. 12 | */ 13 | public class JavaBundle implements Bundle { 14 | public static final ImmutableList DEFAULT_PROVIDERS = ImmutableList.of( 15 | new OptionalQueryParamInjectableProvider() 16 | ); 17 | 18 | private final Service service; 19 | 20 | public JavaBundle(Service service) { 21 | this.service = service; 22 | } 23 | 24 | @Override 25 | public void initialize(Environment environment) { 26 | environment.addProvider(new JacksonMessageBodyProvider(service.getJson())); 27 | for (Object provider : DEFAULT_PROVIDERS) { 28 | environment.addProvider(provider); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/servlets/CacheBustingFilter.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.servlets; 2 | 3 | import org.eclipse.jetty.http.HttpHeaders; 4 | 5 | import javax.servlet.*; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.io.IOException; 8 | 9 | /** 10 | * Adds a no-cache header to all responses. 11 | */ 12 | public class CacheBustingFilter implements Filter { 13 | private static final String CACHE_SETTINGS = "must-revalidate,no-cache,no-store"; 14 | 15 | @Override 16 | public void doFilter(ServletRequest request, 17 | ServletResponse response, 18 | FilterChain chain) throws IOException, ServletException { 19 | if (response instanceof HttpServletResponse) { 20 | final HttpServletResponse resp = (HttpServletResponse) response; 21 | resp.setHeader(HttpHeaders.CACHE_CONTROL, CACHE_SETTINGS); 22 | } 23 | chain.doFilter(request, response); 24 | } 25 | 26 | @Override 27 | public void destroy() { /* unused */ } 28 | 29 | @Override 30 | public void init(FilterConfig filterConfig) throws ServletException { /* unused */ } 31 | } 32 | -------------------------------------------------------------------------------- /dropwizard-auth/src/main/java/com/yammer/dropwizard/auth/Authenticator.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth; 2 | 3 | import com.google.common.base.Optional; 4 | 5 | /** 6 | * An interface for classes which authenticate user-provided credentials and return principal 7 | * objects. 8 | * 9 | * @param the type of credentials the authenticator can authenticate 10 | * @param

the type of principals the authenticator returns 11 | */ 12 | public interface Authenticator { 13 | /** 14 | * Given a set of user-provided credentials, return an optional principal. 15 | * 16 | *

If the credentials are valid and map to a principal, returns an {@code Optional.of(p)}.

17 | * 18 | *

If the credentials are invalid, returns an {@code Optional.absent()}.

19 | * 20 | * @param credentials a set of user-provided credentials 21 | * @return either an authenticated principal or an absent optional 22 | * @throws AuthenticationException if the credentials cannot be authenticated due to an 23 | * underlying error 24 | */ 25 | Optional

authenticate(C credentials) throws AuthenticationException; 26 | } 27 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/db/ImmutableListContainerFactory.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.db; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import org.skife.jdbi.v2.ContainerBuilder; 5 | import org.skife.jdbi.v2.tweak.ContainerFactory; 6 | 7 | public class ImmutableListContainerFactory implements ContainerFactory> { 8 | @Override 9 | public boolean accepts(Class type) { 10 | return ImmutableList.class.isAssignableFrom(type); 11 | } 12 | 13 | @Override 14 | public ContainerBuilder> newContainerBuilderFor(Class type) { 15 | return new ImmutableListContainerBuilder(); 16 | } 17 | 18 | private static class ImmutableListContainerBuilder implements ContainerBuilder> { 19 | private final ImmutableList.Builder builder = ImmutableList.builder(); 20 | 21 | @Override 22 | public ContainerBuilder> add(Object it) { 23 | builder.add(it); 24 | return this; 25 | } 26 | 27 | @Override 28 | public ImmutableList build() { 29 | return builder.build(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dropwizard-client/src/main/java/com/yammer/dropwizard/client/JerseyClient.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.client; 2 | 3 | import com.sun.jersey.api.client.config.ClientConfig; 4 | import com.sun.jersey.client.apache4.ApacheHttpClient4; 5 | import com.sun.jersey.client.apache4.ApacheHttpClient4Handler; 6 | 7 | import javax.ws.rs.core.MediaType; 8 | import java.net.URI; 9 | 10 | public class JerseyClient extends ApacheHttpClient4 { 11 | public JerseyClient(ApacheHttpClient4Handler root, ClientConfig config) { 12 | super(root, config); 13 | } 14 | 15 | public T get(URI uri, MediaType acceptedMediaType, Class klass) { 16 | return resource(uri).accept(acceptedMediaType).get(klass); 17 | } 18 | 19 | public T put(URI uri, MediaType contentType, Object entity, Class returnType) { 20 | return resource(uri).type(contentType).put(returnType, entity); 21 | } 22 | 23 | public T post(URI uri, MediaType contentType, Object entity, Class returnType) { 24 | return resource(uri).type(contentType).post(returnType, entity); 25 | } 26 | 27 | public T delete(URI uri, Class klass) { 28 | return resource(uri).delete(klass); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/tasks/Task.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.tasks; 2 | 3 | import com.google.common.collect.ImmutableMultimap; 4 | 5 | import java.io.PrintWriter; 6 | 7 | /** 8 | * An arbitrary administrative task which can be performed via the internal service interface. 9 | * 10 | * @see TaskServlet 11 | */ 12 | public abstract class Task { 13 | private final String name; 14 | 15 | /** 16 | * Create a new task with the given name. 17 | * 18 | * @param name the task's name 19 | */ 20 | protected Task(String name) { 21 | this.name = name; 22 | } 23 | 24 | /** 25 | * Returns the task's name, 26 | * 27 | * @return the task's name 28 | */ 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | /** 34 | * Executes the task. 35 | * 36 | * @param parameters the query string parameters 37 | * @param output a {@link PrintWriter} wrapping the output stream of the task 38 | * @throws Exception if something goes wrong 39 | */ 40 | public abstract void execute(ImmutableMultimap parameters, 41 | PrintWriter output) throws Exception; 42 | } 43 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/OptionalExtractor.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey; 2 | 3 | import com.google.common.base.Optional; 4 | import com.sun.jersey.server.impl.model.parameter.multivalued.MultivaluedParameterExtractor; 5 | 6 | import javax.ws.rs.core.MultivaluedMap; 7 | 8 | // TODO: 11/14/11 -- test OptionalExtractor 9 | // TODO: 11/14/11 -- document OptionalExtractor 10 | 11 | public class OptionalExtractor implements MultivaluedParameterExtractor { 12 | private final String parameterName; 13 | private final Optional defaultValue; 14 | 15 | public OptionalExtractor(String parameterName, String defaultValue) { 16 | this.parameterName = parameterName; 17 | this.defaultValue = Optional.fromNullable(defaultValue); 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return parameterName; 23 | } 24 | 25 | @Override 26 | public String getDefaultStringValue() { 27 | return defaultValue.orNull(); 28 | } 29 | 30 | @Override 31 | public Object extract(MultivaluedMap parameters) { 32 | return Optional.fromNullable(parameters.getFirst(parameterName)).or(defaultValue); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/code.less: -------------------------------------------------------------------------------- 1 | // Code.less 2 | // Code typography styles for the and
 elements
 3 | // --------------------------------------------------------
 4 | 
 5 | // Inline and block code styles
 6 | .code-and-pre,
 7 | pre {
 8 |   padding: 0 3px 2px;
 9 |   #font > #family > .monospace;
10 |   font-size: @baseFontSize - 1;
11 |   color: @grayDark;
12 |   .border-radius(3px);
13 | }
14 | .code, code {
15 |   .code-and-pre();
16 |   color: #d14;
17 |   background-color: #f7f7f9;
18 |   border: 1px solid #e1e1e8;
19 | }
20 | pre {
21 |   display: block;
22 |   padding: (@baseLineHeight - 1) / 2;
23 |   margin: 0 0 @baseLineHeight / 2;
24 |   font-size: 12px;
25 |   line-height: @baseLineHeight;
26 |   background-color: #f5f5f5;
27 |   border: 1px solid #ccc; // fallback for IE7-8
28 |   border: 1px solid rgba(0,0,0,.15);
29 |   .border-radius(4px);
30 |   white-space: pre;
31 |   white-space: pre-wrap;
32 |   word-break: break-all;
33 | 
34 |   // Make prettyprint styles more spaced out for readability
35 |   &.prettyprint {
36 |     margin-bottom: @baseLineHeight;
37 |   }
38 | 
39 |   // Account for some code outputs that place code tags in pre tags
40 |   code {
41 |     padding: 0;
42 |     background-color: transparent;
43 |   }
44 | }
45 | 


--------------------------------------------------------------------------------
/dropwizard-example/src/main/java/com/example/helloworld/HelloWorldConfiguration.java:
--------------------------------------------------------------------------------
 1 | package com.example.helloworld;
 2 | 
 3 | import com.example.helloworld.core.Template;
 4 | import com.yammer.dropwizard.config.Configuration;
 5 | import com.yammer.dropwizard.db.DatabaseConfiguration;
 6 | import org.codehaus.jackson.annotate.JsonProperty;
 7 | import org.hibernate.validator.constraints.NotEmpty;
 8 | 
 9 | import javax.validation.Valid;
10 | import javax.validation.constraints.NotNull;
11 | 
12 | @SuppressWarnings("FieldMayBeFinal")
13 | public class HelloWorldConfiguration extends Configuration {
14 | 
15 |     @NotEmpty
16 |     private String template;
17 |     
18 |     @NotEmpty
19 |     private String defaultName = "Stranger";
20 | 
21 |     @Valid
22 |     @NotNull
23 |     @JsonProperty
24 |     private DatabaseConfiguration database = new DatabaseConfiguration();
25 | 
26 |     public String getTemplate() {
27 |         return template;
28 |     }
29 | 
30 |     public String getDefaultName() {
31 |         return defaultName;
32 |     }
33 | 
34 |     public Template buildTemplate() {
35 |         return new Template(template, defaultName);
36 |     }
37 | 
38 |     public DatabaseConfiguration getDatabaseConfiguration() {
39 |         return database;
40 |     }
41 | }
42 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/util/tests/ServletsTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.util.tests;
 2 | 
 3 | import com.yammer.dropwizard.util.Servlets;
 4 | import org.junit.Test;
 5 | 
 6 | import javax.servlet.http.HttpServletRequest;
 7 | 
 8 | import static org.hamcrest.Matchers.is;
 9 | import static org.junit.Assert.assertThat;
10 | import static org.mockito.Mockito.mock;
11 | import static org.mockito.Mockito.when;
12 | 
13 | public class ServletsTest {
14 |     private final HttpServletRequest request = mock(HttpServletRequest.class);
15 |     private final HttpServletRequest fullRequest = mock(HttpServletRequest.class);
16 | 
17 |     {
18 |         when(request.getRequestURI()).thenReturn("/one/two");
19 |         when(fullRequest.getRequestURI()).thenReturn("/one/two");
20 |         when(fullRequest.getQueryString()).thenReturn("one=two&three=four");
21 |     }
22 | 
23 |     @Test
24 |     public void formatsBasicURIs() throws Exception {
25 |         assertThat(Servlets.getFullUrl(request),
26 |                    is("/one/two"));
27 |     }
28 | 
29 |     @Test
30 |     public void formatsFullURIs() throws Exception {
31 |         assertThat(Servlets.getFullUrl(fullRequest),
32 |                    is("/one/two?one=two&three=four"));
33 |     }
34 | }
35 | 


--------------------------------------------------------------------------------
/dropwizard-example/src/main/java/com/example/helloworld/resources/HelloWorldResource.java:
--------------------------------------------------------------------------------
 1 | package com.example.helloworld.resources;
 2 | 
 3 | import com.example.helloworld.core.Saying;
 4 | import com.example.helloworld.core.Template;
 5 | import com.google.common.base.Optional;
 6 | import com.yammer.dropwizard.jersey.caching.CacheControl;
 7 | import com.yammer.metrics.annotation.Timed;
 8 | 
 9 | import javax.ws.rs.GET;
10 | import javax.ws.rs.Path;
11 | import javax.ws.rs.Produces;
12 | import javax.ws.rs.QueryParam;
13 | import javax.ws.rs.core.MediaType;
14 | import java.util.concurrent.TimeUnit;
15 | import java.util.concurrent.atomic.AtomicLong;
16 | 
17 | @Path("/hello-world")
18 | @Produces(MediaType.APPLICATION_JSON)
19 | public class HelloWorldResource {
20 |     private final Template template;
21 |     private final AtomicLong counter;
22 | 
23 |     public HelloWorldResource(Template template) {
24 |         this.template = template;
25 |         this.counter = new AtomicLong();
26 |     }
27 | 
28 |     @GET
29 |     @Timed(name = "get-requests")
30 |     @CacheControl(maxAge = 1, maxAgeUnit = TimeUnit.DAYS)
31 |     public Saying sayHello(@QueryParam("name") Optional name) {
32 |         return new Saying(counter.incrementAndGet(), template.render(name));
33 |     }
34 | }
35 | 


--------------------------------------------------------------------------------
/docs/source/_themes/yammerdoc/less/pagination.less:
--------------------------------------------------------------------------------
 1 | // PAGINATION
 2 | // ----------
 3 | 
 4 | .pagination {
 5 |   height: @baseLineHeight * 2;
 6 |   margin: @baseLineHeight 0;
 7 |  }
 8 | .pagination ul {
 9 |   display: inline-block;
10 |   .ie7-inline-block();
11 |   margin-left: 0;
12 |   margin-bottom: 0;
13 |   .border-radius(3px);
14 |   .box-shadow(0 1px 2px rgba(0,0,0,.05));
15 | }
16 | .pagination li {
17 |     display: inline;
18 |   }
19 | .pagination a {
20 |   float: left;
21 |   padding: 0 14px;
22 |   line-height: (@baseLineHeight * 2) - 2;
23 |   text-decoration: none;
24 |   border: 1px solid #ddd;
25 |   border-left-width: 0;
26 | }
27 | .pagination a:hover,
28 | .pagination .active a {
29 |   background-color: #f5f5f5;
30 | }
31 | .pagination .active a {
32 |   color: @grayLight;
33 |   cursor: default;
34 | }
35 | .pagination .disabled a,
36 | .pagination .disabled a:hover {
37 |   color: @grayLight;
38 |   background-color: transparent;
39 |   cursor: default;
40 | }
41 | .pagination li:first-child a {
42 |   border-left-width: 1px;
43 |   .border-radius(3px 0 0 3px);
44 | }
45 | .pagination li:last-child a {
46 |   .border-radius(0 3px 3px 0);
47 | }
48 | 
49 | // Centered
50 | .pagination-centered {
51 |   text-align: center;
52 | }
53 | .pagination-right {
54 |   text-align: right;
55 | }
56 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/config/RequestLogConfiguration.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.config;
 2 | 
 3 | import org.codehaus.jackson.annotate.JsonProperty;
 4 | 
 5 | import javax.validation.constraints.NotNull;
 6 | 
 7 | import java.util.TimeZone;
 8 | 
 9 | import static com.yammer.dropwizard.config.LoggingConfiguration.*;
10 | 
11 | @SuppressWarnings({ "FieldMayBeFinal", "FieldCanBeLocal" })
12 | public class RequestLogConfiguration {
13 |     @NotNull
14 |     @JsonProperty
15 |     protected ConsoleConfiguration console = new ConsoleConfiguration();
16 | 
17 |     @NotNull
18 |     @JsonProperty
19 |     protected FileConfiguration file = new FileConfiguration();
20 | 
21 |     @NotNull
22 |     @JsonProperty
23 |     protected SyslogConfiguration syslog = new SyslogConfiguration();
24 | 
25 |     @NotNull
26 |     @JsonProperty
27 |     protected TimeZone timeZone = UTC;
28 | 
29 |     public ConsoleConfiguration getConsoleConfiguration() {
30 |         return console;
31 |     }
32 | 
33 |     public FileConfiguration getFileConfiguration() {
34 |         return file;
35 |     }
36 | 
37 |     public SyslogConfiguration getSyslogConfiguration() {
38 |         return syslog;
39 |     }
40 | 
41 |     public TimeZone getTimeZone() {
42 |         return timeZone;
43 |     }
44 | }
45 | 


--------------------------------------------------------------------------------
/dropwizard-testing/src/test/java/com/yammer/dropwizard/testing/tests/service/PersonResourceTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.testing.tests.service;
 2 | 
 3 | import com.yammer.dropwizard.testing.ResourceTest;
 4 | import com.yammer.dropwizard.testing.tests.Person;
 5 | import org.junit.Test;
 6 | 
 7 | import java.util.logging.Level;
 8 | import java.util.logging.Logger;
 9 | 
10 | import static org.hamcrest.Matchers.is;
11 | import static org.junit.Assert.assertThat;
12 | import static org.mockito.Matchers.anyString;
13 | import static org.mockito.Mockito.mock;
14 | import static org.mockito.Mockito.when;
15 | 
16 | public class PersonResourceTest extends ResourceTest {
17 |     static {
18 |         Logger.getLogger("com.sun.jersey").setLevel(Level.OFF);
19 |     }
20 | 
21 |     private final Person person = new Person("blah", "blah@example.com");
22 |     private final PeopleStore store = mock(PeopleStore.class);
23 | 
24 |     @Override
25 |     protected void setUpResources() {
26 |         when(store.fetchPerson(anyString())).thenReturn(person);
27 |         addResource(new PersonResource(store));
28 |     }
29 | 
30 |     @Test
31 |     public void simpleResourceTest() throws Exception {
32 |         assertThat(client().resource("/person/blah").get(Person.class),
33 |                    is(person));
34 |     }
35 | }
36 | 


--------------------------------------------------------------------------------
/docs/source/_themes/yammerdoc/less/popovers.less:
--------------------------------------------------------------------------------
 1 | // POPOVERS
 2 | // --------
 3 | 
 4 | .popover {
 5 |   position: absolute;
 6 |   top: 0;
 7 |   left: 0;
 8 |   z-index: @zindexPopover;
 9 |   display: none;
10 |   padding: 5px;
11 |   &.top    { margin-top:  -5px; }
12 |   &.right  { margin-left:  5px; }
13 |   &.bottom { margin-top:   5px; }
14 |   &.left   { margin-left: -5px; }
15 |   &.top .arrow    { #popoverArrow > .top(); }
16 |   &.right .arrow  { #popoverArrow > .right(); }
17 |   &.bottom .arrow { #popoverArrow > .bottom(); }
18 |   &.left .arrow   { #popoverArrow > .left();  }
19 |   .arrow {
20 |     position: absolute;
21 |     width: 0;
22 |     height: 0;
23 |   }
24 | }
25 | .popover-inner {
26 |   padding: 3px;
27 |   width: 280px;
28 |   overflow: hidden;
29 |   background: @black; // has to be full background declaration for IE fallback
30 |   background: rgba(0,0,0,.8);
31 |   .border-radius(6px);
32 |   .box-shadow(0 3px 7px rgba(0,0,0,0.3));
33 | }
34 | .popover-title {
35 |   padding: 9px 15px;
36 |   line-height: 1;
37 |   background-color: #f5f5f5;
38 |   border-bottom:1px solid #eee;
39 |   .border-radius(3px 3px 0 0);
40 | }
41 | .popover-content {
42 |   padding: 14px;
43 |   background-color: @white;
44 |   .border-radius(0 0 3px 3px);
45 |   .background-clip(padding-box);
46 |   p, ul, ol {
47 |     margin-bottom: 0;
48 |   }
49 | }
50 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/jersey/params/tests/IntParamTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.jersey.params.tests;
 2 | 
 3 | import com.yammer.dropwizard.jersey.params.IntParam;
 4 | import org.junit.Test;
 5 | 
 6 | import javax.ws.rs.WebApplicationException;
 7 | import javax.ws.rs.core.Response;
 8 | 
 9 | import static org.hamcrest.Matchers.is;
10 | import static org.junit.Assert.assertThat;
11 | import static org.junit.Assert.fail;
12 | 
13 | public class IntParamTest {
14 |     @Test
15 |     public void anIntegerReturnsAnInteger() throws Exception {
16 |         final IntParam param = new IntParam("200");
17 | 
18 |         assertThat(param.get(),
19 |                    is(200));
20 |     }
21 | 
22 |     @Test
23 |     @SuppressWarnings("ResultOfObjectAllocationIgnored")
24 |     public void aNonIntegerThrowsAnException() throws Exception {
25 |         try {
26 |             new IntParam("foo");
27 |             fail("expected a WebApplicationException, but none was thrown");
28 |         } catch (WebApplicationException e) {
29 |             final Response response = e.getResponse();
30 | 
31 |             assertThat(response.getStatus(),
32 |                        is(400));
33 | 
34 |             assertThat((String) response.getEntity(),
35 |                        is("\"foo\" is not a number."));
36 |         }
37 |     }
38 | }
39 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/jersey/params/tests/LongParamTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.jersey.params.tests;
 2 | 
 3 | import com.yammer.dropwizard.jersey.params.LongParam;
 4 | import org.junit.Test;
 5 | 
 6 | import javax.ws.rs.WebApplicationException;
 7 | import javax.ws.rs.core.Response;
 8 | 
 9 | import static org.hamcrest.Matchers.is;
10 | import static org.junit.Assert.assertThat;
11 | import static org.junit.Assert.fail;
12 | 
13 | public class LongParamTest {
14 |     @Test
15 |     public void aLongReturnsALong() throws Exception {
16 |         final LongParam param = new LongParam("200");
17 | 
18 |         assertThat(param.get(),
19 |                    is(200L));
20 |     }
21 | 
22 |     @Test
23 |     @SuppressWarnings("ResultOfObjectAllocationIgnored")
24 |     public void aNonIntegerThrowsAnException() throws Exception {
25 |         try {
26 |             new LongParam("foo");
27 |             fail("expected a WebApplicationException, but none was thrown");
28 |         } catch (WebApplicationException e) {
29 |             final Response response = e.getResponse();
30 | 
31 |             assertThat(response.getStatus(),
32 |                        is(400));
33 | 
34 |             assertThat((String) response.getEntity(),
35 |                        is("\"foo\" is not a number."));
36 |         }
37 |     }
38 | }
39 | 


--------------------------------------------------------------------------------
/dropwizard-testing/src/test/java/com/yammer/dropwizard/testing/tests/JsonHelpersTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.testing.tests;
 2 | 
 3 | import org.codehaus.jackson.type.TypeReference;
 4 | import org.junit.Test;
 5 | 
 6 | import static com.yammer.dropwizard.testing.JsonHelpers.*;
 7 | import static org.hamcrest.Matchers.is;
 8 | import static org.junit.Assert.assertThat;
 9 | 
10 | public class JsonHelpersTest {
11 |     private final String json = "{\"name\":\"Coda\",\"email\":\"coda@example.com\"}";
12 | 
13 |     @Test
14 |     public void readsJsonFixturesAsJsonNodes() throws Exception {
15 |         assertThat(jsonFixture("fixtures/person.json"),
16 |                    is(json));
17 |     }
18 | 
19 |     @Test
20 |     public void convertsObjectsIntoJson() throws Exception {
21 |         assertThat(asJson(new Person("Coda", "coda@example.com")),
22 |                    is(jsonFixture("fixtures/person.json")));
23 |     }
24 | 
25 |     @Test
26 |     public void convertsJsonIntoObjects() throws Exception {
27 |         assertThat(fromJson(jsonFixture("fixtures/person.json"), Person.class),
28 |                    is(new Person("Coda", "coda@example.com")));
29 | 
30 |         assertThat(fromJson(jsonFixture("fixtures/person.json"), new TypeReference() {}),
31 |                    is(new Person("Coda", "coda@example.com")));
32 |     }
33 | }
34 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/Service.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard;
 2 | 
 3 | import com.yammer.dropwizard.bundles.JavaBundle;
 4 | import com.yammer.dropwizard.config.Configuration;
 5 | 
 6 | /**
 7 |  * The default Java service class. Extend this to write your own service.
 8 |  *
 9 |  * @param     the type of configuration class to use
10 |  * @see Configuration
11 |  */
12 | public abstract class Service extends AbstractService {
13 |     protected Service(String name) {
14 |         super(name);
15 |         addBundle(new JavaBundle(this));
16 |         checkForScalaExtensions();
17 |     }
18 | 
19 |     @Override
20 |     protected final void subclassServiceInsteadOfThis() {
21 | 
22 |     }
23 | 
24 |     private void checkForScalaExtensions() {
25 |         try {
26 |             final Class scalaObject = Class.forName("scala.ScalaObject");
27 |             final Class klass = getClass();
28 |             if (scalaObject.isAssignableFrom(klass)) {
29 |                 throw new IllegalStateException(klass.getCanonicalName() + " is a Scala class. " +
30 |                                                         "It should extend ScalaService, not Service.");
31 |             }
32 |         } catch (ClassNotFoundException ignored) {
33 |             // definitely not a Scala project
34 |         }
35 |     }
36 | }
37 | 


--------------------------------------------------------------------------------
/dropwizard-client/src/main/java/com/yammer/dropwizard/client/JerseyClientConfiguration.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.client;
 2 | 
 3 | import com.yammer.dropwizard.validation.ValidationMethod;
 4 | 
 5 | import javax.validation.constraints.Max;
 6 | import javax.validation.constraints.Min;
 7 | 
 8 | public class JerseyClientConfiguration extends HttpClientConfiguration {
 9 |     @Max(16 * 1024)
10 |     @Min(1)
11 |     private int minThreads = 1;
12 | 
13 |     @Max(16 * 1024)
14 |     @Min(1)
15 |     private int maxThreads = 128;
16 | 
17 |     private boolean gzipEnabled = true;
18 | 
19 |     public int getMinThreads() {
20 |         return minThreads;
21 |     }
22 | 
23 |     public void setMinThreads(int minThreads) {
24 |         this.minThreads = minThreads;
25 |     }
26 | 
27 |     public int getMaxThreads() {
28 |         return maxThreads;
29 |     }
30 | 
31 |     public void setMaxThreads(int maxThreads) {
32 |         this.maxThreads = maxThreads;
33 |     }
34 | 
35 |     public boolean isGzipEnabled() {
36 |         return gzipEnabled;
37 |     }
38 | 
39 |     public void setGzipEnabled(boolean enable) {
40 |         this.gzipEnabled = enable;
41 |     }
42 | 
43 |     @ValidationMethod(message = ".minThreads must be less than or equal to maxThreads")
44 |     public boolean isThreadPoolSizedCorrectly() {
45 |         return minThreads <= maxThreads;
46 |     }
47 | }
48 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/cli/tests/ConfiguredCommandTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.cli.tests;
 2 | 
 3 | import org.junit.Assert;
 4 | 
 5 | import com.yammer.dropwizard.AbstractService;
 6 | import com.yammer.dropwizard.cli.ConfiguredCommand;
 7 | import com.yammer.dropwizard.config.Configuration;
 8 | 
 9 | import org.apache.commons.cli.CommandLine;
10 | import org.junit.Test;
11 | 
12 | public class ConfiguredCommandTest {
13 |     public static class MyConfig extends Configuration { }
14 | 
15 |     static class DirectCommand extends ConfiguredCommand {
16 |         protected DirectCommand() { super("test", "foobar"); }
17 |         @Override protected void run(AbstractService service, MyConfig configuration, CommandLine params) { }
18 |         // needed since super-class method is protected
19 |         public Class getParameterization() { return super.getConfigurationClass(); }
20 |     }
21 | 
22 |     static class UberCommand extends DirectCommand { }
23 |     
24 |     @Test
25 |     public void canResolveParameterization() {
26 |         // first, simple case with direct sub-class parameterization:
27 |         Assert.assertEquals(new DirectCommand().getParameterization(), MyConfig.class);
28 |         // then indirect one
29 |         Assert.assertEquals(new UberCommand().getParameterization(), MyConfig.class);
30 |     }
31 | 
32 | }
33 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/tasks/tests/GarbageCollectionTaskTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.tasks.tests;
 2 | 
 3 | import com.google.common.collect.ImmutableMultimap;
 4 | import com.yammer.dropwizard.tasks.GarbageCollectionTask;
 5 | import com.yammer.dropwizard.tasks.Task;
 6 | import org.junit.Test;
 7 | 
 8 | import java.io.PrintWriter;
 9 | 
10 | import static org.mockito.Mockito.*;
11 | 
12 | @SuppressWarnings("CallToSystemGC")
13 | public class GarbageCollectionTaskTest {
14 |     private final Runtime runtime = mock(Runtime.class);
15 |     private final PrintWriter output = mock(PrintWriter.class);
16 |     private final Task task = new GarbageCollectionTask(runtime);
17 | 
18 |     @Test
19 |     public void runsOnceWithNoParameters() throws Exception {
20 |         task.execute(ImmutableMultimap.of(), output);
21 | 
22 |         verify(runtime, times(1)).gc();
23 |     }
24 | 
25 |     @Test
26 |     public void usesTheFirstRunsParameter() throws Exception {
27 |         task.execute(ImmutableMultimap.of("runs", "3", "runs", "2"), output);
28 | 
29 |         verify(runtime, times(3)).gc();
30 |     }
31 | 
32 |     @Test
33 |     public void defaultsToOneRunIfTheQueryParamDoesNotParse() throws Exception {
34 |         task.execute(ImmutableMultimap.of("runs", "$"), output);
35 | 
36 |         verify(runtime, times(1)).gc();
37 |     }
38 | }
39 | 


--------------------------------------------------------------------------------
/dropwizard-db/src/main/java/com/yammer/dropwizard/db/NamePrependingStatementRewriter.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.db;
 2 | 
 3 | import org.skife.jdbi.v2.Binding;
 4 | import org.skife.jdbi.v2.StatementContext;
 5 | import org.skife.jdbi.v2.tweak.RewrittenStatement;
 6 | import org.skife.jdbi.v2.tweak.StatementRewriter;
 7 | 
 8 | class NamePrependingStatementRewriter implements StatementRewriter {
 9 |     private final StatementRewriter rewriter;
10 | 
11 |     NamePrependingStatementRewriter(StatementRewriter rewriter) {
12 |         this.rewriter = rewriter;
13 |     }
14 | 
15 |     @Override
16 |     public RewrittenStatement rewrite(String sql, Binding params, StatementContext ctx) {
17 |         if ((ctx.getSqlObjectType() != null) && (ctx.getSqlObjectMethod() != null)) {
18 |             final StringBuilder query = new StringBuilder(sql.length() + 100);
19 |             query.append("/* ");
20 |             final String className = ctx.getSqlObjectType().getSimpleName();
21 |             if (!className.isEmpty()) {
22 |                 query.append(className).append('.');
23 |             }
24 |             query.append(ctx.getSqlObjectMethod().getName());
25 |             query.append(" */ ");
26 |             query.append(sql);
27 |             return rewriter.rewrite(query.toString(), params, ctx);
28 |         }
29 |         return rewriter.rewrite(sql, params, ctx);
30 |     }
31 | }
32 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/cli/tests/CommandTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.cli.tests;
 2 | 
 3 | import com.yammer.dropwizard.AbstractService;
 4 | import com.yammer.dropwizard.cli.Command;
 5 | import org.apache.commons.cli.CommandLine;
 6 | import org.apache.commons.cli.Options;
 7 | import org.junit.Test;
 8 | 
 9 | import static org.hamcrest.Matchers.is;
10 | import static org.junit.Assert.assertThat;
11 | 
12 | public class CommandTest {
13 |     public static class ExampleCommand extends Command {
14 |         public ExampleCommand() {
15 |             super("name", "description");
16 |         }
17 | 
18 |         @Override
19 |         protected void run(AbstractService service,
20 |                            CommandLine params) throws Exception {
21 |         }
22 |     }
23 | 
24 |     private final ExampleCommand command = new ExampleCommand();
25 | 
26 |     @Test
27 |     public void hasAName() throws Exception {
28 |         assertThat(command.getName(),
29 |                    is("name"));
30 |     }
31 | 
32 |     @Test
33 |     public void hasADescription() throws Exception {
34 |         assertThat(command.getDescription(),
35 |                    is("description"));
36 |     }
37 | 
38 |     @Test
39 |     public void hasEmptyOptionsByDefault() throws Exception {
40 |         assertThat(command.getOptions().toString(),
41 |                    is(new Options().toString()));
42 |     }
43 | }
44 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests/ConfigurationTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.config.tests;
 2 | 
 3 | import com.yammer.dropwizard.config.Configuration;
 4 | import com.yammer.dropwizard.json.Json;
 5 | 
 6 | import org.junit.Test;
 7 | 
 8 | import static org.hamcrest.Matchers.is;
 9 | import static org.hamcrest.Matchers.notNullValue;
10 | import static org.junit.Assert.assertThat;
11 | 
12 | public class ConfigurationTest {
13 |     private final Configuration configuration = new Configuration();
14 | 
15 |     @Test
16 |     public void hasAnHttpConfiguration() throws Exception {
17 |         assertThat(configuration.getHttpConfiguration(),
18 |                    is(notNullValue()));
19 |     }
20 | 
21 |     @Test
22 |     public void hasALoggingConfiguration() throws Exception {
23 |         assertThat(configuration.getLoggingConfiguration(),
24 |                    is(notNullValue()));
25 |     }
26 | 
27 |     @Test
28 |     public void ensureConfigSerializable() throws Exception {
29 |         Json mapper = new Json();
30 |         // Issue-96: some types were not serializable
31 |         String json = mapper.writeValueAsString(configuration);
32 |         assertThat(json, is(notNullValue()));
33 | 
34 |         // and as an added bonus, let's see we can also read it back:
35 |         Configuration cfg = mapper.readValue(json, Configuration.class);
36 |         assertThat(cfg, is(notNullValue()));
37 |     }
38 | }
39 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/config/GzipConfiguration.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.config;
 2 | 
 3 | import com.google.common.base.Optional;
 4 | import com.google.common.collect.ImmutableSet;
 5 | import com.yammer.dropwizard.util.Size;
 6 | import org.codehaus.jackson.annotate.JsonProperty;
 7 | 
 8 | @SuppressWarnings({ "FieldMayBeFinal", "FieldCanBeLocal" })
 9 | public class GzipConfiguration {
10 |     @JsonProperty
11 |     protected boolean enabled = true;
12 | 
13 |     @JsonProperty
14 |     protected Size minimumEntitySize = null;
15 | 
16 |     @JsonProperty
17 |     protected Size bufferSize = null;
18 | 
19 |     @JsonProperty
20 |     protected ImmutableSet excludedUserAgents = null;
21 | 
22 |     @JsonProperty
23 |     protected ImmutableSet compressedMimeTypes = null;
24 | 
25 |     public boolean isEnabled() {
26 |         return enabled;
27 |     }
28 | 
29 |     public Optional getMinimumEntitySize() {
30 |         return Optional.fromNullable(minimumEntitySize);
31 |     }
32 | 
33 |     public Optional getBufferSize() {
34 |         return Optional.fromNullable(bufferSize);
35 |     }
36 | 
37 |     public Optional> getExcludedUserAgents() {
38 |         return Optional.fromNullable(excludedUserAgents);
39 |     }
40 | 
41 |     public Optional> getCompressedMimeTypes() {
42 |         return Optional.fromNullable(compressedMimeTypes);
43 |     }
44 | }
45 | 


--------------------------------------------------------------------------------
/docs/source/manual/scala.rst:
--------------------------------------------------------------------------------
 1 | .. _manual-scala:
 2 | 
 3 | ##################
 4 | Dropwizard & Scala
 5 | ##################
 6 | 
 7 | .. highlight:: text
 8 | 
 9 | .. rubric:: The ``dropwizard-scala`` module provides you with glue code required to write your
10 |             Dropwizard services in Scala_.
11 | 
12 | 
13 | .. _Scala: http://www.scala-lang.org
14 | 
15 | Dropwizard :ref:`services ` should extend ``ScalaService`` instead of ``Service``:
16 | 
17 | .. code-block:: scala
18 | 
19 |     object ExampleService extends ScalaService[ExampleConfiguration]("example") {
20 |       def initialize(configuration: ExampleConfiguration, environment: Environment) {
21 |         environment.addResource(new ExampleResource)
22 |       }
23 |     }
24 | 
25 | .. _man-scala-features:
26 | 
27 | Features
28 | ========
29 | 
30 | ``dropwizard-scala`` provides the following:
31 | 
32 | * ``QueryParam``-annotated parameters of type ``Seq[String]``, ``List[String]``, ``Vector[String]``,
33 |   ``IndexedSeq[String]``, ``Set[String]``, and ``Option[String]``.
34 | * ``AST.JValue`` request and response entities.
35 | * ``JsonNode`` request and response entities.
36 | * Case class (i.e., ``Product`` instances) JSON request and response entities.
37 | * ``Array[A]`` request and response entities. (Due to the JVM's type erasure and mismatches between
38 |   Scala and Java type signatures, this is the only "generic" class supported since ``Array`` type
39 |   parameters are reified.)
40 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/bundles/tests/JavaBundleTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.bundles.tests;
 2 | 
 3 | import com.google.common.collect.ImmutableList;
 4 | import com.yammer.dropwizard.Service;
 5 | import com.yammer.dropwizard.bundles.JavaBundle;
 6 | import com.yammer.dropwizard.config.Environment;
 7 | import com.yammer.dropwizard.jersey.JacksonMessageBodyProvider;
 8 | import com.yammer.dropwizard.jersey.OptionalQueryParamInjectableProvider;
 9 | import org.junit.Before;
10 | import org.junit.Test;
11 | 
12 | import static org.mockito.Matchers.isA;
13 | import static org.mockito.Mockito.*;
14 | 
15 | public class JavaBundleTest {
16 |     private final Environment environment = mock(Environment.class);
17 |     private final Service service = mock(Service.class);
18 |     private final JavaBundle bundle = new JavaBundle(service);
19 | 
20 |     @Before
21 |     public void setUp() throws Exception {
22 |         when(service.getJacksonModules()).thenReturn(ImmutableList.of());
23 |     }
24 | 
25 |     @Test
26 |     public void addsJSONSupport() throws Exception {
27 |         bundle.initialize(environment);
28 |         
29 |         verify(environment).addProvider(isA(JacksonMessageBodyProvider.class));
30 |     }
31 | 
32 |     @Test
33 |     public void addsOptionalQueryParamSupport() throws Exception {
34 |         bundle.initialize(environment);
35 | 
36 |         verify(environment).addProvider(isA(OptionalQueryParamInjectableProvider.class));
37 |     }
38 | }
39 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/validation/tests/MethodValidatorTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.validation.tests;
 2 | 
 3 | import com.google.common.collect.ImmutableList;
 4 | import com.yammer.dropwizard.validation.ValidationMethod;
 5 | import com.yammer.dropwizard.validation.Validator;
 6 | import org.junit.Test;
 7 | 
 8 | import javax.validation.Valid;
 9 | 
10 | import static org.hamcrest.Matchers.is;
11 | import static org.junit.Assert.assertThat;
12 | 
13 | @SuppressWarnings({"FieldMayBeFinal","MethodMayBeStatic","UnusedDeclaration"})
14 | public class MethodValidatorTest {
15 |     public static class SubExample {
16 |         @ValidationMethod(message = "also needs something special")
17 |         public boolean isOK() {
18 |             return false;
19 |         }
20 |     }
21 | 
22 |     public static class Example {
23 |         @Valid
24 |         private SubExample subExample = new SubExample();
25 | 
26 |         @ValidationMethod(message = "must have a false thing")
27 |         public boolean isFalse() {
28 |             return false;
29 |         }
30 | 
31 |         @ValidationMethod(message = "must have a true thing")
32 |         public boolean isTrue() {
33 |             return true;
34 |         }
35 |     }
36 | 
37 |     @Test
38 |     public void complainsAboutMethodsWhichReturnFalse() throws Exception {
39 |         assertThat(new Validator().validate(new Example()),
40 |                    is(ImmutableList.of("must have a false thing", "subExample also needs something special")));
41 |     }
42 | }
43 | 


--------------------------------------------------------------------------------
/dropwizard-example/src/main/java/com/example/helloworld/cli/SetupDatabaseCommand.java:
--------------------------------------------------------------------------------
 1 | package com.example.helloworld.cli;
 2 | 
 3 | import com.example.helloworld.HelloWorldConfiguration;
 4 | import com.example.helloworld.db.PeopleDAO;
 5 | import com.yammer.dropwizard.AbstractService;
 6 | import com.yammer.dropwizard.cli.ConfiguredCommand;
 7 | import com.yammer.dropwizard.config.Environment;
 8 | import com.yammer.dropwizard.db.Database;
 9 | import com.yammer.dropwizard.db.DatabaseFactory;
10 | import com.yammer.dropwizard.logging.Log;
11 | import org.apache.commons.cli.CommandLine;
12 | 
13 | public class SetupDatabaseCommand extends ConfiguredCommand {
14 | 
15 |     public SetupDatabaseCommand() {
16 |         super("setup", "Setup the database.");
17 |     }
18 | 
19 |     @Override
20 |     protected void run(AbstractService service, HelloWorldConfiguration configuration, CommandLine params) throws Exception {
21 | 
22 |         final Log log = Log.forClass(SetupDatabaseCommand.class);
23 |         final Environment environment = new Environment(configuration, service);
24 |         //service.initializeWithBundles(configuration, environment);
25 |         final DatabaseFactory factory = new DatabaseFactory(environment);
26 |         final Database db = factory.build(configuration.getDatabaseConfiguration(), "h2");
27 |         final PeopleDAO peopleDAO = db.onDemand(PeopleDAO.class);
28 | 
29 |         log.info("creating tables.");
30 |         peopleDAO.createPeopleTable();
31 | 
32 |     }
33 | }
34 | 


--------------------------------------------------------------------------------
/dropwizard-auth/pom.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |     4.0.0
 4 | 
 5 |     
 6 |         com.yammer.dropwizard
 7 |         dropwizard-parent
 8 |         0.4.1-SNAPSHOT
 9 |     
10 | 
11 |     dropwizard-auth
12 |     Dropwizard Authentication
13 | 
14 |     
15 |         
16 |             com.yammer.dropwizard
17 |             dropwizard-core
18 |             ${project.version}
19 |         
20 |         
21 |             junit
22 |             junit
23 |             4.10
24 |             test
25 |         
26 |         
27 |             org.mockito
28 |             mockito-all
29 |             1.9.0
30 |             test
31 |         
32 |         
33 |             org.hamcrest
34 |             hamcrest-all
35 |             1.1
36 |             test
37 |         
38 |     
39 | 
40 | 


--------------------------------------------------------------------------------
/docs/source/_themes/yammerdoc/less/alerts.less:
--------------------------------------------------------------------------------
 1 | // ALERT STYLES
 2 | // ------------
 3 | 
 4 | // Base alert styles
 5 | .alert {
 6 |   padding: 8px 35px 8px 14px;
 7 |   margin-bottom: @baseLineHeight;
 8 |   text-shadow: 0 1px 0 rgba(255,255,255,.5);
 9 |   background-color: @warningBackground;
10 |   border: 1px solid @warningBorder;
11 |   .border-radius(4px);
12 | }
13 | .alert,
14 | .alert-heading {
15 |   color: @warningText;
16 | }
17 | 
18 | // Adjust close link position
19 | .alert .close {
20 |   position: relative;
21 |   top: -2px;
22 |   right: -21px;
23 |   line-height: 18px;
24 | }
25 | 
26 | // Alternate styles
27 | // ----------------
28 | 
29 | .alert-success {
30 |   background-color: @successBackground;
31 |   border-color: @successBorder;  
32 | }
33 | .alert-success,
34 | .alert-success .alert-heading {
35 |   color: @successText;
36 | }
37 | .alert-danger,
38 | .alert-error {
39 |   background-color: @errorBackground;
40 |   border-color: @errorBorder;
41 | }
42 | .alert-danger,
43 | .alert-error,
44 | .alert-danger .alert-heading,
45 | .alert-error .alert-heading {
46 |   color: @errorText;
47 | }
48 | .alert-info {
49 |   background-color: @infoBackground;
50 |   border-color: @infoBorder;
51 | }
52 | .alert-info,
53 | .alert-info .alert-heading {
54 |   color: @infoText;
55 | }
56 | 
57 | 
58 | // Block alerts
59 | // ------------------------
60 | .alert-block {
61 |   padding-top: 14px;
62 |   padding-bottom: 14px;
63 | }
64 | .alert-block > p,
65 | .alert-block > ul {
66 |   margin-bottom: 0;
67 | }
68 | .alert-block p + p {
69 |   margin-top: 5px;
70 | }
71 | 


--------------------------------------------------------------------------------
/dropwizard-db/src/main/java/com/yammer/dropwizard/db/logging/LogbackLog.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.db.logging;
 2 | 
 3 | import ch.qos.logback.classic.Level;
 4 | import ch.qos.logback.classic.Logger;
 5 | import org.skife.jdbi.v2.DBI;
 6 | import org.skife.jdbi.v2.logging.FormattedLog;
 7 | import org.slf4j.LoggerFactory;
 8 | 
 9 | /**
10 |  * Logs SQL via Logback
11 |  */
12 | public class LogbackLog extends FormattedLog {
13 |     private final Logger log;
14 |     private Level level;
15 |     private String fqcn;
16 | 
17 |     /**
18 |      * Logs to org.skife.jdbi.v2 logger at the debug level
19 |      */
20 |     public LogbackLog()
21 |     {
22 |         this((Logger) LoggerFactory.getLogger(DBI.class.getPackage().getName()));
23 |     }
24 | 
25 |     /**
26 |      * Use an arbitrary logger to log to at the debug level
27 |      */
28 |     public LogbackLog(Logger log)
29 |     {
30 |         this(log, Level.DEBUG);
31 |     }
32 | 
33 |     /**
34 |      * Specify both the logger and the level to log at
35 |      * @param log The logger to log to
36 |      * @param level the priority to log at
37 |      */
38 |     public LogbackLog(Logger log, Level level) {
39 |         this.log = log;
40 |         this.level = level;
41 |         this.fqcn = LogbackLog.class.getName();
42 |     }
43 | 
44 |     @Override
45 |     protected final boolean isEnabled()
46 |     {
47 |         return log.isEnabledFor(level);
48 |     }
49 | 
50 |     @Override
51 |     protected final void log(String msg)
52 |     {
53 |         log.log(null, fqcn, level.toLocationAwareLoggerInteger(level), msg, null, null);
54 |     }
55 | }
56 | 


--------------------------------------------------------------------------------
/dropwizard-testing/src/main/java/com/yammer/dropwizard/testing/FixtureHelpers.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.testing;
 2 | 
 3 | import com.google.common.base.Charsets;
 4 | import com.google.common.io.Resources;
 5 | 
 6 | import java.io.IOException;
 7 | import java.nio.charset.Charset;
 8 | 
 9 | /**
10 |  * A set of helper method for fixture files.
11 |  */
12 | public class FixtureHelpers {
13 |     private FixtureHelpers() { /* singleton */ }
14 | 
15 |     /**
16 |      * Reads the given fixture file from {@code src/test/resources} and returns its contents as a
17 |      * UTF-8 string.
18 |      *
19 |      * @param filename    the filename of the fixture file
20 |      * @return the contents of {@code src/test/resources/{filename}}
21 |      * @throws IOException if {@code filename} doesn't exist or can't be opened
22 |      */
23 |     public static String fixture(String filename) throws IOException {
24 |         return fixture(filename, Charsets.UTF_8);
25 |     }
26 | 
27 |     /**
28 |      * Reads the given fixture file from {@code src/test/resources} and returns its contents as a
29 |      * string.
30 |      *
31 |      * @param filename    the filename of the fixture file
32 |      * @param charset     the character set of {@code filename}
33 |      * @return the contents of {@code src/test/resources/{filename}}
34 |      * @throws IOException if {@code filename} doesn't exist or can't be opened
35 |      */
36 |     private static String fixture(String filename, Charset charset) throws IOException {
37 |         return Resources.toString(Resources.getResource(filename), charset).trim();
38 |     }
39 | }
40 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/OptionalQueryParamInjectableProvider.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.jersey;
 2 | 
 3 | import com.google.common.base.Optional;
 4 | import com.sun.jersey.api.model.Parameter;
 5 | import com.sun.jersey.core.spi.component.ComponentContext;
 6 | import com.sun.jersey.core.spi.component.ComponentScope;
 7 | import com.sun.jersey.spi.inject.Injectable;
 8 | import com.sun.jersey.spi.inject.InjectableProvider;
 9 | 
10 | import javax.ws.rs.QueryParam;
11 | import javax.ws.rs.ext.Provider;
12 | 
13 | // TODO: 11/14/11  -- test OptionalQueryParamInjectableProvider
14 | // TODO: 11/14/11  -- document OptionalQueryParamInjectableProvider
15 | 
16 | @Provider
17 | public class OptionalQueryParamInjectableProvider implements InjectableProvider {
18 |     @Override
19 |     public ComponentScope getScope() {
20 |         return ComponentScope.PerRequest;
21 |     }
22 | 
23 |     @Override
24 |     public Injectable getInjectable(ComponentContext ic,
25 |                                        QueryParam a,
26 |                                        Parameter c) {
27 |         final String parameterName = c.getSourceName();
28 |         if ((parameterName != null) && !parameterName.isEmpty() &&
29 |                 c.getParameterClass().isAssignableFrom(Optional.class)) {
30 |             return new MultivaluedParameterExtractorQueryParamInjectable(
31 |                     new OptionalExtractor(parameterName, c.getDefaultValue()),
32 |                     !c.isEncoded()
33 |             );
34 |         }
35 |         return null;
36 |     }
37 | }
38 | 


--------------------------------------------------------------------------------
/dropwizard-testing/src/test/java/com/yammer/dropwizard/testing/tests/Person.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.testing.tests;
 2 | 
 3 | import com.google.common.base.Objects;
 4 | 
 5 | public class Person {
 6 |     private String name;
 7 |     private String email;
 8 | 
 9 |     private Person() { /* Jackson deserialization */ }
10 | 
11 |     public Person(String name, String email) {
12 |         this.name = name;
13 |         this.email = email;
14 |     }
15 | 
16 |     public String getName() {
17 |         return name;
18 |     }
19 | 
20 |     public void setName(String name) {
21 |         this.name = name;
22 |     }
23 | 
24 |     public String getEmail() {
25 |         return email;
26 |     }
27 | 
28 |     public void setEmail(String email) {
29 |         this.email = email;
30 |     }
31 | 
32 |     @Override
33 |     public boolean equals(Object obj) {
34 |         if (this == obj) { return true; }
35 |         if ((obj == null) || (getClass() != obj.getClass())) { return false; }
36 | 
37 |         final Person person = (Person) obj;
38 |         return !((email != null) ? !email.equals(person.email) : (person.email != null)) &&
39 |                 !((name != null) ? !name.equals(person.name) : (person.name != null));
40 |     }
41 | 
42 |     @Override
43 |     public int hashCode() {
44 |         int result = (name != null) ? name.hashCode() : 0;
45 |         result = (31 * result) + ((email != null) ? email.hashCode() : 0);
46 |         return result;
47 |     }
48 | 
49 |     @Override
50 |     public String toString() {
51 |         return Objects.toStringHelper(this).add("name", name).add("email", email).toString();
52 |     }
53 | }
54 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/servlets/tests/CacheBustingFilterTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.servlets.tests;
 2 | 
 3 | import com.yammer.dropwizard.servlets.CacheBustingFilter;
 4 | import org.junit.Test;
 5 | import org.mockito.InOrder;
 6 | 
 7 | import javax.servlet.FilterChain;
 8 | import javax.servlet.ServletRequest;
 9 | import javax.servlet.ServletResponse;
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 | 
13 | import static org.mockito.Mockito.*;
14 | 
15 | public class CacheBustingFilterTest {
16 |     private final HttpServletRequest request = mock(HttpServletRequest.class);
17 |     private final HttpServletResponse response = mock(HttpServletResponse.class);
18 |     private final FilterChain chain = mock(FilterChain.class);
19 |     private final CacheBustingFilter filter = new CacheBustingFilter();
20 | 
21 |     @Test
22 |     public void passesThroughNonHttpRequests() throws Exception {
23 |         final ServletRequest req = mock(ServletRequest.class);
24 |         final ServletResponse res = mock(ServletResponse.class);
25 | 
26 |         filter.doFilter(req, res, chain);
27 | 
28 |         verify(chain).doFilter(req, res);
29 |         verifyZeroInteractions(res);
30 |     }
31 | 
32 |     @Test
33 |     public void setsACacheHeaderOnTheResponse() throws Exception {
34 |         filter.doFilter(request, response, chain);
35 | 
36 |         final InOrder inOrder = inOrder(response, chain);
37 |         inOrder.verify(response).setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
38 |         inOrder.verify(chain).doFilter(request, response);
39 |     }
40 | }
41 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/tests/ServiceTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.tests;
 2 | 
 3 | import com.yammer.dropwizard.Bundle;
 4 | import com.yammer.dropwizard.Service;
 5 | import com.yammer.dropwizard.config.Configuration;
 6 | import com.yammer.dropwizard.config.Environment;
 7 | import org.junit.Test;
 8 | 
 9 | import static org.hamcrest.Matchers.*;
10 | import static org.junit.Assert.assertThat;
11 | import static org.mockito.Mockito.mock;
12 | 
13 | public class ServiceTest {
14 |     @SuppressWarnings({"PackageVisibleInnerClass", "EmptyClass"})
15 |     static class FakeConfiguration extends Configuration {
16 | 
17 |     }
18 | 
19 |     private class FakeService extends Service {
20 |         FakeService() {
21 |             super("test");
22 |             addBundle(bundle);
23 |         }
24 | 
25 |         @Override
26 |         protected void initialize(FakeConfiguration configuration,
27 |                                   Environment environment) {
28 |         }
29 |     }
30 | 
31 |     private class PoserService extends FakeService { }
32 |     
33 |     private final Bundle bundle = mock(Bundle.class);
34 |     private final FakeService service = new FakeService();
35 | 
36 |     @Test
37 |     public void hasAReferenceToItsTypeParameter() throws Exception {
38 |         assertThat(service.getConfigurationClass(),
39 |                    is(sameInstance(FakeConfiguration.class)));
40 |     }
41 | 
42 |     @Test
43 |     public void canDetermineConfiguration() throws Exception {
44 |         assertThat(new PoserService().getConfigurationClass(),
45 |                 is(sameInstance(FakeConfiguration.class)));
46 |     }
47 | }
48 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/MultivaluedParameterExtractorQueryParamInjectable.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.jersey;
 2 | 
 3 | import com.sun.jersey.api.ParamException;
 4 | import com.sun.jersey.api.core.HttpContext;
 5 | import com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable;
 6 | import com.sun.jersey.server.impl.model.parameter.multivalued.ExtractorContainerException;
 7 | import com.sun.jersey.server.impl.model.parameter.multivalued.MultivaluedParameterExtractor;
 8 | 
 9 | // TODO: 11/14/11  -- test MultivaluedParameterExtractorQueryParamInjectable
10 | // TODO: 11/14/11  -- document MultivaluedParameterExtractorQueryParamInjectable
11 | 
12 | public class MultivaluedParameterExtractorQueryParamInjectable extends AbstractHttpContextInjectable {
13 |     private final MultivaluedParameterExtractor extractor;
14 |     private final boolean decode;
15 | 
16 |     public MultivaluedParameterExtractorQueryParamInjectable(MultivaluedParameterExtractor extractor,
17 |                                                              boolean decode) {
18 |         this.extractor = extractor;
19 |         this.decode = decode;
20 |     }
21 | 
22 |     @Override
23 |     public Object getValue(HttpContext c) {
24 |         try {
25 |             return extractor.extract(c.getUriInfo().getQueryParameters(decode));
26 |         } catch (ExtractorContainerException e) {
27 |             throw new ParamException.QueryParamException(e.getCause(),
28 |                                                          extractor.getName(),
29 |                                                          extractor.getDefaultStringValue());
30 |         }
31 |     }
32 | }
33 | 


--------------------------------------------------------------------------------
/dropwizard-testing/pom.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |     4.0.0
 4 | 
 5 |     
 6 |         com.yammer.dropwizard
 7 |         dropwizard-parent
 8 |         0.4.1-SNAPSHOT
 9 |     
10 | 
11 |     dropwizard-testing
12 |     Dropwizard Test Helpers
13 | 
14 |     
15 |         
16 |             com.yammer.dropwizard
17 |             dropwizard-core
18 |             ${project.version}
19 |         
20 |         
21 |             com.sun.jersey.jersey-test-framework
22 |             jersey-test-framework-inmemory
23 |             ${jersey.version}
24 |         
25 |         
26 |             junit
27 |             junit
28 |             4.10
29 |         
30 |         
31 |             org.mockito
32 |             mockito-all
33 |             1.9.0
34 |         
35 |         
36 |             org.hamcrest
37 |             hamcrest-all
38 |             1.1
39 |         
40 |     
41 | 
42 | 


--------------------------------------------------------------------------------
/dropwizard-auth/src/main/java/com/yammer/dropwizard/auth/oauth/OAuthProvider.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.auth.oauth;
 2 | 
 3 | import com.sun.jersey.api.model.Parameter;
 4 | import com.sun.jersey.core.spi.component.ComponentContext;
 5 | import com.sun.jersey.core.spi.component.ComponentScope;
 6 | import com.sun.jersey.spi.inject.Injectable;
 7 | import com.sun.jersey.spi.inject.InjectableProvider;
 8 | import com.yammer.dropwizard.auth.Auth;
 9 | import com.yammer.dropwizard.auth.Authenticator;
10 | 
11 | /**
12 |  * A Jersey providers for OAuth2 bearer tokens.
13 |  *
14 |  * @param  the principal type
15 |  */
16 | public class OAuthProvider implements InjectableProvider {
17 |     private final Authenticator authenticator;
18 |     private final String realm;
19 | 
20 |     /**
21 |      * Creates a new {@link OAuthProvider} with the given {@link Authenticator} and realm.
22 |      *
23 |      * @param authenticator    the authenticator which will take the OAuth2 bearer token and convert
24 |      *                         them into instances of {@code T}
25 |      * @param realm            the name of the authentication realm
26 |      */
27 |     public OAuthProvider(Authenticator authenticator, String realm) {
28 |         this.authenticator = authenticator;
29 |         this.realm = realm;
30 |     }
31 | 
32 |     @Override
33 |     public ComponentScope getScope() {
34 |         return ComponentScope.PerRequest;
35 |     }
36 | 
37 |     @Override
38 |     public Injectable getInjectable(ComponentContext ic,
39 |                                        Auth a,
40 |                                        Parameter c) {
41 |         return new OAuthInjectable(authenticator, realm, a.required());
42 |     }
43 | }
44 | 


--------------------------------------------------------------------------------
/docs/source/_themes/yammerdoc/less/bootstrap.less:
--------------------------------------------------------------------------------
 1 | /*!
 2 |  * Bootstrap v2.0.0
 3 |  *
 4 |  * Copyright 2012 Twitter, Inc
 5 |  * Licensed under the Apache License v2.0
 6 |  * http://www.apache.org/licenses/LICENSE-2.0
 7 |  *
 8 |  * Designed and built with all the love in the world @twitter by @mdo and @fat.
 9 |  */
10 | 
11 | // CSS Reset
12 | @import "reset.less";
13 | 
14 | // Core variables and mixins
15 | @import "variables.less"; // Modify this for custom colors, font-sizes, etc
16 | @import "mixins.less";
17 | 
18 | // Grid system and page structure
19 | @import "scaffolding.less";
20 | @import "grid.less";
21 | @import "layouts.less";
22 | 
23 | // Base CSS
24 | @import "type.less";
25 | @import "code.less";
26 | @import "forms.less";
27 | @import "tables.less";
28 | 
29 | // Components: common
30 | @import "sprites.less";
31 | @import "dropdowns.less";
32 | @import "wells.less";
33 | @import "component-animations.less";
34 | @import "close.less";
35 | 
36 | // Components: Buttons & Alerts
37 | @import "buttons.less";
38 | @import "button-groups.less";
39 | @import "alerts.less"; // Note: alerts share common CSS with buttons and thus have styles in buttons.less
40 | 
41 | // Components: Nav
42 | @import "navs.less";
43 | @import "navbar.less";
44 | @import "breadcrumbs.less";
45 | @import "pagination.less";
46 | @import "pager.less";
47 | 
48 | // Components: Popovers
49 | @import "modals.less";
50 | @import "tooltip.less";
51 | @import "popovers.less";
52 | 
53 | // Components: Misc
54 | @import "thumbnails.less";
55 | @import "labels.less";
56 | @import "progress-bars.less";
57 | @import "accordion.less";
58 | @import "carousel.less";
59 | @import "hero-unit.less";
60 | 
61 | // Utility classes
62 | @import "utilities.less"; // Has to be last to override when necessary
63 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/servlets/ThreadNameFilter.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.servlets;
 2 | 
 3 | import javax.servlet.*;
 4 | import javax.servlet.http.HttpServletRequest;
 5 | import java.io.IOException;
 6 | 
 7 | import static com.yammer.dropwizard.util.Servlets.getFullUrl;
 8 | 
 9 | /**
10 |  * A servlet filter which adds the request method and URI to the thread name processing the request
11 |  * for the duration of the request.
12 |  */
13 | public class ThreadNameFilter implements Filter {
14 |     @Override
15 |     public void init(FilterConfig filterConfig) throws ServletException { /* unused */ }
16 | 
17 |     @Override
18 |     public void destroy() { /* unused */ }
19 | 
20 |     @Override
21 |     public void doFilter(ServletRequest request,
22 |                          ServletResponse response,
23 |                          FilterChain chain) throws IOException, ServletException {
24 |         final HttpServletRequest req = (HttpServletRequest) request;
25 |         final Thread current = Thread.currentThread();
26 |         final String oldName = current.getName();
27 |         try {
28 |             current.setName(formatName(req, oldName));
29 |             chain.doFilter(request, response);
30 |         } finally {
31 |             current.setName(oldName);
32 |         }
33 |     }
34 | 
35 |     private static String formatName(HttpServletRequest req, String oldName) {
36 |         return new StringBuilder(150).append(oldName)
37 |                                      .append(" - ")
38 |                                      .append(req.getMethod())
39 |                                      .append(' ')
40 |                                      .append(getFullUrl(req))
41 |                                      .toString();
42 |     }
43 | }
44 | 


--------------------------------------------------------------------------------
/dropwizard-example/README.md:
--------------------------------------------------------------------------------
 1 | # Introduction
 2 | 
 3 | The drop wizard example application was developed to, as its name implies, provide examples of some of the features
 4 | present in drop wizard.
 5 | 
 6 | # Overview
 7 | 
 8 | Included with this application is an example of the optional db API module. The examples provided illustrate a few of
 9 | the features available in (JDBI)[http://jdbi.org], along with demonstrating how these are used from within dropwizard.
10 | 
11 | This database example is comprised of the following classes.
12 | 
13 | * The `PersonDAO` illustrates using the [SQL Object Queries](http://jdbi.org/sql_object_api_queries/) and string template
14 | features in JDBI.
15 | 
16 | * The `PeopleDAO.sql.stg` stores all the SQL statements for use in the `PersonDAO`, note this is located in the
17 | src/resources under the same path as the `PersonDAO` class file.
18 | 
19 | * The `SetupDatabaseCommand` illustrates building a "setup" command which can create your database prior to running
20 | dropwizard your application for the first time.
21 | 
22 | * The `PersonResource` and `PeopleResource` are the REST resource which use the PersonDAO to retrieve data from the database, note the injection
23 | of the PersonDAO in their constructors.
24 | 
25 | As with all the modules the db example is wired up in the `initialize` function of the `HelloWorldService`.
26 | 
27 | # Running The Application
28 | 
29 | To test the example application run the following commands.
30 | 
31 | * To package the example run.
32 | 
33 |         mvn package
34 | 
35 | * To setup the h2 database run.
36 | 
37 |         java -jar target/dropwizard-example-0.3.0-SNAPSHOT.jar setup example.yml
38 | 
39 | * To run the server run.
40 | 
41 |         java -jar target/dropwizard-example-0.3.0-SNAPSHOT.jar server example.yml
42 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/jetty/NonblockingServletHolder.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.jetty;
 2 | 
 3 | import org.eclipse.jetty.server.Request;
 4 | import org.eclipse.jetty.servlet.ServletHolder;
 5 | 
 6 | import javax.servlet.*;
 7 | import java.io.IOException;
 8 | 
 9 | /**
10 |  * A {@link ServletHolder} subclass which removes the synchronization around servlet initialization
11 |  * by requiring a pre-initialized servlet holder.
12 |  */
13 | public class NonblockingServletHolder extends ServletHolder {
14 |     private final Servlet servlet;
15 | 
16 |     public NonblockingServletHolder(Servlet servlet) {
17 |         super(servlet);
18 |         this.servlet = servlet;
19 |     }
20 | 
21 |     @Override
22 |     public boolean equals(Object o) {
23 |         return (o instanceof NonblockingServletHolder) && (this.compareTo(o) == 0);
24 |     }
25 | 
26 |     @Override
27 |     public int hashCode() {
28 |         int result = super.hashCode();
29 |         result = (31 * result) + ((servlet != null) ? servlet.hashCode() : 0);
30 |         return result;
31 |     }
32 | 
33 |     @Override
34 |     public Servlet getServlet() throws ServletException {
35 |         return servlet;
36 |     }
37 | 
38 |     @Override
39 |     public void handle(Request baseRequest,
40 |                        ServletRequest request,
41 |                        ServletResponse response) throws ServletException, IOException {
42 |         final boolean asyncSupported = baseRequest.isAsyncSupported();
43 |         if (!isAsyncSupported()) {
44 |             baseRequest.setAsyncSupported(false);
45 |         }
46 |         try {
47 |             servlet.service(request, response);
48 |         } finally {
49 |             baseRequest.setAsyncSupported(asyncSupported);
50 |         }
51 |     }
52 | }
53 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/validation/tests/ValidatorTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.validation.tests;
 2 | 
 3 | import com.google.common.collect.ImmutableList;
 4 | import com.yammer.dropwizard.validation.Validator;
 5 | import org.junit.Test;
 6 | 
 7 | import javax.validation.constraints.Max;
 8 | import javax.validation.constraints.NotNull;
 9 | 
10 | import java.util.Locale;
11 | 
12 | import static org.hamcrest.Matchers.is;
13 | import static org.junit.Assert.assertThat;
14 | 
15 | public class ValidatorTest {
16 |     @SuppressWarnings("unused")
17 |     public static class Example {
18 |         @NotNull
19 |         private String notNull = null;
20 | 
21 |         @Max(30)
22 |         private int tooBig = 50;
23 | 
24 |         public void setNotNull(String notNull) {
25 |             this.notNull = notNull;
26 |         }
27 | 
28 |         public void setTooBig(int tooBig) {
29 |             this.tooBig = tooBig;
30 |         }
31 |     }
32 | 
33 |     private final Validator validator = new Validator();
34 | 
35 |     @Test
36 |     public void returnsASetOfErrorsForAnObject() throws Exception {
37 |         if ("en".equals(Locale.getDefault().getLanguage())) {
38 |             assertThat(validator.validate(new Example()),
39 |                        is(ImmutableList.of("notNull may not be null (was null)",
40 |                                            "tooBig must be less than or equal to 30 (was 50)")));
41 |         }
42 |     }
43 | 
44 |     @Test
45 |     public void returnsAnEmptySetForAValidObject() throws Exception {
46 |         final Example example = new Example();
47 |         example.setNotNull("woo");
48 |         example.setTooBig(20);
49 | 
50 |         assertThat(validator.validate(example),
51 |                    is(ImmutableList.of()));
52 |     }
53 | }
54 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/test/java/com/yammer/dropwizard/jetty/tests/NonblockingServletHolderTest.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.jetty.tests;
 2 | 
 3 | import com.yammer.dropwizard.jetty.NonblockingServletHolder;
 4 | import org.eclipse.jetty.server.Request;
 5 | import org.junit.Test;
 6 | import org.mockito.InOrder;
 7 | 
 8 | import javax.servlet.Servlet;
 9 | import javax.servlet.ServletRequest;
10 | import javax.servlet.ServletResponse;
11 | 
12 | import static org.hamcrest.Matchers.is;
13 | import static org.junit.Assert.assertThat;
14 | import static org.mockito.Mockito.inOrder;
15 | import static org.mockito.Mockito.mock;
16 | import static org.mockito.Mockito.verify;
17 | 
18 | public class NonblockingServletHolderTest {
19 |     private final Servlet servlet = mock(Servlet.class);
20 |     private final NonblockingServletHolder holder = new NonblockingServletHolder(servlet);
21 |     private final Request baseRequest = mock(Request.class);
22 |     private final ServletRequest request = mock(ServletRequest.class);
23 |     private final ServletResponse response = mock(ServletResponse.class);
24 | 
25 |     @Test
26 |     public void hasAServlet() throws Exception {
27 |         assertThat(holder.getServlet(),
28 |                    is(servlet));
29 |     }
30 | 
31 |     @Test
32 |     public void servicesRequests() throws Exception {
33 |         holder.handle(baseRequest, request, response);
34 | 
35 |         verify(servlet).service(request, response);
36 |     }
37 | 
38 |     @Test
39 |     public void temporarilyDisablesAsyncRequestsIfDisabled() throws Exception {
40 |         holder.setAsyncSupported(false);
41 | 
42 |         holder.handle(baseRequest, request, response);
43 | 
44 |         final InOrder inOrder = inOrder(baseRequest, servlet);
45 | 
46 |         inOrder.verify(baseRequest).setAsyncSupported(false);
47 |         inOrder.verify(servlet).service(request, response);
48 |     }
49 | }
50 | 


--------------------------------------------------------------------------------
/docs/source/_themes/yammerdoc/less/modals.less:
--------------------------------------------------------------------------------
 1 | // MODALS
 2 | // ------
 3 | 
 4 | .modal-open {
 5 |   .dropdown-menu {  z-index: @zindexDropdown + @zindexModal; }
 6 |   .dropdown.open { *z-index: @zindexDropdown + @zindexModal; }
 7 |   .popover       {  z-index: @zindexPopover  + @zindexModal; }
 8 |   .tooltip       {  z-index: @zindexTooltip  + @zindexModal; }
 9 | }
10 | 
11 | .modal-backdrop {
12 |   position: fixed;
13 |   top: 0;
14 |   right: 0;
15 |   bottom: 0;
16 |   left: 0;
17 |   z-index: @zindexModalBackdrop;
18 |   background-color: @black;
19 |   // Fade for backdrop
20 |   &.fade { opacity: 0; }
21 | }
22 | 
23 | .modal-backdrop,
24 | .modal-backdrop.fade.in {
25 |   .opacity(80);
26 | }
27 | 
28 | .modal {
29 |   position: fixed;
30 |   top: 50%;
31 |   left: 50%;
32 |   z-index: @zindexModal;
33 |   max-height: 500px;
34 |   overflow: auto;
35 |   width: 560px;
36 |   margin: -250px 0 0 -280px;
37 |   background-color: @white;
38 |   border: 1px solid #999;
39 |   border: 1px solid rgba(0,0,0,.3);
40 |   *border: 1px solid #999; /* IE6-7 */
41 |   .border-radius(6px);
42 |   .box-shadow(0 3px 7px rgba(0,0,0,0.3));
43 |   .background-clip(padding-box);
44 |   &.fade {
45 |     .transition(e('opacity .3s linear, top .3s ease-out'));
46 |     top: -25%;
47 |   }
48 |   &.fade.in { top: 50%; }
49 | }
50 | .modal-header {
51 |   padding: 9px 15px;
52 |   border-bottom: 1px solid #eee;
53 |   // Close icon
54 |   .close { margin-top: 2px; }
55 | }
56 | .modal-body {
57 |   padding: 15px;
58 | }
59 | .modal-footer {
60 |   padding: 14px 15px 15px;
61 |   margin-bottom: 0;
62 |   background-color: #f5f5f5;
63 |   border-top: 1px solid #ddd;
64 |   .border-radius(0 0 6px 6px);
65 |   .box-shadow(inset 0 1px 0 @white);
66 |   .clearfix();
67 |   .btn {
68 |     float: right;
69 |     margin-left: 5px;
70 |     margin-bottom: 0; // account for input[type="submit"] which gets the bottom margin like all other inputs
71 |   }
72 | }
73 | 


--------------------------------------------------------------------------------
/dropwizard-views/pom.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |     4.0.0
 4 | 
 5 |     
 6 |         com.yammer.dropwizard
 7 |         dropwizard-parent
 8 |         0.4.1-SNAPSHOT
 9 |     
10 | 
11 |     dropwizard-views
12 |     Dropwizard Views
13 |     
14 |     
15 |         
16 |             com.yammer.dropwizard
17 |             dropwizard-core
18 |             ${project.version}
19 |         
20 |         
21 |             com.sun.jersey.contribs
22 |             jersey-freemarker
23 |             1.12
24 |         
25 |         
26 |             org.freemarker
27 |             freemarker
28 |             2.3.19
29 |         
30 |         
31 |             junit
32 |             junit
33 |             4.10
34 |             test
35 |         
36 |         
37 |             org.hamcrest
38 |             hamcrest-all
39 |             1.1
40 |             test
41 |         
42 |         
43 |             org.mockito
44 |             mockito-all
45 |             1.9.0
46 |         
47 |     
48 | 
49 | 


--------------------------------------------------------------------------------
/dropwizard-auth/src/main/java/com/yammer/dropwizard/auth/basic/BasicAuthProvider.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.auth.basic;
 2 | 
 3 | import com.sun.jersey.api.model.Parameter;
 4 | import com.sun.jersey.core.spi.component.ComponentContext;
 5 | import com.sun.jersey.core.spi.component.ComponentScope;
 6 | import com.sun.jersey.spi.inject.Injectable;
 7 | import com.sun.jersey.spi.inject.InjectableProvider;
 8 | import com.yammer.dropwizard.auth.Auth;
 9 | import com.yammer.dropwizard.auth.Authenticator;
10 | import com.yammer.dropwizard.logging.Log;
11 | 
12 | /**
13 |  * A Jersey provider for Basic HTTP authentication.
14 |  *
15 |  * @param     the principal type.
16 |  */
17 | public class BasicAuthProvider implements InjectableProvider {
18 |     static final Log LOG = Log.forClass(BasicAuthProvider.class);
19 | 
20 |     private final Authenticator authenticator;
21 |     private final String realm;
22 | 
23 |     /**
24 |      * Creates a new {@link BasicAuthProvider} with the given {@link Authenticator} and realm.
25 |      *
26 |      * @param authenticator    the authenticator which will take the {@link BasicCredentials} and
27 |      *                         convert them into instances of {@code T}
28 |      * @param realm            the name of the authentication realm
29 |      */
30 |     public BasicAuthProvider(Authenticator authenticator, String realm) {
31 |         this.authenticator = authenticator;
32 |         this.realm = realm;
33 |     }
34 | 
35 |     @Override
36 |     public ComponentScope getScope() {
37 |         return ComponentScope.PerRequest;
38 |     }
39 | 
40 |     @Override
41 |     public Injectable getInjectable(ComponentContext ic,
42 |                                        Auth a,
43 |                                        Parameter c) {
44 |         return new BasicAuthInjectable(authenticator, realm, a.required());
45 |     }
46 | }
47 | 


--------------------------------------------------------------------------------
/dropwizard-core/src/main/java/com/yammer/dropwizard/tasks/GarbageCollectionTask.java:
--------------------------------------------------------------------------------
 1 | package com.yammer.dropwizard.tasks;
 2 | 
 3 | import com.google.common.collect.ImmutableList;
 4 | import com.google.common.collect.ImmutableMultimap;
 5 | 
 6 | import java.io.PrintWriter;
 7 | 
 8 | /**
 9 |  * Performs a full JVM garbage collection (probably).
10 |  */
11 | public class GarbageCollectionTask extends Task {
12 |     private final Runtime runtime;
13 | 
14 |     /**
15 |      * Creates a new {@link GarbageCollectionTask}.
16 |      */
17 |     public GarbageCollectionTask() {
18 |         this(Runtime.getRuntime());
19 |     }
20 | 
21 |     /**
22 |      * Creates a new {@link GarbageCollectionTask} with the given {@link Runtime} instance.
23 |      * 

24 | * Use {@link GarbageCollectionTask#GarbageCollectionTask()} instead. 25 | * 26 | * @param runtime a {@link Runtime} instance 27 | */ 28 | public GarbageCollectionTask(Runtime runtime) { 29 | super("gc"); 30 | this.runtime = runtime; 31 | } 32 | 33 | @Override 34 | @SuppressWarnings("CallToSystemGC") 35 | public void execute(ImmutableMultimap parameters, PrintWriter output) { 36 | final int count = parseRuns(parameters); 37 | for (int i = 0; i < count; i++) { 38 | output.println("Running GC..."); 39 | output.flush(); 40 | runtime.gc(); 41 | } 42 | 43 | output.println("Done!"); 44 | } 45 | 46 | private static int parseRuns(ImmutableMultimap parameters) { 47 | final ImmutableList runs = parameters.get("runs").asList(); 48 | if (runs.isEmpty()) { 49 | return 1; 50 | } else { 51 | try { 52 | return Integer.parseInt(runs.get(0)); 53 | } catch (NumberFormatException ignored) { 54 | return 1; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /dropwizard-example/src/main/java/com/example/helloworld/cli/RenderCommand.java: -------------------------------------------------------------------------------- 1 | package com.example.helloworld.cli; 2 | 3 | import com.example.helloworld.HelloWorldConfiguration; 4 | import com.example.helloworld.core.Template; 5 | import com.google.common.base.Optional; 6 | import com.yammer.dropwizard.AbstractService; 7 | import com.yammer.dropwizard.cli.ConfiguredCommand; 8 | import com.yammer.dropwizard.logging.Log; 9 | import org.apache.commons.cli.CommandLine; 10 | import org.apache.commons.cli.Options; 11 | 12 | public class RenderCommand extends ConfiguredCommand { 13 | private static final Log LOG = Log.forClass(RenderCommand.class); 14 | 15 | public RenderCommand() { 16 | super("render", "Renders the configured template to the console."); 17 | } 18 | 19 | @Override 20 | protected String getConfiguredSyntax() { 21 | return "[name1 name2]"; 22 | } 23 | 24 | @Override 25 | public Options getOptions() { 26 | final Options options = new Options(); 27 | options.addOption("i", "include-default", false, 28 | "Also render the template with the default name"); 29 | return options; 30 | } 31 | 32 | @Override 33 | protected void run(AbstractService service, 34 | HelloWorldConfiguration configuration, 35 | CommandLine params) throws Exception { 36 | final Template template = configuration.buildTemplate(); 37 | 38 | if (params.hasOption("include-default")) { 39 | LOG.info("DEFAULT => {}", template.render(Optional.absent())); 40 | } 41 | 42 | for (String name : params.getArgs()) { 43 | for (int i = 0; i < 1000; i++) { 44 | LOG.info("{} => {}", name, template.render(Optional.of(name))); 45 | Thread.sleep(1000); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/logging/LoggingBean.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.logging; 2 | 3 | // TODO: 10/12/11 -- test LoggingBean 4 | // TODO: 10/12/11 -- document LoggingBean 5 | 6 | import ch.qos.logback.classic.Level; 7 | import ch.qos.logback.classic.Logger; 8 | import com.google.common.collect.Lists; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.Collections; 12 | import java.util.Enumeration; 13 | import java.util.List; 14 | import java.util.logging.LogManager; 15 | import java.util.logging.LoggingMXBean; 16 | 17 | public class LoggingBean implements LoggingMXBean { 18 | @Override 19 | public String getLoggerLevel(String loggerName) { 20 | return Log.named(loggerName).getLevel().toString(); 21 | } 22 | 23 | @Override 24 | public List getLoggerNames() { 25 | final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); 26 | 27 | final List names = Lists.newArrayList(); 28 | for (Logger logger : root.getLoggerContext().getLoggerList()) { 29 | names.add(logger.getName()); 30 | } 31 | 32 | final Enumeration moreNames = LogManager.getLogManager() 33 | .getLoggerNames(); 34 | while (moreNames.hasMoreElements()) { 35 | final String name = moreNames.nextElement(); 36 | names.add(name); 37 | } 38 | 39 | Collections.sort(names); 40 | return names; 41 | } 42 | 43 | @Override 44 | public void setLoggerLevel(String loggerName, String levelName) { 45 | final Level newLevel = Level.toLevel(levelName, Level.INFO); 46 | Log.named(loggerName).setLevel(newLevel); 47 | } 48 | 49 | @Override 50 | public String getParentLoggerName(String loggerName) { 51 | throw new UnsupportedOperationException("Can't determine parents."); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/LoggingExceptionMapper.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey; 2 | 3 | import com.yammer.dropwizard.logging.Log; 4 | 5 | import javax.ws.rs.WebApplicationException; 6 | import javax.ws.rs.core.MediaType; 7 | import javax.ws.rs.core.Response; 8 | import javax.ws.rs.ext.ExceptionMapper; 9 | import javax.ws.rs.ext.Provider; 10 | import java.util.Random; 11 | 12 | // TODO: 10/12/11 -- write tests for LoggingExceptionMapper 13 | // TODO: 10/12/11 -- write docs for LoggingExceptionMapper 14 | 15 | @Provider 16 | public class LoggingExceptionMapper implements ExceptionMapper { 17 | private static final Log LOG = Log.forClass(LoggingExceptionMapper.class); 18 | private static final Random RANDOM = new Random(); 19 | 20 | @Override 21 | public Response toResponse(E exception) { 22 | if (exception instanceof WebApplicationException) { 23 | return ((WebApplicationException) exception).getResponse(); 24 | } 25 | final long id = randomId(); 26 | logException(id, exception); 27 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR) 28 | .type(MediaType.TEXT_PLAIN_TYPE) 29 | .entity(formatResponseEntity(id, exception)) 30 | .build(); 31 | } 32 | 33 | protected void logException(long id, E exception) { 34 | LOG.error(exception, formatLogMessage(id, exception)); 35 | } 36 | 37 | protected String formatResponseEntity(long id, Throwable exception) { 38 | return String.format("There was an error processing your request. It has been logged (ID %016x).\n", id); 39 | } 40 | 41 | protected String formatLogMessage(long id, Throwable exception) { 42 | return String.format("Error handling a request: %016x", id); 43 | } 44 | 45 | protected static long randomId() { 46 | return RANDOM.nextLong(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests/GzipConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config.tests; 2 | 3 | import com.google.common.base.Optional; 4 | import com.google.common.collect.ImmutableSet; 5 | import com.google.common.io.Resources; 6 | import com.yammer.dropwizard.config.ConfigurationFactory; 7 | import com.yammer.dropwizard.config.GzipConfiguration; 8 | import com.yammer.dropwizard.util.Size; 9 | import com.yammer.dropwizard.validation.Validator; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | 13 | import java.io.File; 14 | 15 | import static org.hamcrest.Matchers.*; 16 | import static org.junit.Assert.*; 17 | 18 | public class GzipConfigurationTest { 19 | private GzipConfiguration gzip; 20 | 21 | @Before 22 | public void setUp() throws Exception { 23 | this.gzip = ConfigurationFactory.forClass(GzipConfiguration.class, 24 | new Validator()).build(new File(Resources.getResource("yaml/gzip.yml").getFile())); 25 | } 26 | 27 | @Test 28 | public void canBeEnabled() throws Exception { 29 | assertThat(gzip.isEnabled(), 30 | is(false)); 31 | } 32 | 33 | @Test 34 | public void hasAMinimumEntitySize() throws Exception { 35 | assertThat(gzip.getMinimumEntitySize(), 36 | is(Optional.of(Size.kilobytes(12)))); 37 | } 38 | 39 | @Test 40 | public void hasABufferSize() throws Exception { 41 | assertThat(gzip.getBufferSize(), 42 | is(Optional.of(Size.kilobytes(32)))); 43 | } 44 | 45 | @Test 46 | public void hasExcludedUserAgents() throws Exception { 47 | assertThat(gzip.getExcludedUserAgents(), 48 | is(Optional.of(ImmutableSet.of("IE")))); 49 | } 50 | 51 | @Test 52 | public void hasCompressedMimeTypes() throws Exception { 53 | assertThat(gzip.getCompressedMimeTypes(), 54 | is(Optional.of(ImmutableSet.of("text/plain")))); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/search.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/search.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the search page. 6 | 7 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {% extends "layout.html" %} 11 | {% set title = _('Search') %} 12 | {% set script_files = script_files + ['_static/searchtools.js'] %} 13 | {% block extrahead %} 14 | 17 | {{ super() }} 18 | {% endblock %} 19 | {% block body %} 20 |

{{ _('Search') }}

21 |
22 | 23 |

24 | {% trans %}Please activate JavaScript to enable the search 25 | functionality.{% endtrans %} 26 |

27 |
28 |

29 | {% trans %}From here you can search these documents. Enter your search 30 | words into the box below and click "search". Note that the search 31 | function will automatically search for all of the words. Pages 32 | containing fewer words won't appear in the result list.{% endtrans %} 33 |

34 |
35 | 36 | 37 | 38 |
39 | {% if search_performed %} 40 |

{{ _('Search Results') }}

41 | {% if not search_results %} 42 |

{{ _('Your search did not match any results.') }}

43 | {% endif %} 44 | {% endif %} 45 |
46 | {% if search_results %} 47 |
    48 | {% for href, caption, context in search_results %} 49 |
  • {{ caption }} 50 |
    {{ context|e }}
    51 |
  • 52 | {% endfor %} 53 |
54 | {% endif %} 55 |
56 | {% endblock %} 57 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests/FilterConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config.tests; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import com.google.common.collect.ImmutableMultimap; 5 | import com.yammer.dropwizard.config.FilterConfiguration; 6 | import org.eclipse.jetty.servlet.FilterHolder; 7 | import org.junit.Test; 8 | 9 | import static org.hamcrest.Matchers.is; 10 | import static org.junit.Assert.assertThat; 11 | import static org.mockito.Mockito.mock; 12 | import static org.mockito.Mockito.verify; 13 | import static org.mockito.Mockito.verifyNoMoreInteractions; 14 | 15 | public class FilterConfigurationTest { 16 | private final FilterHolder holder = mock(FilterHolder.class); 17 | private final ImmutableMultimap.Builder mappings = ImmutableMultimap.builder(); 18 | private final FilterConfiguration config = new FilterConfiguration(holder, mappings); 19 | 20 | @Test 21 | public void setsInitializationParameters() throws Exception { 22 | config.setInitParam("one", "1"); 23 | 24 | verify(holder).setInitParameter("one", "1"); 25 | } 26 | 27 | @Test 28 | public void addsInitializationParameters() throws Exception { 29 | config.addInitParams(ImmutableMap.of("one", "1", "two", "2")); 30 | 31 | verify(holder).setInitParameter("one", "1"); 32 | verify(holder).setInitParameter("two", "2"); 33 | verifyNoMoreInteractions(holder); 34 | } 35 | 36 | @Test 37 | public void mapsAUrlPatternToAFilter() throws Exception { 38 | config.addUrlPattern("/one"); 39 | 40 | assertThat(mappings.build(), 41 | is(ImmutableMultimap.of("/one", holder))); 42 | } 43 | 44 | @Test 45 | public void mapsUrlPatternsToAFilter() throws Exception { 46 | config.addUrlPatterns("/one", "/two"); 47 | 48 | assertThat(mappings.build(), 49 | is(ImmutableMultimap.of("/one", holder, 50 | "/two", holder))); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/cli/UsagePrinter.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.cli; 2 | 3 | import com.yammer.dropwizard.AbstractService; 4 | import com.yammer.dropwizard.util.JarLocation; 5 | import org.apache.commons.cli.HelpFormatter; 6 | 7 | @SuppressWarnings("UseOfSystemOutOrSystemErr") 8 | public class UsagePrinter { 9 | private UsagePrinter() { 10 | // singleton 11 | } 12 | 13 | public static void printRootHelp(AbstractService service) { 14 | System.out.printf("java -jar %s [arg1 arg2]\n\n", new JarLocation(service.getClass())); 15 | System.out.println("Commands"); 16 | System.out.println("========\n"); 17 | 18 | for (Command command : service.getCommands()) { 19 | printCommandHelp(command, service.getClass()); 20 | } 21 | } 22 | 23 | public static void printCommandHelp(Command cmd, Class klass) { 24 | printCommandHelp(cmd, klass, null); 25 | } 26 | 27 | public static void printCommandHelp(Command cmd, Class klass, String errorMessage) { 28 | if (errorMessage != null) { 29 | System.err.println(errorMessage); 30 | System.out.println(); 31 | } 32 | 33 | System.out.println(formatTitle(cmd)); 34 | final HelpFormatter helpFormatter = new HelpFormatter(); 35 | helpFormatter.setLongOptPrefix(" --"); 36 | helpFormatter.printHelp(String.format("java -jar %s", cmd.getUsage(klass)), 37 | cmd.getOptionsWithHelp()); 38 | System.out.println("\n"); 39 | } 40 | 41 | private static String formatTitle(Command cmd) { 42 | final String title = cmd.getName() + ": " + cmd.getDescription(); 43 | return title + '\n' + getBanner(title.length()); 44 | } 45 | 46 | private static String getBanner(int length) { 47 | final StringBuilder builder = new StringBuilder(length); 48 | for (int i = 0; i < length; i++) { 49 | builder.append('-'); 50 | } 51 | return builder.toString(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /dropwizard-db/src/main/java/com/yammer/dropwizard/db/Database.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.db; 2 | 3 | import ch.qos.logback.classic.Level; 4 | import ch.qos.logback.classic.Logger; 5 | import com.yammer.dropwizard.db.args.OptionalArgumentFactory; 6 | import com.yammer.dropwizard.db.logging.LogbackLog; 7 | import com.yammer.dropwizard.lifecycle.Managed; 8 | import com.yammer.metrics.Metrics; 9 | import com.yammer.metrics.jdbi.InstrumentedTimingCollector; 10 | import org.apache.tomcat.dbcp.pool.ObjectPool; 11 | import org.skife.jdbi.v2.ColonPrefixNamedParamStatementRewriter; 12 | import org.skife.jdbi.v2.DBI; 13 | import org.skife.jdbi.v2.Handle; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import javax.sql.DataSource; 17 | import java.sql.SQLException; 18 | 19 | public class Database extends DBI implements Managed { 20 | private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(Database.class); 21 | 22 | private final ObjectPool pool; 23 | private final String validationQuery; 24 | 25 | public Database(DataSource dataSource, ObjectPool pool, String validationQuery) { 26 | super(dataSource); 27 | this.pool = pool; 28 | this.validationQuery = validationQuery; 29 | setSQLLog(new LogbackLog(LOGGER, Level.TRACE)); 30 | setTimingCollector(new InstrumentedTimingCollector(Metrics.defaultRegistry())); 31 | setStatementRewriter(new NamePrependingStatementRewriter(new ColonPrefixNamedParamStatementRewriter())); 32 | registerArgumentFactory(new OptionalArgumentFactory()); 33 | registerContainerFactory(new ImmutableListContainerFactory()); 34 | } 35 | 36 | @Override 37 | public void start() throws Exception { 38 | // already started, man 39 | } 40 | 41 | @Override 42 | public void stop() throws Exception { 43 | pool.close(); 44 | } 45 | 46 | public void ping() throws SQLException { 47 | final Handle handle = open(); 48 | try { 49 | handle.execute(validationQuery); 50 | } finally { 51 | handle.close(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /dropwizard-auth/src/test/java/com/yammer/dropwizard/auth/basic/tests/BasicCredentialsTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth.basic.tests; 2 | 3 | import com.yammer.dropwizard.auth.basic.BasicCredentials; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.Matchers.*; 7 | import static org.junit.Assert.*; 8 | 9 | public class BasicCredentialsTest { 10 | private final BasicCredentials credentials = new BasicCredentials("u", "p"); 11 | 12 | @Test 13 | public void hasAUsername() throws Exception { 14 | assertThat(credentials.getUsername(), 15 | is("u")); 16 | } 17 | 18 | @Test 19 | public void hasAPassword() throws Exception { 20 | assertThat(credentials.getPassword(), 21 | is("p")); 22 | } 23 | 24 | @Test 25 | public void hasAWorkingEqualsMethod() throws Exception { 26 | assertThat(credentials, 27 | is(equalTo(credentials))); 28 | 29 | assertThat(credentials, 30 | is(equalTo(new BasicCredentials("u", "p")))); 31 | 32 | assertThat(credentials, 33 | is(not(equalTo(null)))); 34 | 35 | assertThat(credentials, 36 | is(not(equalTo((Object) "string")))); 37 | 38 | assertThat(credentials, 39 | is(not(equalTo(new BasicCredentials("u1", "p"))))); 40 | 41 | assertThat(credentials, 42 | is(not(equalTo(new BasicCredentials("u", "p1"))))); 43 | } 44 | 45 | @Test 46 | public void hasAWorkingHashCode() throws Exception { 47 | assertThat(credentials.hashCode(), 48 | is(new BasicCredentials("u", "p").hashCode())); 49 | 50 | assertThat(credentials.hashCode(), 51 | is(not(new BasicCredentials("u1", "p").hashCode()))); 52 | 53 | assertThat(credentials.hashCode(), 54 | is(not(new BasicCredentials("u", "p1").hashCode()))); 55 | } 56 | 57 | @Test 58 | public void isHumanReadable() throws Exception { 59 | assertThat(credentials.toString(), 60 | is("BasicCredentials{username=u, password=**********}")); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/jersey/caching/CacheControlledResourceMethodDispatchProvider.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.jersey.caching; 2 | 3 | import com.sun.jersey.api.model.AbstractResourceMethod; 4 | import com.sun.jersey.spi.container.ResourceMethodDispatchProvider; 5 | import com.sun.jersey.spi.dispatch.RequestDispatcher; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | public class CacheControlledResourceMethodDispatchProvider implements ResourceMethodDispatchProvider { 10 | private static final int ONE_YEAR_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(365); 11 | 12 | private final ResourceMethodDispatchProvider provider; 13 | 14 | public CacheControlledResourceMethodDispatchProvider(ResourceMethodDispatchProvider provider) { 15 | this.provider = provider; 16 | } 17 | 18 | @Override 19 | public RequestDispatcher create(AbstractResourceMethod abstractResourceMethod) { 20 | final RequestDispatcher dispatcher = provider.create(abstractResourceMethod); 21 | final CacheControl control = abstractResourceMethod.getAnnotation(CacheControl.class); 22 | if (control != null) { 23 | final javax.ws.rs.core.CacheControl cacheControl = new javax.ws.rs.core.CacheControl(); 24 | cacheControl.setPrivate(control.isPrivate()); 25 | cacheControl.setNoCache(control.noCache()); 26 | cacheControl.setNoStore(control.noStore()); 27 | cacheControl.setNoTransform(control.noTransform()); 28 | cacheControl.setMustRevalidate(control.mustRevalidate()); 29 | cacheControl.setProxyRevalidate(control.proxyRevalidate()); 30 | cacheControl.setMaxAge((int) control.maxAgeUnit().toSeconds(control.maxAge())); 31 | cacheControl.setSMaxAge((int) control.sharedMaxAgeUnit() 32 | .toSeconds(control.sharedMaxAge())); 33 | if (control.immutable()) { 34 | cacheControl.setMaxAge(ONE_YEAR_IN_SECONDS); 35 | } 36 | return new CacheControlledRequestDispatcher(dispatcher, cacheControl); 37 | } 38 | return dispatcher; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /dropwizard-core/src/test/java/com/yammer/dropwizard/config/tests/ServletConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config.tests; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import com.yammer.dropwizard.config.ServletConfiguration; 5 | import org.eclipse.jetty.servlet.ServletHolder; 6 | import org.junit.Test; 7 | 8 | import static org.hamcrest.Matchers.is; 9 | import static org.junit.Assert.assertThat; 10 | import static org.mockito.Mockito.mock; 11 | import static org.mockito.Mockito.verify; 12 | import static org.mockito.Mockito.verifyNoMoreInteractions; 13 | 14 | public class ServletConfigurationTest { 15 | private final ServletHolder holder = mock(ServletHolder.class); 16 | private final ImmutableMap.Builder mappings = ImmutableMap.builder(); 17 | private final ServletConfiguration config = new ServletConfiguration(holder, mappings); 18 | 19 | @Test 20 | public void setsInitializationOrder() throws Exception { 21 | config.setInitOrder(13); 22 | 23 | verify(holder).setInitOrder(13); 24 | } 25 | 26 | @Test 27 | public void setsInitializationParameters() throws Exception { 28 | config.setInitParam("one", "1"); 29 | 30 | verify(holder).setInitParameter("one", "1"); 31 | } 32 | 33 | @Test 34 | public void addsInitializationParameters() throws Exception { 35 | config.addInitParams(ImmutableMap.of("one", "1", "two", "2")); 36 | 37 | verify(holder).setInitParameter("one", "1"); 38 | verify(holder).setInitParameter("two", "2"); 39 | verifyNoMoreInteractions(holder); 40 | } 41 | 42 | @Test 43 | public void mapsAUrlPatternToAFilter() throws Exception { 44 | config.addUrlPattern("/one"); 45 | 46 | assertThat(mappings.build(), 47 | is(ImmutableMap.of("/one", holder))); 48 | } 49 | 50 | @Test 51 | public void mapsUrlPatternsToAFilter() throws Exception { 52 | config.addUrlPatterns("/one", "/two"); 53 | 54 | assertThat(mappings.build(), 55 | is(ImmutableMap.of("/one", holder, 56 | "/two", holder))); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /dropwizard-client/src/main/java/com/yammer/dropwizard/client/JerseyClientFactory.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.client; 2 | 3 | import com.sun.jersey.api.client.filter.GZIPContentEncodingFilter; 4 | import com.sun.jersey.client.apache4.ApacheHttpClient4Handler; 5 | import com.sun.jersey.client.apache4.config.ApacheHttpClient4Config; 6 | import com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config; 7 | import com.yammer.dropwizard.config.Environment; 8 | import com.yammer.dropwizard.jersey.JacksonMessageBodyProvider; 9 | import org.apache.http.client.HttpClient; 10 | 11 | import java.util.concurrent.TimeUnit; 12 | 13 | public class JerseyClientFactory { 14 | private final JerseyClientConfiguration configuration; 15 | private final HttpClientFactory factory; 16 | 17 | public JerseyClientFactory(JerseyClientConfiguration configuration) { 18 | this.configuration = configuration; 19 | this.factory = new HttpClientFactory(configuration); 20 | } 21 | 22 | public JerseyClient build(Environment environment) { 23 | final HttpClient client = factory.build(); 24 | 25 | final ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(client, null, true); 26 | 27 | final ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); 28 | config.getSingletons().add(new JacksonMessageBodyProvider(environment.getService().getJson())); 29 | 30 | final JerseyClient jerseyClient = new JerseyClient(handler, config); 31 | jerseyClient.setExecutorService(environment.managedExecutorService("jersey-client-%d", 32 | configuration.getMinThreads(), 33 | configuration.getMaxThreads(), 34 | 60, 35 | TimeUnit.SECONDS)); 36 | 37 | if (configuration.isGzipEnabled()) { 38 | jerseyClient.addFilter(new GZIPContentEncodingFilter()); 39 | } 40 | 41 | return jerseyClient; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /findbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/validation/Validator.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.validation; 2 | 3 | import com.google.common.base.Joiner; 4 | import com.google.common.collect.ImmutableList; 5 | import com.google.common.collect.Ordering; 6 | import com.google.common.collect.Sets; 7 | 8 | import javax.validation.ConstraintViolation; 9 | import javax.validation.Path; 10 | import javax.validation.Validation; 11 | import javax.validation.ValidatorFactory; 12 | import java.util.Set; 13 | 14 | import static java.lang.String.format; 15 | 16 | /** 17 | * A simple façade for Hibernate Validator. 18 | */ 19 | public class Validator { 20 | private final ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 21 | 22 | /** 23 | * Validates the given object, and returns a list of error messages, if any. If the returned 24 | * list is empty, the object is valid. 25 | * 26 | * @param o a potentially-valid object 27 | * @param the type of object to validate 28 | * @return a list of error messages, if any, regarding {@code o}'s validity 29 | */ 30 | public ImmutableList validate(T o) { 31 | final Set errors = Sets.newHashSet(); 32 | final Set> violations = factory.getValidator().validate(o); 33 | for (ConstraintViolation v : violations) { 34 | if (v.getConstraintDescriptor().getAnnotation() instanceof ValidationMethod) { 35 | final ImmutableList nodes = ImmutableList.copyOf(v.getPropertyPath()); 36 | final ImmutableList usefulNodes = nodes.subList(0, nodes.size() - 1); 37 | final String msg = v.getMessage().startsWith(".") ? "%s%s" : "%s %s"; 38 | errors.add(format(msg, Joiner.on('.').join(usefulNodes), v.getMessage()).trim()); 39 | } else { 40 | errors.add(format("%s %s (was %s)", 41 | v.getPropertyPath(), 42 | v.getMessage(), 43 | v.getInvalidValue())); 44 | } 45 | } 46 | return ImmutableList.copyOf(Ordering.natural().sortedCopy(errors)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/config/Configuration.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.config; 2 | 3 | import org.codehaus.jackson.annotate.JsonProperty; 4 | 5 | import javax.validation.Valid; 6 | import javax.validation.constraints.NotNull; 7 | 8 | /** 9 | * An object representation of the YAML configuration file. Extend this with your own configuration 10 | * properties, and they'll be parsed from the YAML file as well. 11 | *

12 | * For example, given a YAML file with this: 13 | *

14 |  * name: "Random Person"
15 |  * age: 43
16 |  * # ... etc ...
17 |  * 
18 | * And a configuration like this: 19 | *
20 |  * public class ExampleConfiguration extends Configuration {
21 |  *     \@NotNull
22 |  *     private String name;
23 |  *
24 |  *     \@Min(1)
25 |  *     \@Max(120)
26 |  *     private int age;
27 |  *
28 |  *     public String getName() {
29 |  *         return name;
30 |  *     }
31 |  *
32 |  *     public int getAge() {
33 |  *         return age;
34 |  *     }
35 |  * }
36 |  * 
37 | * Dropwizard will parse the given YAML file and provide an {@code ExampleConfiguration} instance 38 | * to your service whose {@code getName()} method will return {@code "Random Person"} and whose 39 | * {@code getAge()} method will return {@code 43}. 40 | * 41 | * @see YAML Cookbook 42 | */ 43 | @SuppressWarnings("FieldMayBeFinal") 44 | public class Configuration { 45 | @Valid 46 | @NotNull 47 | @JsonProperty 48 | protected HttpConfiguration http = new HttpConfiguration(); 49 | 50 | @Valid 51 | @NotNull 52 | @JsonProperty 53 | protected LoggingConfiguration logging = new LoggingConfiguration(); 54 | 55 | /** 56 | * Returns the HTTP-specific section of the configuration file. 57 | * 58 | * @return HTTP-specific configuration parameters 59 | */ 60 | public HttpConfiguration getHttpConfiguration() { 61 | return http; 62 | } 63 | 64 | /** 65 | * Returns the logging-specific section of the configuration file. 66 | * 67 | * @return logging-specific configuration parameters 68 | */ 69 | public LoggingConfiguration getLoggingConfiguration() { 70 | return logging; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/servlets/SlowRequestFilter.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.servlets; 2 | 3 | import com.yammer.dropwizard.logging.Log; 4 | import com.yammer.dropwizard.util.Duration; 5 | 6 | import javax.servlet.*; 7 | import javax.servlet.http.HttpServletRequest; 8 | import java.io.IOException; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import static com.yammer.dropwizard.util.Servlets.getFullUrl; 12 | 13 | /** 14 | * A servlet filter which logs the methods and URIs of requests which take longer than a given 15 | * duration of time to complete. 16 | */ 17 | public class SlowRequestFilter implements Filter { 18 | private static final Log LOG = Log.forClass(SlowRequestFilter.class); 19 | private final long threshold; 20 | 21 | /** 22 | * Creates a filter which logs requests which take longer than 1 second. 23 | */ 24 | public SlowRequestFilter() { 25 | this(Duration.seconds(1)); 26 | } 27 | 28 | /** 29 | * Creates a filter which logs requests which take longer than the given duration. 30 | * 31 | * @param threshold the threshold for considering a request slow 32 | */ 33 | public SlowRequestFilter(Duration threshold) { 34 | this.threshold = threshold.toNanoseconds(); 35 | } 36 | 37 | @Override 38 | public void init(FilterConfig filterConfig) throws ServletException { /* unused */ } 39 | 40 | @Override 41 | public void destroy() { /* unused */ } 42 | 43 | @Override 44 | public void doFilter(ServletRequest request, 45 | ServletResponse response, 46 | FilterChain chain) throws IOException, ServletException { 47 | final HttpServletRequest req = (HttpServletRequest) request; 48 | final long startTime = System.nanoTime(); 49 | try { 50 | chain.doFilter(request, response); 51 | } finally { 52 | final long elapsedMS = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); 53 | if (elapsedMS >= threshold) { 54 | LOG.warn("Slow request: {} {} ({}ms)", 55 | req.getMethod(), 56 | getFullUrl(req), elapsedMS); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /dropwizard-core/src/main/java/com/yammer/dropwizard/json/LogbackModule.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.json; 2 | 3 | import ch.qos.logback.classic.Level; 4 | import org.codehaus.jackson.JsonParser; 5 | import org.codehaus.jackson.Version; 6 | import org.codehaus.jackson.map.*; 7 | import org.codehaus.jackson.map.annotate.JsonCachable; 8 | import org.codehaus.jackson.type.JavaType; 9 | 10 | import java.io.IOException; 11 | 12 | class LogbackModule extends Module { 13 | @JsonCachable 14 | private static class LevelDeserializer extends JsonDeserializer { 15 | @Override 16 | public Level deserialize(JsonParser jp, 17 | DeserializationContext ctxt) throws IOException { 18 | 19 | final String text = jp.getText(); 20 | 21 | if ("false".equalsIgnoreCase(text)) { 22 | return Level.OFF; 23 | } 24 | 25 | if ("true".equalsIgnoreCase(text)) { 26 | return Level.ALL; 27 | } 28 | 29 | return Level.toLevel(text, Level.INFO); 30 | } 31 | } 32 | 33 | private static class LogbackDeserializers extends Deserializers.Base { 34 | @Override 35 | public JsonDeserializer findBeanDeserializer(JavaType type, 36 | DeserializationConfig config, 37 | DeserializerProvider provider, 38 | BeanDescription beanDesc, 39 | BeanProperty property) throws JsonMappingException { 40 | if (Level.class.isAssignableFrom(type.getRawClass())) { 41 | return new LevelDeserializer(); 42 | } 43 | 44 | return super.findBeanDeserializer(type, config, provider, beanDesc, property); 45 | } 46 | } 47 | 48 | @Override 49 | public String getModuleName() { 50 | return "LogbackModule"; 51 | } 52 | 53 | @Override 54 | public Version version() { 55 | return Version.unknownVersion(); 56 | } 57 | 58 | @Override 59 | public void setupModule(SetupContext context) { 60 | context.addDeserializers(new LogbackDeserializers()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/less/progress-bars.less: -------------------------------------------------------------------------------- 1 | // PROGRESS BARS 2 | // ------------- 3 | 4 | 5 | // ANIMATIONS 6 | // ---------- 7 | 8 | // Webkit 9 | @-webkit-keyframes progress-bar-stripes { 10 | from { background-position: 0 0; } 11 | to { background-position: 40px 0; } 12 | } 13 | 14 | // Firefox 15 | @-moz-keyframes progress-bar-stripes { 16 | from { background-position: 0 0; } 17 | to { background-position: 40px 0; } 18 | } 19 | 20 | // Spec 21 | @keyframes progress-bar-stripes { 22 | from { background-position: 0 0; } 23 | to { background-position: 40px 0; } 24 | } 25 | 26 | 27 | 28 | // THE BARS 29 | // -------- 30 | 31 | // Outer container 32 | .progress { 33 | overflow: hidden; 34 | height: 18px; 35 | margin-bottom: 18px; 36 | #gradient > .vertical(#f5f5f5, #f9f9f9); 37 | .box-shadow(inset 0 1px 2px rgba(0,0,0,.1)); 38 | .border-radius(4px); 39 | } 40 | 41 | // Bar of progress 42 | .progress .bar { 43 | width: 0%; 44 | height: 18px; 45 | color: @white; 46 | font-size: 12px; 47 | text-align: center; 48 | text-shadow: 0 -1px 0 rgba(0,0,0,.25); 49 | #gradient > .vertical(#149bdf, #0480be); 50 | .box-shadow(inset 0 -1px 0 rgba(0,0,0,.15)); 51 | .box-sizing(border-box); 52 | .transition(width .6s ease); 53 | } 54 | 55 | // Striped bars 56 | .progress-striped .bar { 57 | #gradient > .striped(#62c462); 58 | .background-size(40px 40px); 59 | } 60 | 61 | // Call animation for the active one 62 | .progress.active .bar { 63 | -webkit-animation: progress-bar-stripes 2s linear infinite; 64 | -moz-animation: progress-bar-stripes 2s linear infinite; 65 | animation: progress-bar-stripes 2s linear infinite; 66 | } 67 | 68 | 69 | 70 | // COLORS 71 | // ------ 72 | 73 | // Danger (red) 74 | .progress-danger .bar { 75 | #gradient > .vertical(#ee5f5b, #c43c35); 76 | } 77 | .progress-danger.progress-striped .bar { 78 | #gradient > .striped(#ee5f5b); 79 | } 80 | 81 | // Success (green) 82 | .progress-success .bar { 83 | #gradient > .vertical(#62c462, #57a957); 84 | } 85 | .progress-success.progress-striped .bar { 86 | #gradient > .striped(#62c462); 87 | } 88 | 89 | // Info (teal) 90 | .progress-info .bar { 91 | #gradient > .vertical(#5bc0de, #339bb9); 92 | } 93 | .progress-info.progress-striped .bar { 94 | #gradient > .striped(#5bc0de); 95 | } 96 | -------------------------------------------------------------------------------- /dropwizard-db/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.yammer.dropwizard 7 | dropwizard-parent 8 | 0.4.1-SNAPSHOT 9 | 10 | 11 | dropwizard-db 12 | Dropwizard Database Client 13 | 14 | 15 | 16 | com.yammer.dropwizard 17 | dropwizard-core 18 | ${project.version} 19 | 20 | 21 | org.jdbi 22 | jdbi 23 | 2.34 24 | 25 | 26 | com.yammer.metrics 27 | metrics-jdbi 28 | ${metrics.version} 29 | 30 | 31 | org.apache.tomcat 32 | tomcat-dbcp 33 | 7.0.27 34 | 35 | 36 | hsqldb 37 | hsqldb 38 | 1.8.0.10 39 | test 40 | 41 | 42 | junit 43 | junit 44 | 4.10 45 | test 46 | 47 | 48 | org.mockito 49 | mockito-all 50 | 1.9.0 51 | test 52 | 53 | 54 | org.hamcrest 55 | hamcrest-all 56 | 1.1 57 | test 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /dropwizard-auth/src/main/java/com/yammer/dropwizard/auth/basic/BasicCredentials.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.auth.basic; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.base.Objects; 5 | 6 | import java.security.MessageDigest; 7 | 8 | import static com.google.common.base.Preconditions.checkNotNull; 9 | 10 | /** 11 | * A set of user-provided Basic Authentication credentials, consisting of a username and a password. 12 | */ 13 | public class BasicCredentials { 14 | private final String username; 15 | private final String password; 16 | 17 | /** 18 | * Creates a new {@link BasicCredentials} with the given username and password. 19 | * 20 | * @param username the username 21 | * @param password the password 22 | */ 23 | public BasicCredentials(String username, String password) { 24 | this.username = checkNotNull(username); 25 | this.password = checkNotNull(password); 26 | } 27 | 28 | /** 29 | * Returns the credentials' username. 30 | * 31 | * @return the credentials' username 32 | */ 33 | public String getUsername() { 34 | return username; 35 | } 36 | 37 | /** 38 | * Returns the credentials' password. 39 | * 40 | * @return the credentials' password 41 | */ 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) { return true; } 49 | if ((obj == null) || (getClass() != obj.getClass())) { return false; } 50 | final BasicCredentials that = (BasicCredentials) obj; 51 | // N.B.: Do a constant-time comparison here to prevent timing attacks. 52 | final byte[] thisBytes = password.getBytes(Charsets.UTF_8); 53 | final byte[] thatBytes = that.password.getBytes(Charsets.UTF_8); 54 | return username.equals(that.username) && MessageDigest.isEqual(thisBytes, thatBytes); 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return (31 * username.hashCode()) + password.hashCode(); 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return Objects.toStringHelper(this) 65 | .add("username", username) 66 | .add("password", "**********") 67 | .toString(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /docs/source/_themes/yammerdoc/genindex.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/genindex.html 3 | ~~~~~~~~~~~~~~~~~~~ 4 | 5 | Template for an "all-in-one" index. 6 | 7 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {% macro indexentries(firstname, links) %} 11 |
12 | {%- if links -%} 13 | 14 | {%- if links[0][0] %}{% endif -%} 15 | {{ firstname|e }} 16 | {%- if links[0][0] %}{% endif -%} 17 | 18 | 19 | {%- for ismain, link in links[1:] -%} 20 | , {% if ismain %}{% endif -%} 21 | [{{ loop.index }}] 22 | {%- if ismain %}{% endif -%} 23 | 24 | {%- endfor %} 25 | {%- else %} 26 | {{ firstname|e }} 27 | {%- endif %} 28 |
29 | {% endmacro %} 30 | 31 | {% extends "layout.html" %} 32 | {% set title = _('Index') %} 33 | {% block body %} 34 | 35 |

{{ _('Index') }}

36 | 37 |
38 | {% for key, dummy in genindexentries -%} 39 | {{ key }} 40 | {% if not loop.last %}| {% endif %} 41 | {%- endfor %} 42 |
43 | 44 | {%- for key, entries in genindexentries %} 45 |

{{ key }}

46 | 47 | {%- for column in entries|slice(2) if column %} 48 | 60 | {%- endfor %} 61 |
49 | {%- for entryname, (links, subitems) in column %} 50 | {{ indexentries(entryname, links) }} 51 | {%- if subitems %} 52 |
53 | {%- for subentryname, subentrylinks in subitems %} 54 | {{ indexentries(subentryname, subentrylinks) }} 55 | {%- endfor %} 56 |
57 | {%- endif -%} 58 | {%- endfor %} 59 |
62 | {% endfor %} 63 | 64 | {% endblock %} 65 | 66 | {% block sidebarrel %} 67 | {% if split_index %} 68 |

{{ _('Index') }}

69 |

{% for key, dummy in genindexentries -%} 70 | {{ key }} 71 | {% if not loop.last %}| {% endif %} 72 | {%- endfor %}

73 | 74 |

{{ _('Full index on one page') }}

75 | {% endif %} 76 | {{ super() }} 77 | {% endblock %} 78 | -------------------------------------------------------------------------------- /dropwizard-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.yammer.dropwizard 7 | dropwizard-parent 8 | 0.4.1-SNAPSHOT 9 | 10 | 11 | dropwizard-client 12 | Dropwizard HTTP Client 13 | 14 | 15 | 16 | com.yammer.dropwizard 17 | dropwizard-core 18 | ${project.version} 19 | 20 | 21 | com.sun.jersey 22 | jersey-client 23 | ${jersey.version} 24 | 25 | 26 | com.sun.jersey.contribs 27 | jersey-apache-client4 28 | ${jersey.version} 29 | 30 | 31 | org.apache.httpcomponents 32 | httpclient 33 | 4.1.3 34 | 35 | 36 | com.yammer.metrics 37 | metrics-httpclient 38 | ${metrics.version} 39 | 40 | 41 | junit 42 | junit 43 | 4.10 44 | test 45 | 46 | 47 | org.mockito 48 | mockito-all 49 | 1.9.0 50 | test 51 | 52 | 53 | org.hamcrest 54 | hamcrest-all 55 | 1.1 56 | test 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /dropwizard-views/src/main/java/com/yammer/dropwizard/views/ViewBundle.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.views; 2 | 3 | import com.yammer.dropwizard.Bundle; 4 | import com.yammer.dropwizard.config.Environment; 5 | 6 | /** 7 | * A {@link Bundle} which enables the rendering of FreeMarker views by your service. 8 | * 9 | *

A view combines a Freemarker template with a set of Java objects:

10 | * 11 | *

12 |  * public class PersonView extends View {
13 |  *     private final Person person;
14 |  *
15 |  *     public PersonView(Person person) {
16 |  *         super("profile.ftl");
17 |  *         this.person = person;
18 |  *     }
19 |  *
20 |  *     public Person getPerson() {
21 |  *         return person;
22 |  *     }
23 |  * }
24 |  * 
25 | * 26 | *

The {@code "profile.ftl"} is the path of the template relative to the class name. If this 27 | * class was {@code com.example.service.PersonView}, Freemarker would then look for the file 28 | * {@code src/main/resources/com/example/service/profile.ftl}. If the template path 29 | * starts with a slash (e.g., {@code "/hello.ftl"}), Freemarker will look for the file {@code 30 | * src/main/resources/hello.ftl}. 31 | * 32 | *

A resource method with a view would looks something like this:

33 | * 34 | *

35 |  * \@GET
36 |  * public PersonView getPerson(\@PathParam("id") String id) {
37 |  *     return new PersonView(dao.find(id));
38 |  * }
39 |  * 
40 | * 41 | *

Freemarker templates look something like this:

42 | * 43 | *
{@code
44 |  * <#-- @ftlvariable name="" type="com.example.service.PersonView" -->
45 |  * 
46 |  *     
47 |  *         

Hello, ${person.name?html}!

48 | * 49 | * 50 | * }
51 | * 52 | *

In this template, {@code ${person.name}} calls {@code getPerson().getName()}, and the 53 | * {@code ?html} escapes all HTML control characters in the result. The {@code ftlvariable} comment 54 | * at the top indicate to Freemarker (and your IDE) that the root object is a {@code Person}, 55 | * allowing for better typesafety in your templates.

56 | * 57 | * @see FreeMarker Manual 58 | */ 59 | public class ViewBundle implements Bundle { 60 | @Override 61 | public void initialize(Environment environment) { 62 | environment.addProvider(ViewMessageBodyWriter.class); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /dropwizard-client/src/main/java/com/yammer/dropwizard/client/HttpClientConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.yammer.dropwizard.client; 2 | 3 | import com.yammer.dropwizard.util.Duration; 4 | 5 | import javax.validation.constraints.Max; 6 | import javax.validation.constraints.Min; 7 | import javax.validation.constraints.NotNull; 8 | 9 | public class HttpClientConfiguration { 10 | @NotNull 11 | private Duration timeout = Duration.milliseconds(500); 12 | 13 | @NotNull 14 | private Duration connectionTimeout = Duration.milliseconds(500); 15 | 16 | @NotNull 17 | private Duration timeToLive = Duration.hours(1); 18 | 19 | private boolean cookiesEnabled = false; 20 | 21 | @Max(Integer.MAX_VALUE) 22 | @Min(1) 23 | private int maxConnections = 1024; 24 | 25 | @NotNull 26 | private Duration keepAlive = Duration.milliseconds(0l); 27 | 28 | @Max(Integer.MAX_VALUE) 29 | @Min(1) 30 | private int maxConnectionsPerRoute = 1024; 31 | 32 | public Duration getKeepAlive() { 33 | return keepAlive; 34 | } 35 | 36 | public void setKeepAlive(Duration keepAlive) { 37 | this.keepAlive = keepAlive; 38 | } 39 | 40 | public int getMaxConnectionsPerRoute() { 41 | return maxConnectionsPerRoute; 42 | } 43 | 44 | public void setMaxConnectionsPerRoute(int maxConnectionsPerRoute) { 45 | this.maxConnectionsPerRoute = maxConnectionsPerRoute; 46 | } 47 | public Duration getTimeout() { 48 | return timeout; 49 | } 50 | 51 | public Duration getConnectionTimeout() { 52 | return connectionTimeout; 53 | } 54 | 55 | public Duration getTimeToLive() { 56 | return timeToLive; 57 | } 58 | 59 | public boolean isCookiesEnabled() { 60 | return cookiesEnabled; 61 | } 62 | 63 | public void setTimeout(Duration duration) { 64 | this.timeout = duration; 65 | } 66 | 67 | public void setConnectionTimeout(Duration duration) { 68 | this.connectionTimeout = duration; 69 | } 70 | 71 | public void setTimeToLive(Duration timeToLive) { 72 | this.timeToLive = timeToLive; 73 | } 74 | 75 | public void setCookiesEnabled(boolean enabled) { 76 | this.cookiesEnabled = enabled; 77 | } 78 | 79 | public int getMaxConnections() { 80 | return maxConnections; 81 | } 82 | 83 | public void setMaxConnections(int maxConnections) { 84 | this.maxConnections = maxConnections; 85 | } 86 | } 87 | --------------------------------------------------------------------------------