users@jersey.java.net

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

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

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

> 2009/4/22 James Strachan <james.strachan_at_gmail.com>:
>> 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...)
>>
>> 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) {
>
>
> Just to answer my own question - DOH - not enough coffee! (Note to
> self - have another cup before posting...)
>
> The trick is not to use the JSPTemplateProcessor's style of
> constructor, but just inject the required attributes...
>
> @Context
> HttpServletRequest request;
>
> @Context
> HttpServletResponse response;
>
> I wonder if its worth adding a little comment to the constructor of
> JSPTemplateProcessor to help avoid other folks not having had much
> coffee and copy and pasting that constructor code then scratching
> their heads when all the parameters are null?
>

I will do one better and modify it to be a proper component using
@Context for injection on the constructor parameters and registering
in the set of classes of the resource config.

Paul.

> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://fusesource.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>