Fork me on GitHub

JAX-RS Procedure Tutorial

This tutorial demonstrates configuring a JAX-RS end point method as a procedure.

Adding a JAX-RS end point method as a procedure, allows re-use of existing code. Ideally, over time, the JAX-RS resources are simplified to methods taking advantage of OfficeFloor's IoCC. However, JAX-RS is supported as procedures to avoid significant rewrites of application code. This enables taking advantage of OfficeFloor's features with existing JAX-RS code.

Tutorial Source

Configuring JAX-RS

Please see the JAX-RS Tutorial regarding configuring JAX-RS resources into WoOF. The tutorial needs to be followed to also enable JAX-RS end point methods to be configured as procedures.

Configuring as a Procedure

JAX-RS resource methods are configured as procedures via REST endpoint YAML files. The following configures the GET officefloor endpoint:

get:
  resource: net.officefloor.tutorial.jaxrshttpserver.JaxRsResource
  procedure: JAXRS
  method: get

The path parameter endpoint:

path:
  resource: net.officefloor.tutorial.jaxrshttpserver.JaxRsResource
  procedure: JAXRS
  method: path

The PUT endpoint:

post:
  resource: net.officefloor.tutorial.jaxrshttpserver.JaxRsResource
  procedure: JAXRS
  method: post

Note that the WoOF configured paths can be different to the JAX-RS end point 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"));
		response.assertResponse(200, "GET OfficeFloor Dependency");
	}

	@Test
	public void pathParam() {
		MockWoofResponse response = server.send(MockWoofServer.mockRequest("/officefloor/changed/parameter"));
		response.assertJson(200, new ResponseModel("parameter"));
	}

	@Test
	public void post() {
		MockWoofResponse response = server
				.send(MockWoofServer.mockJsonRequest(HttpMethod.PUT, "/officefloor/update", new RequestModel("INPUT")));
		response.assertJson(200, new ResponseModel("INPUT"));
	}

Next

The next tutorial covers migrating JAX-RS for simpler code.