Fork me on GitHub

Servlet Container Tutorial

This tutorial demonstrates the ease of embedding a WoOF application into a Servlet container. This is typically necessary to run with PaaS Cloud providers.

The tutorial will demonstrate this with a simple increment service.

Tutorial Source

Configuring for Servlet container

To run within a Servlet container, add the following dependency:


Then package the application as a war to enable being deployed to Servlet container.

Note that WoOF will run as a Filter and only intercept requests it can handle. This means existing Servlet functionality can work side by side with WoOF. Very useful for phased migration of existing Servlet applications to WoOF.

Also, WoOF does not do class path scanning. Therefore, the start times are very fast. This makes WoOF ideal for scale to zero PaaS deployments. See the OfficeFloor Subscription App for an example (code also available

Integration Test

The following integration test has the project started as follows:


This will allow the following integration test to call the WoOF application within the Servlet container to increment the value:

	private static final String SERVER_URL = "http://localhost:8999";

	public HttpClientExtension client = new HttpClientExtension();

	private final ObjectMapper mapper = new ObjectMapper();

	public void woofInput() throws Exception {

		// Create request
		HttpPost post = new HttpPost(SERVER_URL + "/increment");
		post.addHeader("Content-Type", "application/json");
		post.setEntity(new StringEntity(this.mapper.writeValueAsString(new Increment.Request("1"))));

		// Execute request
		HttpResponse response = this.client.execute(post);

		// Confirm expected response
		String entity = EntityUtils.toString(response.getEntity());
		assertEquals(200, response.getStatusLine().getStatusCode(), "Incorrect status: " + entity);
		assertEquals("application/json", response.getFirstHeader("Content-Type").getValue(), "Incorrect content type");
		Increment.Response entityResponse = this.mapper.readValue(entity, Increment.Response.class);
		assertEquals("2", entityResponse.getValue(), "Incorrect response");


The next tutorial covers REST.