Spring Web MVC Procedure Tutorial
This tutorial demonstrates configuring a Spring Web MVC Controller as a procedure.
Adding a Spring Web MVC Controller as a procedure, allows re-use of existing code. Ideally, over time, the Spring Web MVC Controllers are simplified to methods taking advantage of OfficeFloor's IoCC. However, Spring Web MVC Controllers are supported as procedures to avoid significant rewrites of application code. This enables taking advantage of OfficeFloor's features with existing Spring code.
Configuring Spring Web MVC Controller
Please see the Spring Web MVC Controller Tutorial regarding configuring Spring Web MVC Controllers into WoOF. The tutorial needs to be followed to also enable Spring Web MVC Controllers to be configured as procedures.
Configuring as a Procedure
Spring Web MVC Controller methods are configured as procedures via REST endpoint YAML files. The following configures the GET rest endpoint:
get:
resource: net.officefloor.tutorial.springwebmvchttpserver.SpringRestController
procedure: SpringWebMvcController
method: get
The path parameter endpoint:
path:
resource: net.officefloor.tutorial.springwebmvchttpserver.SpringRestController
procedure: SpringWebMvcController
method: path
The PUT endpoint:
post:
resource: net.officefloor.tutorial.springwebmvchttpserver.SpringRestController
procedure: SpringWebMvcController
method: post
The HTML page endpoint:
html:
resource: net.officefloor.tutorial.springwebmvchttpserver.SpringController
procedure: SpringWebMvcController
method: html
Note that the WoOF configured paths can be different to the Spring Web MVC Controller request mappings. The only constraint on this is that the path parameters must match.
Testing
The following tests demonstrates the procedures.
@RegisterExtension
public static final MockWoofServerExtension server = new MockWoofServerExtension();
@Test
public void get() {
MockWoofResponse response = server.send(MockWoofServer.mockRequest("/officefloor/rest"));
response.assertJson(200, new ResponseModel("GET Spring Dependency"));
}
@Test
public void pathParam() {
MockWoofResponse response = server.send(MockWoofServer.mockRequest("/officefloor/changed/parameter"));
response.assertJson(200, new ResponseModel("parameter"));
}
@Test
public void put() {
MockWoofResponse response = server
.send(MockWoofServer.mockJsonRequest(HttpMethod.PUT, "/officefloor/update", new RequestModel("INPUT")));
response.assertJson(200, new ResponseModel("INPUT"));
}
@Test
public void html() {
MockWoofResponse response = server.send(MockWoofServer.mockRequest("/officefloor/html?name=Daniel"));
response.assertResponse(200, "<html><body><p >Hello Daniel</p></body></html>");
}
Next
The next tutorial covers migrating Spring Web MVC Controllers for simpler code and avoid the dependency on Spring.

