Ticket #31 (new task)
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:
- 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.
- return a domain object and implement a custom MessageBodyWriter?
- implement a system that automatically finds a template based on the [resource class or returned object] class name.
- 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.
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.