users@jersey.java.net

[Jersey] Re: Digest for list users_at_jersey.java.net

From: Simon Roberts <simon_at_dancingcloudphotography.com>
Date: Sat, 26 Oct 2013 08:10:34 -0600

I believe that provided you're actually running in a servlet-hosted
environment (which you are, presumably, because you are talking about
web.xml) then you can use @Context to inject the ServletConfig and
ServletContext objects:

https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e2030

HTH
Simon



On Fri, Oct 25, 2013 at 9:05 PM, <users-request_at_jersey.java.net> wrote:

> Table of contents:
>
> 1. [Jersey] [ANN] Jersey 2.4 has been released - Adam Lindenthal <
> adam.lindenthal_at_oracle.com>
> 2. [Jersey] Jersey2: How to map URI to Resource? - cowwoc <
> cowwoc_at_bbs.darktech.org>
> 3. [Jersey] Jersey2: How to pass parameters from web.xml to the
> Application? - cowwoc <cowwoc_at_bbs.darktech.org>
> 4. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - Ivar <ivarconr_at_gmail.com>
> 5. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - Joseph Mocker <jmocker_at_velti.com>
> 6. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - cowwoc <cowwoc_at_bbs.darktech.org>
> 7. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - Joseph Mocker <jmocker_at_velti.com>
> 8. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - "Van Klaveren, Brian N." <bvan_at_slac.stanford.edu>
> 9. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - cowwoc <cowwoc_at_bbs.darktech.org>
> 10. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - "Van Klaveren, Brian N." <bvan_at_slac.stanford.edu>
> 11. [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application? - Joseph Mocker <jmocker_at_velti.com>
>
>
>
> ---------- Forwarded message ----------
> From: Adam Lindenthal <adam.lindenthal_at_oracle.com>
> To: users_at_jersey.java.net
> Cc:
> Date: Fri, 25 Oct 2013 17:53:39 +0200
> Subject: [Jersey] [ANN] Jersey 2.4 has been released
>
> Jersey team is happy to announce availability of Jersey 2.4.
>
> For an overview of changes, bug fixes and new features, please consult
> Jersey 2.4 Release Notes: https://jersey.java.net/release-notes/2.4.html
> To download Jersey 2.4, please check our download page:
> https://jersey.java.net/download.html
>
> We also recommend you to check out the refreshed Jersey 2.4 documentation:
>
> - API: https://jersey.java.net/apidocs/2.4/jersey/index.html
> - User Guide: https://jersey.java.net/documentation/2.4/index.html
>
> We appreciate your feedback - if you have any thoughts or comments, send
> us an email to Jersey users mailing list users_at_jersey.java.net or file
> any discovered bugs & new feature requests in Jersey Jira issue tracker:
> https://java.net/jira/browse/JERSEY/
>
> May the REST be with you,
> Your Jersey Team.
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org>
> To: users_at_jersey.java.net
> Cc:
> Date: Fri, 25 Oct 2013 12:56:23 -0400
> Subject: [Jersey] Jersey2: How to map URI to Resource?
> Hi,
>
> I posted this question at http://stackoverflow.com/q/**17284419/14731<http://stackoverflow.com/q/17284419/14731>.
> What replaces ResourceContext.matchResource(**URI)? How do we go from a
> URI back to a resource class?
>
> Thanks,
> Gili
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org>
> To: users_at_jersey.java.net
> Cc:
> Date: Fri, 25 Oct 2013 14:03:43 -0400
> Subject: [Jersey] Jersey2: How to pass parameters from web.xml to the
> Application?
> Hi,
>
> I posted this question here: http://stackoverflow.com/q/**
> 19596592/14731 <http://stackoverflow.com/q/19596592/14731>
>
> The container needs to be able to tell the Application whether it is
> running in debug or release mode. The container needs to know this
> information because it exposes extra resources in debug mode, and the
> application needs to know this because it registers different
> implementations in debug mode. Any ideas?
>
> Gili
>
>
> ---------- Forwarded message ----------
> From: Ivar <ivarconr_at_gmail.com>
> To: users_at_jersey.java.net
> Cc:
> Date: Fri, 25 Oct 2013 21:46:40 +0200
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> Use regular jvm properties to set a debug property?
>
> Ivar
>
>
> ---------- Forwarded message ----------
> From: Joseph Mocker <jmocker_at_velti.com>
> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
> Cc:
> Date: Fri, 25 Oct 2013 20:42:14 +0000
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> 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
>
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org>
> To: users_at_jersey.java.net
> Cc:
> Date: Fri, 25 Oct 2013 17:24:23 -0400
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
>
> 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
>>>
>>
>
>
> ---------- Forwarded message ----------
> From: Joseph Mocker <jmocker_at_velti.com>
> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
> Cc:
> Date: Fri, 25 Oct 2013 21:42:31 +0000
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> Yeah I haven’t found the link between ServletContainer and ResourceConfig
> either.
>
> But, if you are going to have different web.xml files for your dev and
> prod environments, why not just have two different ResourceConfig
> subclasses, one for each environment?
>
> With my suggestion, it may be ugly, but you are never generating multiple
> WARs, your environment specific parameters are held outside the WAR. That’s
> nice from a management/deployment standpoint.
>
> I’ll bet something similar could be done with JNDI.
>
> —joe
>
> 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
> >
>
>
>
> ---------- Forwarded message ----------
> From: "Van Klaveren, Brian N." <bvan_at_slac.stanford.edu>
> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
> Cc:
> Date: Fri, 25 Oct 2013 14:44:51 -0700
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> 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
> >
>
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org>
> To: users_at_jersey.java.net
> Cc:
> Date: Fri, 25 Oct 2013 17:50:35 -0400
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> 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
>>>>>
>>>>
>
>
> ---------- Forwarded message ----------
> From: "Van Klaveren, Brian N." <bvan_at_slac.stanford.edu>
> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
> Cc:
> Date: Fri, 25 Oct 2013 15:27:40 -0700
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> Hi,
>
> Sorry, I double checked because I thought context-param added it to the
> environment as well, but it only adds it to a servlet context. I think the
> first part is right, however, if you want to do it not from a servlet, you
> need to define it in web.xml the following way:
>
> <env-entry>
> <env-entry-name>maybeDebug</env-entry-name>
> <env-entry-value>nope</env-entry-value>
> <env-entry-type>java.lang.String</env-entry-type>
> </env-entry>
>
> The second bit of code remains the same. You should be able to retrieve,
> anywhere in the application, with the following code:
>
> String paramValue = (String) new
> InitialContext().lookup("java:comp/env/maybeDebug");
>
> Brian
>
>
> On Oct 25, 2013, at 2:50 PM, cowwoc <cowwoc_at_bbs.darktech.org> wrote:
>
> > 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
> >
>
>
>
> ---------- Forwarded message ----------
> From: Joseph Mocker <jmocker_at_velti.com>
> To: "users_at_jersey.java.net" <users_at_jersey.java.net>
> Cc:
> Date: Fri, 25 Oct 2013 22:51:05 +0000
> Subject: [Jersey] Re: Jersey2: How to pass parameters from web.xml to the
> Application?
> JNDI FTW! :-) Beauty Brian.
>
> —joe
>
> 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 3:27 PM, Van Klaveren, Brian N. <
> bvan_at_slac.stanford.edu> wrote:
>
> > Hi,
> >
> > Sorry, I double checked because I thought context-param added it to the
> environment as well, but it only adds it to a servlet context. I think the
> first part is right, however, if you want to do it not from a servlet, you
> need to define it in web.xml the following way:
> >
> > <env-entry>
> > <env-entry-name>maybeDebug</env-entry-name>
> > <env-entry-value>nope</env-entry-value>
> > <env-entry-type>java.lang.String</env-entry-type>
> > </env-entry>
> >
> > The second bit of code remains the same. You should be able to retrieve,
> anywhere in the application, with the following code:
> >
> > String paramValue = (String) new
> InitialContext().lookup("java:comp/env/maybeDebug");
> >
> > Brian
> >
> >
> > On Oct 25, 2013, at 2:50 PM, cowwoc <cowwoc_at_bbs.darktech.org> wrote:
> >
> >> 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
> >>
> >
>
>
> End of digest for list users_at_jersey.java.net - Sat, 26 Oct 2013
>
>


-- 
Simon Roberts
Certified Professional Photographer
http://dancingcloudphotography.com
(303) 249 3613