users@jersey.java.net

Re: small questions about configuration, Reader, external executable

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 04 Apr 2008 10:38:15 +0200

On Apr 3, 2008, at 10:28 PM, Gabor Szokoli wrote:

> Hi,
>
> I know it's been a while, but we just moved to jersey 0.6, and I
> noticed my ResourceConfig instance is null.
> Both in the constructor, and my GET method, does not get injected I
> guess.

It should work for fields, see the unit test

   com.sun.ws.rest.impl.inject.AllInjectablesTest

but may be i only fixed this properly for 0.7, i cannot remember....

Note that this cannot be injected on to constructor or method
parameters. The (faulty) logic was that only request-related @Context
stuff would be injected onto parameters of constructors or methods.
But i think we should fix that.


> So I moved back to 0.5, and noticed it never has been, I just had a
> fallback :-)
> I don't see anything suspicious in the logs, but I'm not sure what I'm
> looking for.
> So my question is: what should I be looking for to track this
> down? :-)
>

If it does not work for fields in 0.6 a work around is to extend
ServletConfig and add your own ResourceConfig injectable.

protected void configure(final ServletConfig sc, ResourceConfig rc,
WebApplication wa) {
    // Configure for ServletContainer
    super.configure(sc, rc, wa);
    // Create injectable for resource config
    // See code in WebApplicationImpl for example
    Injectable rc = ...
    wa.addIjectable(rc);
}

To support injection onto fields: See my previous email to Martin on
ParameterProcessor's that may help i.e. the
HttpContextParameterProcessor could support all the other field-based
injected stuff that is currently not possible, namely:

   ResourceConfig, MessageBodyContext, HttpContext, TemplateContext
(and when using Servlet, the servlet stuff).

Note that we are not required to thread local proxy the instances for
parameters and per-request information like UriInfo are not thread
proxied for parameters, only for fields (strictly speaking we are not
required to do that for per-request life-cycle, but we do, and should
fix that) so there needs to be some code distinction when to use
thread-local proxied injected stuff or otherwise.

Paul.

> Linux, Glassfish v2, Jersey 0.5 or 0.6 deploying via ServletContainer.
>
> On 3/4/08, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>>
>> Any init-param name and value automatically gets added to the
>> ResourceConfig properties map, the values get added as String
>> instances.
>>
>> You can then inject a ResourceConfig onto your class:
>>
>> @Path("/")
>> public class Resource {
>> @Context ResourceConfig rc;
>>
>> @GET public String get() {
>> return
>> rc.getProperties().get("my-servlet-init-param-property");
>> }
>> }
>>
>
> Thanks!
>
> Gabor Szokoli
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>