Running WoOF Stand-Alone Tutorial
This tutorial covers the basic layout of a web application and how to run the web application.
To demonstrate this the tutorial will illustrate starting a HTTP server and have it respond with the following static index.html page:

You may skip ahead to the next tutorial to look a dynamic content as this tutorial covers some very basics regarding static content. Later you can come back to this tutorial for running a WoOF (Web on OfficeFloor) application.
This tutorial will require downloading the Tutorial Source to have it available to run.
The following is the example's jar layout:
+- PUBLIC/ (contents public)
| +- index.html
| +- images/
| | +- banner.png
| +- css/
| +- site.css
+- net/ (contents not public)
| +- officefloor/
| +- tutorial/
| +- Example.class
+- application.woofNote that only files under the PUBLIC directory will be made available which keeps the code private (e.g. the net.officefloor.tutorial.Example and application.woof files will not be visible). This structure also allows using the jar normally on a class path without any special class loading - unlike the WAR layout that requires special class loading to access its contained classes.
When using WoOF within a JEE Servlet Container, WoOF will respect the WAR layout and obtain web content from the top level and classes from the respective WEB-INF directories. This enables both easier integration of WoOF into your existing Servlet applications and also lets you use standard build tools (such as Maven) to continue to create the WAR. There are no special build steps required to integrate WoOF into existing Servlet applications.
A Maven plug-in is available to run the web application using the following command:
mvn woof:run
To ensure the plug-in can be found you may need to add the following to your Maven settings.xml file:
<settings>
...
<pluginGroups>
<pluginGroup>net.officefloor.maven</pluginGroup>
</pluginGroups>
...
</settings>The above command will start a HTTP Server on the default port 7878 (i.e. http://localhost:7878) servicing files from the class path under the PUBLIC directory.
Running the above command will actually start two processes.
The first process is the OfficeBuilding which is a central control process. Rather than having a single process which hosts each application that must be run, OfficeFloor has a central process (OfficeBuilding) which spawns each application (OfficeFloor) to run in its own process. This central control process, OfficeBuilding, will expose JMX beans for controlling the OfficeFloor instances on port 13778. The above command will ensure OfficeBuilding is running and then start the web application.
The second process is an OfficeFloor process which is the actual Web Application. It is possible to run this without OfficeBuiling by using the main class WoofOfficeFloorSource. The advantage of using the OfficeBuilding is that OfficeFloor integrates with Maven to take advantage of the Maven repositories to obtain the artifacts and add them to the class path to run the application. Therefore there is no need to package your application to run it - making it much faster to run the code just developed. It also enables easier management of applications on a grid as the OfficeBuilding process acts as an agent on each grid node that can start any application by downloading the necessary artifacts from a Maven repository - further discussion of this however is beyond the scope of this tutorial.
To stop the OfficeBuilding and the OfficeFloor instances running within it, use the following command:
mvn officefloor:stop
Unit testing your code should always be made easy and this is also the case for web applications. The following unit tests shows how to start the web application, request the index.html page and then stop it.
protected void setUp() throws Exception {
WoofOfficeFloorSource.main();
}
Starts the example HTTP Server.
public void testStaticFile() throws Exception {
// Send request for 'index.html'
HttpResponse response = new DefaultHttpClient().execute(new HttpGet(
"http://localhost:7878/index.html"));
// Ensure request is successful
assertEquals("Request should be successful", 200, response
.getStatusLine().getStatusCode());
// Indicate content of 'index.html'
response.getEntity().writeTo(System.out);
}
Requests index.html from the HTTP Server.
protected void tearDown() throws Exception {
AutoWireManagement.closeAllOfficeFloors();
}
As the code to run the HTTP Server is contained within the main method, the AutoWireManagement provides means to stop the HTTP Server via JMX. This means that the unit test code need not maintain reference to the underlying OfficeFloor for closing between tests.
See the other tutorials for the features of OfficeFloor.