CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-dropwizard--dropwizard-core

Core components of the Dropwizard framework for building Java web applications

Pending
Overview
Eval results
Files

server-config.mddocs/

Server Configuration

Dropwizard's pluggable server factory system supports different deployment patterns with configurable connectors, thread pools, and server implementations.

Capabilities

ServerFactory Interface

Base interface for building Jetty servers with pluggable implementations supporting different deployment patterns.

/**
 * A factory for building Server instances for Dropwizard applications.
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = DefaultServerFactory.class)
public interface ServerFactory extends Discoverable {
    /**
     * Build a server for the given Dropwizard application.
     * @param environment the application's environment
     * @return a Server running the Dropwizard application
     */
    Server build(Environment environment);
    
    /**
     * Configures the given environment with settings defined in the factory.
     * @param environment the application's environment
     */
    void configure(Environment environment);
}

The @JsonTypeInfo annotation enables polymorphic JSON deserialization based on the "type" property in configuration.

DefaultServerFactory

Multi-connector server factory supporting separate application and admin connectors on different ports. This is the default and recommended configuration for production deployments.

/**
 * Default server factory with separate application and admin connectors.
 */
@JsonTypeName("default")
public class DefaultServerFactory extends AbstractServerFactory {
    /**
     * Returns the application connectors.
     * @return list of application connectors
     */
    @JsonProperty("applicationConnectors")
    public List<ConnectorFactory> getApplicationConnectors();
    
    /**
     * Sets the application connectors.
     * @param connectors the application connectors
     */
    @JsonProperty("applicationConnectors")
    public void setApplicationConnectors(List<ConnectorFactory> connectors);
    
    /**
     * Returns the admin connectors.
     * @return list of admin connectors
     */
    @JsonProperty("adminConnectors")
    public List<ConnectorFactory> getAdminConnectors();
    
    /**
     * Sets the admin connectors.
     * @param connectors the admin connectors
     */
    @JsonProperty("adminConnectors")
    public void setAdminConnectors(List<ConnectorFactory> connectors);
    
    /**
     * Returns the admin maximum threads.
     * @return admin max threads
     */
    @JsonProperty("adminMaxThreads")
    public int getAdminMaxThreads();
    
    /**
     * Sets the admin maximum threads.
     * @param threads the admin max threads
     */
    @JsonProperty("adminMaxThreads")
    public void setAdminMaxThreads(int threads);
    
    /**
     * Returns the admin minimum threads.
     * @return admin min threads
     */
    @JsonProperty("adminMinThreads")
    public int getAdminMinThreads();
    
    /**
     * Sets the admin minimum threads.
     * @param threads the admin min threads
     */
    @JsonProperty("adminMinThreads")
    public void setAdminMinThreads(int threads);
}

Configuration Example:

server:
  type: default
  applicationConnectors:
    - type: http
      port: 8080
      bindHost: 0.0.0.0
    - type: https
      port: 8443
      keyStorePath: /path/to/keystore.jks
      keyStorePassword: password
  adminConnectors:
    - type: http
      port: 8081
      bindHost: 127.0.0.1
  adminMaxThreads: 64
  adminMinThreads: 1
  maxThreads: 1024
  minThreads: 8

SimpleServerFactory

Single-connector server factory that combines application and admin interfaces on the same port and connector. Useful for development and simple deployments.

/**
 * Simple server factory with a single connector for both application and admin.
 */
@JsonTypeName("simple")
public class SimpleServerFactory extends AbstractServerFactory {
    /**
     * Returns the connector configuration.
     * @return the connector factory
     */
    @JsonProperty("connector")
    public ConnectorFactory getConnector();
    
    /**
     * Sets the connector configuration.
     * @param factory the connector factory
     */
    @JsonProperty("connector")
    public void setConnector(ConnectorFactory factory);
    
    /**
     * Returns the application context path.
     * @return the application context path
     */
    @JsonProperty("applicationContextPath")
    public String getApplicationContextPath();
    
    /**
     * Sets the application context path.
     * @param contextPath the application context path
     */
    @JsonProperty("applicationContextPath")
    public void setApplicationContextPath(String contextPath);
    
