Ticket #31 (new task)

Opened 5 years ago

Last modified 4 years ago

Some mechanism for using templates to render JAX-RS responses

Reported by: bruno Owned by: bruno
Priority: minor Milestone: 0.5
Component: modules/kauri-routing Version: trunk
Keywords: Cc:

Description

The problem: how to use JAX-RS in situations where you want to render a response using a template (or similar view-technology such as an xml pipeline)?

Different approaches are imaginable:

  1. return a TemplateResponse? object for which an accompanying TemplateResponseWriter? (= a JAX-RS provider) is implemented. This is somewhat similar to the TemplateRepresentation? which the template service currently provides.
  2. return a domain object and implement a custom MessageBodyWriter?
  3. implement a system that automatically finds a template based on the [resource class or returned object] class name.
  4. allow to add "annotations" to templates which indicate that they are the view for a certain type of object, and dynamically create and configure MessageBodyWriters? for those templates. This is a sort-of non-Java way to implement custom MessageBodyWriters?

The first approach makes that the resource class is very much tied to the template response. OTOH, it allows to put the context data for the template in the TemplateResponse? object.

Most of the other approaches assume a domain object is returned, which rather severely limits the data passed to the template.

Jersey (= JAX-RS ref impl) seems to have a mechanism whereby a template is derived from the resource class name, and the resource class itself is passed on as the template data. I don't understand too much about their samples though since they don't even have @GET/@HttpMethod? annotations, which I thought were required.

By comparison, in Cocoon (and probably many web-frameworks) the view is, at the end of an apple/flowscript, identified by a name/path and allows to pass a map of data. This allows to nicely control what data is passed to the view, and doesn't hardcode the view implementation in the controller.

Change History

comment:1 Changed 5 years ago by bruno

Update: I've meanwhile learned that Restlet's JAX-RS implementation allows to return Restlet Representation objects from JAX-RS classes. So the TemplateService?'s existing support for creating Restlet Representations can also be used in JAX-RS classes.

comment:2 Changed 4 years ago by mpo

  • Milestone set to 0.5
Note: See TracTickets for help on using tickets.