users@jersey.java.net

Re: [Jersey] Accessing ServletContext or ServletConfig from a Provider

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 09 Mar 2009 18:42:22 +0100

On Mar 9, 2009, at 2:34 PM, Erdinc Yilmazel wrote:

> I am writing a MessageBodyWriter for a custom format and annotated the
> implementation class @Provider. Is there any way to access to the
> ServletContext or ServletConfig of a web application? What I want to
> do is access some init-param's from the web.xml.
>

You can inject:

   @Context ServletContext sc;

or

   @Context ServletConfig sc;

on to a field or on to a constructor parameter.

See the following for more details:

   http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features#OverviewofJAX-RS1.0Features-Useof
@Context

Alternatively you could use:

   @Context ResourceConfig rc;

any servlet init-params are copied across as properties on the
ResourceConfig, plus any init-params that are boolean values are
copied across as features.

Paul.

[1] http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features


> Regards,
>
> Erdinc
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>