    /**
     * Returns the admin context path.
     * @return the admin context path
     */
    @JsonProperty("adminContextPath")
    public String getAdminContextPath();
    
    /**
     * Sets the admin context path.
     * @param contextPath the admin context path
     */
    @JsonProperty("adminContextPath")
    public void setAdminContextPath(String contextPath);
}

Configuration Example:

server:
  type: simple
  connector:
    type: http
    port: 9000
    bindHost: 0.0.0.0
  applicationContextPath: /api
  adminContextPath: /admin
  maxThreads: 1024
  minThreads: 8

Usage Examples:

With simple server configuration, your application and admin interfaces are available at:

  • Application: http://localhost:9000/api/
  • Admin: http://localhost:9000/admin/

AbstractServerFactory

Base class providing common server configuration shared by both DefaultServerFactory and SimpleServerFactory.

/**
 * Base server factory implementation with common configuration.
 */
public abstract class AbstractServerFactory implements ServerFactory {
    /**
     * Returns the maximum number of threads.
     * @return max threads
     */
    @JsonProperty("maxThreads")
    public int getMaxThreads();
    
    /**
     * Sets the maximum number of threads.
     * @param count the max threads
     */
    @JsonProperty("maxThreads") 
    public void setMaxThreads(int count);
    
    /**
     * Returns the minimum number of threads.
     * @return min threads
     */
    @JsonProperty("minThreads")
    public int getMinThreads();
    
    /**
     * Sets the minimum number of threads.
     * @param count the min threads
     */
    @JsonProperty("minThreads")
    public void setMinThreads(int count);
    
    /**
     * Returns the max queued requests.
     * @return max queued requests
     */
    @JsonProperty("maxQueuedRequests")
    public int getMaxQueuedRequests();
    
    /**
     * Sets the max queued requests.
     * @param maxQueuedRequests the max queued requests
     */
    @JsonProperty("maxQueuedRequests")
    public void setMaxQueuedRequests(int maxQueuedRequests);
    
    /**
     * Returns the idle thread timeout.
     * @return idle thread timeout duration
     */
    @JsonProperty("idleThreadTimeout")
    public Duration getIdleThreadTimeout();
    
    /**
     * Sets the idle thread timeout.
     * @param idleThreadTimeout the idle thread timeout
     */
    @JsonProperty("idleThreadTimeout")
    public void setIdleThreadTimeout(Duration idleThreadTimeout);
    
    /**
     * Returns whether detailed dump is enabled.
     * @return true if detailed dump is enabled
     */
    @JsonProperty("detailedJsonParseExceptionMessages")
    public boolean isDetailedJsonParseExceptionMessages();
    
    /**
     * Sets whether detailed dump is enabled.
     * @param detailed true to enable detailed messages
     */
    @JsonProperty("detailedJsonParseExceptionMessages")
    public void setDetailedJsonParseExceptionMessages(boolean detailed);
    
    /**
     * Returns the server push filter factory.
     * @return the server push filter factory (nullable)
     */
    @JsonProperty("serverPush")
    public ServerPushFilterFactory getServerPush();
    
    /**
     * Sets the server push filter factory.
     * @param serverPush the server push filter factory
     */
    @JsonProperty("serverPush")
    public void setServerPush(ServerPushFilterFactory serverPush);
    
    /**
     * Returns whether graceful shutdown is enabled.
     * @return true if graceful shutdown is enabled
     */
    @JsonProperty("shutdownGracePeriod")
    public Duration getShutdownGracePeriod();
    
    /**
     * Sets the graceful shutdown period.
     * @param shutdownGracePeriod the shutdown grace period
     */
    @JsonProperty("shutdownGracePeriod")
    public void setShutdownGracePeriod(Duration shutdownGracePeriod);
    
    /**
     * Returns whether to dump heap on OutOfMemoryError.
     * @return true if heap dump on OOM is enabled
     */
    @JsonProperty("dumpHeapOnOOM")
    public boolean isDumpHeapOnOOM();
    
