Xumulus Logo
Engineering

WebCenter Sites 12c Controllers as REST Endpoints

Author

Dan Kozlowski

Date Published

In WebCenter Sites 12c you can expose controllers directly as REST services, avoiding the need to create separate template entities just to render results. Controllers can be defined as REST resources, and the @Path annotation on any method defines a subresource that is scanned dynamically and made available as an endpoint.

1@Path("/hello")
2@GET
3@Produces("text/plain")
4public String hello() { return "Hello World"; }
5
6@Path("/register")
7@POST
8@Consumes("application/x-www-form-urlencoded")
9public Response register(@FormParam("email") String email,
10 @FormParam("password") String password,
11 @FormParam("age") int age) { /* ... */ }

An HTML form can then POST to a URL like http://localhost:8080/cs/REST/controller/cServices/register.

JAX-RS annotations used

  • @GET and @POST specify the HTTP method.
  • @Produces and @Consumes specify the MIME media types.
  • @FormParam retrieves form parameters.

WebCenter Sites uses the Jersey implementation of RESTful web services — see the Jersey user guide for more on POST handling and other REST verbs.