Use Consul's KV store for Dropwizard settings

I wanted to see how hard it would be to get Dropwizard config from Consul’s key value store. Turns out it is very easy to do! Make sure you’re using Dropwizard >= 0.8.0, this has the SubstitutingSourceProvider that we’re going to use. Create a default Dropwizard project with the following configuration line in its config.yml: someSetting: ${settings/someSetting} Don’t forget to add it to the xxxConfiguration: @JsonProperty @NotEmpty private String someSetting; Now in the xxxApplication class, register a new ConsulKVSubstitutor in the initialize method: »

File upload using Dropwizard 0.8.0-rc2

Dropwizard 0.7.1 used com.sun.jersey:jersey-server:jar:1.18.1, where version 0.8.0 comes with org.glassfish.jersey.core:jersey-server:jar:2.15. Before, when uploading files, it was enough to add the com.sun.jersey.contribs:jersey-multipart dependency like so: <dependency> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-multipart</artifactId> <version>1.18.3</version> </dependency> This will not work anymore and throws the somewhat cryptic exception: java.lang.IllegalArgumentException: The MultiPartConfig instance we expected is not present. Have you registered the MultiPartConfigProvider class? The correct dependency should be <dependency> <groupId></groupId> <artifactId>jersey-media-multipart</artifactId> <version>2.15</version> </dependency> Update your imports and you’re good to go. »

Start Postgres container and connect with JDBC

Quick example of how to set up a Docker container with Postgresql, using the Spotify Docker Java client. This supposes a running Docker installation on your local computer, for example using boot2docker. import; import; import com.spotify.docker.client.DefaultDockerClient; import com.spotify.docker.client.DockerCertificateException; import com.spotify.docker.client.DockerClient; import com.spotify.docker.client.DockerException; import com.spotify.docker.client.messages.ContainerConfig; import com.spotify.docker.client.messages.ContainerCreation; import com.spotify.docker.client.messages.ContainerInfo; import com.spotify.docker.client.messages.HostConfig; import lombok.extern.slf4j.Slf4j; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @Slf4j public abstract class PostgresContainerExample { public static Connection setUpDbContainer() throws SQLException { try { // This will only work with the DOCKER_HOST environment variable set final DockerClient docker = DefaultDockerClient. »