or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdconfiguration.mdcore-application.mddatabase.mdindex.mdmetrics.mdrest-api.mdtesting.mdvalidation.md
tile.json

tessl/maven-io-dropwizard--dropwizard-project

Java framework for developing ops-friendly, high-performance, RESTful web applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.dropwizard/dropwizard-project@3.0.x

To install, run

npx @tessl/cli install tessl/maven-io-dropwizard--dropwizard-project@3.0.0

index.mddocs/

Dropwizard

Dropwizard is a Java framework for developing ops-friendly, high-performance, RESTful web applications. It brings together mature Java libraries including Jetty, Jersey, Jackson, Logback, Hibernate Validator, and Metrics into a cohesive framework that enables rapid development of production-ready services with built-in operational features.

Package Information

  • Package Name: dropwizard-project
  • Package Type: maven
  • Language: Java
  • Installation: Add core dependency to your pom.xml
  • Group ID: io.dropwizard
  • Artifact ID: dropwizard-core
  • Version: 3.0.14
  • License: Apache-2.0

Core Imports

import io.dropwizard.core.Application;
import io.dropwizard.core.Configuration;
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;

Additional common imports:

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import com.codahale.metrics.annotation.Timed;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

Basic Usage

// 1. Create configuration class
public class HelloWorldConfiguration extends Configuration {
    @NotNull
    private String template = "Hello, %s!";
    
    @JsonProperty
    public String getTemplate() { return template; }
    
    @JsonProperty
    public void setTemplate(String template) { this.template = template; }
}

// 2. Create JAX-RS resource
@Path("/hello-world")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
    private final String template;
    
    public HelloWorldResource(String template) {
        this.template = template;
    }
    
    @GET
    @Timed
    public Saying sayHello(@QueryParam("name") Optional<String> name) {
        final String value = String.format(template, name.orElse("Stranger"));
        return new Saying(value);
    }
}

// 3. Create application class
public class HelloWorldApplication extends Application<HelloWorldConfiguration> {
    public static void main(String[] args) throws Exception {
        new HelloWorldApplication().run(args);
    }
    
    @Override
    public String getName() {
        return "hello-world";
    }
    
    @Override
    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
        // Add bundles here
    }
    
    @Override
    public void run(HelloWorldConfiguration configuration,
                    Environment environment) {
        final HelloWorldResource resource = new HelloWorldResource(
            configuration.getTemplate()
        );
        environment.jersey().register(resource);
    }
}

Architecture

Dropwizard follows a convention-over-configuration approach with several key architectural components:

  • Application Class: Main entry point extending Application<T> that defines application lifecycle
  • Configuration: YAML-based configuration with validation using Bean Validation (JSR-303)
  • Environment: Runtime container providing access to Jersey, servlets, admin interface, lifecycle, metrics, and health checks
  • Bootstrap: Pre-start setup environment for registering bundles and commands
  • Bundles: Reusable application components that configure multiple aspects of the application
  • Managed Objects: Lifecycle-aware components with start/stop methods for resource management

Capabilities

Core Application Framework

Foundation classes for building Dropwizard applications including the main Application class, Configuration system, and runtime Environment management.

public abstract class Application<T extends Configuration> {
    public abstract String getName();
    public void initialize(Bootstrap<T> bootstrap) {}
    public abstract void run(T configuration, Environment environment) throws Exception;
    public final void run(String... arguments) throws Exception;
}

public class Configuration {
    // Server configuration, logging, metrics, admin interface setup
}

public class Environment {
    public JerseyEnvironment jersey();
    public ServletEnvironment servlets();
    public AdminEnvironment admin();
    public LifecycleEnvironment lifecycle();
    public HealthCheckRegistry healthChecks();
    public MetricRegistry metrics();
}

Core Application Framework

REST API Development

Jersey (JAX-RS) integration for building RESTful web services with automatic JSON serialization, validation, and metrics collection.

public class JerseyEnvironment {
    public void register(Object component);
    public void register(Class<?> componentClass);
    public void packages(String... packages);
}