    /**
     * Sets whether to dump heap on OutOfMemoryError.
     * @param dumpHeapOnOOM true to enable heap dump on OOM
     */
    @JsonProperty("dumpHeapOnOOM")
    public void setDumpHeapOnOOM(boolean dumpHeapOnOOM);
}

Server Configuration Examples

Production Configuration (Default Server Factory)

server:
  type: default
  maxThreads: 1024
  minThreads: 8
  maxQueuedRequests: 1024
  idleThreadTimeout: 1 minute
  shutdownGracePeriod: 30 seconds
  
  applicationConnectors:
    - type: http
      port: 8080
      bindHost: 0.0.0.0
      idleTimeout: 30 seconds
      soLingerTime: -1s
      reuseAddress: true
      useServerHeader: false
      useDateHeader: false
      useForwardedHeaders: true
      
  adminConnectors:
    - type: http
      port: 8081
      bindHost: 127.0.0.1
      
  adminMaxThreads: 64
  adminMinThreads: 1

Development Configuration (Simple Server Factory)

server:
  type: simple
  applicationContextPath: /api
  adminContextPath: /admin
  connector:
    type: http
    port: 8080
    bindHost: localhost
  maxThreads: 100
  minThreads: 4

HTTPS Configuration

server:
  type: default
  applicationConnectors:
    - type: https
      port: 8443
      keyStorePath: /etc/ssl/dropwizard.jks
      keyStorePassword: changeit
      trustStorePath: /etc/ssl/dropwizard.jks
      trustStorePassword: changeit
      keyManagerPassword: changeit
      needClientAuth: false
      wantClientAuth: false
      certAlias: dropwizard
      crlPath: /etc/ssl/crl.pem
      enableCRLDP: false
      enableOCSP: false
      maxCertPathLength: -1
      ocspResponderUrl: http://winqa2003-ocsp.mlbcorp.net/ocsp
      jceProvider: BC
      validateCerts: true
      validatePeers: true
      supportedProtocols: [TLSv1.1, TLSv1.2]
      excludedProtocols: []
      supportedCipherSuites: []
      excludedCipherSuites: []
      allowRenegotiation: true
      endpointIdentificationAlgorithm: HTTPS
      
  adminConnectors:
    - type: http
      port: 8081
      bindHost: 127.0.0.1

Custom Server Factory

You can create custom server factories by implementing the ServerFactory interface:

@JsonTypeName("custom")
public class CustomServerFactory implements ServerFactory {
    @Override
    public Server build(Environment environment) {
        // Build custom Jetty server
        final QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setMinThreads(8);
        threadPool.setMaxThreads(512);
        
        final Server server = new Server(threadPool);
        
        // Add custom connectors and handlers
        // ...
        
        return server;
    }
    
    @Override
    public void configure(Environment environment) {
        // Configure environment with custom settings
    }
}

// Register in your application
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
    // Register custom server factory for JSON type resolution
    bootstrap.getObjectMapper().getSubtypeResolver()
        .registerSubtypes(CustomServerFactory.class);
}

Types

// Jetty Server and related types
public class Server {
    public void start() throws Exception;
    public void stop() throws Exception;
    public void join() throws InterruptedException;
}

// Connector factories for different protocols
public interface ConnectorFactory {
    Connector build(Server server, MetricRegistry metrics, String name, ThreadPool threadPool);
}

public class HttpConnectorFactory implements ConnectorFactory {
    // HTTP connector configuration
}

public class HttpsConnectorFactory extends HttpConnectorFactory {
    // HTTPS connector configuration  
}

// Thread pool configuration
public class QueuedThreadPool extends AbstractLifeCycle implements ThreadPool {
    public void setMinThreads(int minThreads);
    public void setMaxThreads(int maxThreads);
    public void setIdleTimeout(int idleTimeout);
}

// Duration for timeouts and intervals
public class Duration {
    public static Duration minutes(long minutes);
    public static Duration seconds(long seconds);
    public static Duration milliseconds(long milliseconds);
}

Install with Tessl CLI

npx tessl i tessl/maven-io-dropwizard--dropwizard-core

docs

bundles.md

cli.md

core-application.md

environment-setup.md

index.md

server-config.md

tile.json