Fork me on GitHub

JEE Servlet Container within WoOF Tutorial

This tutorial demonstrates running JEE Servlet functionality within a WoOF web application.

Download Tutorial Source

Extending WoOF application for Servlet functionality

The ServletContainerWoofApplicationExtensionService provides extension to a WoOF application by detecting the presence of a web.xml file following standard Maven war project structure or standard JEE Servlet *.war packaging. On detecting this file, it will load a chained servicer containing the configured Servlet functionality.

This occurs automatically by the inclusion of the following dependencies on the class path:

			<!-- Necessary for non-interface JEE dependencies -->

The result is that any unhandled HTTP request by the WoOF functionality is sent to this servicer. This servicer attempts to service the HTTP request with the web.xml configured Servlet functionality.

Should the HTTP request not be handled by the Servlet functionality then the last chained servicer is used. The last chained servicer attempts to send a corresponding static resource by URI or a 404 if no corresponding resource.

Servlet functionality

The following provides the configuration of the web.xml Servlet functionality for this tutorial:

<?xml version="1.0" encoding="UTF-8"?>



Servlet functionality supported by the WoOF extension is:

  • Filters
  • Servlets
  • MIME mappings

Note that the intention is not to rebuild another JEE Server. The intention is provide enough Servlet Container functionality to embed existing JEE Servlet Applications within WoOF so that they do not need to be fully migrated to WoOF functionality.

The configured Servlet is as follows:

public class ExampleHttpServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {


Unit Test

The unit test highlights the servicing of the HTTP request by the Servlet functionality.

	public void testExampleHttpServlet() throws Exception {

		// Start WoOF (with Servlet extension on class path)

		// Undertake the request to be serviced by Servlet
		HttpGet request = new HttpGet("http://localhost:7878/example");
		HttpResponse response = this.client.execute(request);
		assertEquals("Ensure request successful", 200, response.getStatusLine()

		// Ensure response entity is as expected
		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
		assertEquals("Incorrect response entity", "SERVLET", buffer.toString());


The next tutorial looks at migrating an existing JEE Servlet Application to run within OfficeFloor as a WoOF Application.