users@jersey.java.net

Re: [Jersey] custom TemplateProcessor not having its constructor injected?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 22 Apr 2009 13:21:32 +0200

On Apr 22, 2009, at 1:11 PM, James Strachan wrote:

> I tried creating a custom TemplateProcessor instance like the
> JSPTemplateProcessor using a similar constructor... (I'm experimenting
> using LiftWeb.net's templates with Jersey 1.0.3 - I'm slowly being
> drawn to scala...)
>

I have been drawn to Scala too and wondered if the lift type templates/
snippets could be integrated.

I think there is some potential to provide some nice Scala wrappers on
some stuff, and use of partial functions for resource methods. The
only current down side is a compiler bug that stops the client side
being used :-(


> My class declaration mirrors that of JSPTemplateProcessor.... Yet the
> constructor parameters are all null. Any ideas what I'm doing wrong? I
> notice JSPTemplateProcessor isn't annotated with @Provider - so is
> this special injection only available to JSPTemplateProcessor?
>
>
> @Provider
> public class LiftTemplateProcessor implements TemplateProcessor {
> @Context
> HttpContext hc;
>
> @Context
> ServletContext servletContext;
>
> @Context
> UriInfo ui;
>
> private final ThreadLocal<HttpServletRequest> requestInvoker;
>
> private final ThreadLocal<HttpServletResponse> responseInvoker;
>
> private final String basePath;
>
> public LiftTemplateProcessor(
> ResourceConfig resourceConfig,
> ThreadLocal<HttpServletRequest> requestInvoker,
> ThreadLocal<HttpServletResponse> responseInvoker) {
>
>

Try adding @Context to all three constructor parameters.

The JSPTemplateProcessor is a little special in that it is added as a
singleton to the resource config and was developed before i created
injectable providers for the thread locals of the servlet request and
response (the reason why those are required is because GF/Tomcat does
not like using the proxy instances when forwarding).

Paul.