users@jersey.java.net

[Jersey] Re: Jersey2: How to pass parameters from web.xml to the Application?

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Fri, 25 Oct 2013 17:50:35 -0400

Brian,

     I'm trying to look up the parameter value from inside a class that
extends ResourceConfig. I don't have access to ServletConfig from there,
do I? This is in spite of the fact that Jersey is running on top of
ServletContainer.

Gili

On 25/10/2013 5:44 PM, Van Klaveren, Brian N. wrote:
> In web.xml:
>
> <context-param>
> <param-name>maybeDebug</param-name>
> <param-value>nope</param-value>
> </context-param>
>
>
> In servlet:
> String maybeDebug = getServletConfig().getInitParameter(“maybeDebug”);
>
> In non-servlet:
> InitialContext context = new InitialContext();
> String paramValue = (String) context.lookup("java:comp/env/maybeDebug");
>
>
> Brian
>
> On Oct 25, 2013, at 2:24 PM, cowwoc <cowwoc_at_bbs.darktech.org> wrote:
>
>> Jeez. That's very ugly.
>>
>> Isn't there a way for me to pass variables from web.xml to
>> ServletContainer and from there to ResourceConfig.getProperties()? I
>> haven't tried this yet because the migration process is not complete,
>> but surely there should be a way to do this using existing Jersey
>> mechanisms...?
>>
>> Gili
>>
>> On 25/10/2013 4:42 PM, Joseph Mocker wrote:
>>> A slightly more elegant way than Ivar’s suggestion would be to put a properties file in the classpath somewhere (for example, with Tomcat, you could put it in tomcat’s lib/) folder, then in your ResourceConfig, do a getResourceAsStream(“/config.properties”) and look for some property to tell you the mode you are running in.
>>>
>>>
>>> Joseph Mocker | Velti | Senior Software Architect
>>> t +1.415.315.4314 m +1.650.566.7033
>>> e jmocker_at_velti.com @VeltiMobile
>>>
>>> The leading global technology provider of
>>> mobile marketing and advertising solutions
>>>
>>> On Oct 25, 2013, at 12:46 PM, Ivar <ivarconr_at_gmail.com> wrote:
>>>
>>>> Use regular jvm properties to set a debug property?
>>>>
>>>> ​Ivar