WoOF within JEE Servlet Container Tutorial

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

Download Tutorial Source


The WoofServletFilter is a Servlet Filter which provides the necessary hooks for running WoOF within a JEE Servlet container.

The following is the configuration for this tutorial.

application.woof configuration.

The above configuration provides the following:

  • OfficeFloor dynamic web template
  • Rendering of a JSP (by the Servlet container) as a navigation link from the above web template
  • Utilising a class method example(...) to service the uri /class

For further explanation of the above WoOF configuration see the previous tutorials.

Within a JEE Servlet Container WoOF defers to the JEE Servlet Container to provide the resources. The ability to link to Servlet container resources (e.g. JSPs, Servlets, static pages, etc) is provided to allow introducing WoOF into JEE web applications without having to rewrite the web applications. WoOF will also happily co-exist with other frameworks within a Servlet container.


The following highlighted configuration adds the WoofServletFilter to the web.xml for running WoOF within the Servlet container.

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




WoOF's filter mapping should be /* so that it can intercept each request. WoOF will however only service the requests it is configured to handle and let the Servlet application handle the rest.


As per the above configuration, the following class directly handles a web request.

public class ExampleClass {

	public void example(ServerHttpConnection connection) throws IOException {
		Writer writer = new OutputStreamWriter(connection.getHttpResponse()


Running within a JEE Servlet container the ServerHttpConnection implementation wraps the ServletRequest and ServletResponse so that existing stand-alone WoOF applications can be run. It is the re-implementing of the base WoOF objects ( ServerHttpConnection , HttpSession ) to use the JEE Servlet Container APIs that the JEE Servlet integration is achieved.

Remaining Code

For completeness of this tutorial the remaining code is included below.


Has the #{link} for handling by ExampleTemplateLogic.

<html><body><a href="#{link}">TEMPLATE</a></body></html><html><body><a href="#{link}">TEMPLATE</a></body></html>


Identifies that the link in the above template should be handled by the LINK output. The above configuration maps this to a JSP for the response.

public class ExampleTemplateLogic {

	public void link() {



JSP run by Servlet Container. WoOF navigates to this JSP in the above configuration.

<html><body>Linked to JSP</body></html>


This is included to know when a request is being serviced by the Servlet container (and not OfficeFloor).

public class MockHttpServlet extends HttpServlet {

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


Unit Test

The unit test highlights the servicing of a request by:

  • Servlet container (for request not to be handled by WoOF as per its configuration)
  • WoOF dynamic template
  • Dynamic template link to be serviced by a JSP from the Servlet container
  • Request being serviced by a class
    public class ExampleIT extends TestCase {
    	private final HttpClient client = new DefaultHttpClient();
    	public void testUnhandled() throws IOException {
    		this.assertRequest("/unhandled", "SERVLET");
    	public void testHttpTemplateAndLinkToJsp() throws IOException {
    				"<html><body><a href=\"/template.links-link.task\">TEMPLATE</a></body></html>");
    	public void testLinkToJsp() throws IOException {
    				"<html><body>Linked to JSP</body></html>");
    	public void testClass() throws IOException {
    		this.assertRequest("/class", "<html><body>CLASS</body></html>");
    	private void assertRequest(String uri, String expectedContent)
    			throws IOException {
    		// Undertake the request
    		HttpGet request = new HttpGet("http://localhost:18080" + uri);
    		HttpResponse response = this.client.execute(request);
    		assertEquals("Request should be successful: " + uri, 200, response
    		// Ensure content is as expected
    		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    		assertEquals("Incorrect response entity", expectedContent,


The next tutorial looks at making use of existing Java Server Pages (JSP).