This tutorial provides the typical steps in migrating a JAX-RS resource to avoid dependency on JAX-RS. It also enables simpler code that can take advantage of all the OfficeFloor features.
The JAX-RS resource to be migrated is taken from the previous tutorial:
@Path("/jaxrs") public class JaxRsResource { private @Inject JaxRsDependency dependency; @GET public String get() { return "GET " + this.dependency.getMessage(); } @GET @Path("/path/{param}") public ResponseModel path(@PathParam("param") String param) { return new ResponseModel(param); } @POST @Path("/update") @Consumes("application/json") @Produces("application/json") public ResponseModel post(RequestModel request) { return new ResponseModel(request.getInput()); } }
To migrate a JAX-RS resource:
The resulting migrated code is as follows:
public class MigratedResource { public void get(JaxRsDependency dependency, ServerHttpConnection connection) throws IOException { connection.getResponse().getEntityWriter().write("GET " + dependency.getMessage()); } public void path(@HttpPathParameter("param") String param, ObjectResponse<ResponseModel> response) { response.send(new ResponseModel(param)); } public void post(RequestModel request, ObjectResponse<ResponseModel> response) { response.send(new ResponseModel(request.getInput())); } }
The next tutorial covers creating quick prototype applications.