// Common JAX-RS annotations for resources
@Path("/resource")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ResourceClass {
    @GET @POST @PUT @DELETE
    @Timed @Metered @Counted
    public ResponseType method(@PathParam("id") String id,
                              @QueryParam("param") String param,
                              @Valid RequestType request);
}

REST API Development

Configuration Management

YAML-based configuration system with environment variable substitution, validation, and type-safe access to application settings.

public class ConfigurationFactory<T> {
    public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException;
}

public interface ConfigurationSourceProvider {
    InputStream open(String path) throws IOException;
}

// Configuration validation annotations
@NotNull @NotEmpty @Valid @Min @Max @Range
@DurationRange @DataSizeRange @OneOf @PortRange

Configuration Management

Authentication and Authorization

Pluggable authentication system supporting basic auth, OAuth, and custom authentication schemes with fine-grained authorization control.

public interface Authenticator<C, P> {
    Optional<P> authenticate(C credentials) throws AuthenticationException;
}

public interface Authorizer<P> {
    boolean authorize(P principal, String role);
}

public class AuthDynamicFeature implements DynamicFeature {
    // Register authentication filters with Jersey
}

Authentication

Database Integration

Comprehensive database support including connection pooling, ORM integration with Hibernate, lightweight SQL access with JDBI, and database migrations with Liquibase.

public class DataSourceFactory {
    // Database connection configuration
}

public class HibernateBundle<T extends Configuration> implements ConfiguredBundle<T> {
    // Hibernate ORM integration
}

public class MigrationsBundle<T extends Configuration> implements ConfiguredBundle<T> {
    // Liquibase database migrations
}

Database Integration

Metrics and Monitoring

Built-in application metrics collection, health checks, and operational endpoints for production monitoring and observability.

public class MetricRegistry {
    public Timer timer(String name);
    public Counter counter(String name);
    public Meter meter(String name);
    public Histogram histogram(String name);
}

public abstract class HealthCheck {
    public abstract Result check() throws Exception;
}

// Metric annotations
@Timed @Metered @Counted @Gauge

Metrics and Monitoring

Validation Framework

Comprehensive input validation using Bean Validation (JSR-303) with custom Dropwizard validators for durations, data sizes, and other common types.

// Built-in validation annotations
@DurationRange(min = 1, minUnit = TimeUnit.SECONDS, max = 1, maxUnit = TimeUnit.HOURS)
@DataSizeRange(min = 1, minUnit = DataSize.Unit.KILOBYTES)
@OneOf({"value1", "value2", "value3"})
@PortRange(min = 1024, max = 65535)
@ValidationMethod(message = "Custom validation failed")

Validation

Testing Support

Comprehensive testing utilities including JUnit 5 extensions for full application testing, resource testing, and database testing.

public class DropwizardAppExtension<C extends Configuration> implements BeforeAllCallback, AfterAllCallback {
    // Full application testing
}

public class ResourceExtension implements BeforeEachCallback, AfterEachCallback {
    // Resource-level testing
}

public class DAOTestExtension implements BeforeEachCallback, AfterEachCallback {
    // Database testing support
}

Testing

Bundle System

Dropwizard's bundle system provides reusable application components that can configure multiple aspects of an application. Bundles are registered during the bootstrap phase and can modify both bootstrap and runtime configuration.

Common Bundles

  • AssetsBundle: Serve static assets (CSS, JS, images) from classpath
  • ViewBundle: Template engine integration (Mustache, Freemarker)
  • MigrationsBundle: Database schema migrations
  • HibernateBundle: Hibernate ORM configuration
  • ConfiguredBundle: Bundles that require configuration access

Bundle Usage Pattern

@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets/", "/static/"));
    bootstrap.addBundle(new ViewBundle<MyConfiguration>());
    bootstrap.addBundle(new MigrationsBundle<MyConfiguration>() {
        @Override
        public DataSourceFactory getDataSourceFactory(MyConfiguration configuration) {
            return configuration.getDatabase();
        }
    });
}