users@jersey.java.net

Re: [Jersey] Newbie question: How do I inject objects into resources

From: Ian Clarke <ian.clarke_at_gmail.com>
Date: Tue, 24 Mar 2009 08:48:00 -0500

On Tue, Mar 24, 2009 at 8:44 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> See here for some more details on injection:
>
>
> http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features#OverviewofJAX-RS1.0Features-RulesofInjection
>

Thanks Paul, ok - I think I understand how to retrieve the ServletContext
(and then retrieve objects from this using ServletContext.getAttribute() ),
however how do I put objects into it?

Here is how I'm setting up the server:

        final Map<String, String> initParams = new HashMap<String,
String>();

        initParams.put("com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig");
        initParams.put("com.sun.jersey.config.property.packages",
"com.uprizer.sensearray.io.net.resources");

        log.info("Starting Sensearray Server...");
        return GrizzlyWebContainerFactory.create(baseUri, initParams);

Given this, how do I access the ServletContext so that I can add the
attributes I need to it?

Thanks again,

Ian.

-- 
Ian Clarke
CEO, Uprizer Labs
Email: ian_at_uprizer.com
Ph: +1 512 422 3588
Fax: +1 512 276 6674