Dropwizard Forms

The dropwizard-forms module provides you with a support for multi-part forms via Jersey.

Adding The Bundle

Then, in your application’s initialize method, add a new MultiPartBundle subclass:

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
    bootstrap.addBundle(new MultiPartBundle());
}

Testing

To test resources that utilize multi-part form features, one must add MultiPartFeature.class to the ResourceExtension as a provider, and register it on the client like the following:

@ExtendWith(DropwizardExtensionsSupport.class)
public class MultiPartTest {

    public static final ResourceExtension resourceExtension = ResourceExtension.builder()
            .addProvider(MultiPartFeature.class)
            .addResource(new TestResource())
            .build();

    @Test
    public void testClientMultipart() {
        final FormDataMultiPart multiPart = new FormDataMultiPart()
                .field("test-data", "Hello Multipart");
        final String response = resourceExtension.target("/test")
                .register(MultiPartFeature.class)
                .request()
                .post(Entity.entity(multiPart, multiPart.getMediaType()), String.class);
        assertThat(response).isEqualTo("Hello Multipart");
    }

    @Path("test")
    public static class TestResource {
        @POST
        @Consumes(MediaType.MULTIPART_FORM_DATA)
        public String post(@FormDataParam("test-data") String testData) {
            return testData;
        }
    }
}

More Information

For additional and more detailed documentation about the Jersey multi-part support, please refer to the documentation in the Jersey User Guide and Javadoc.