On 27/10/2013 7:52 PM, Koper, Dies wrote:
>
> Hi Gili,
>
> ØInjecting ServletContext into a Resource would be too late. I need
> the servlet init parameters in the application constructor.
>
> That's an important detail that you left out of your stackflow post.
>
> You crushed my barely existing stackflow reputation so I've learned my
> lesson and won't reply to any of your questions there, but maybe this
> can help you:
>
How so? All I did was unmark the question as answered. This removes
as much reputation as was granted to you when the answer was accepted in
the first place (2 points).
> Note that injection is possible in constructors of @Provider classes
> (according to section 15.5 of the JAX-RS 1.1 spec), and at least with
> GF 3.1.2.2 where I tried, these are instantiated straight after the
> instantiation of your Application subclass (where I return my
> @Provider class from getSingletons).
>
> So if you definitely want the parameters in the Application
> constructor, I think you'll need to look at one of the various other
> suggestions (passing them as system properties to the JVM, use of a
> property file, etc.). But if you want a JAX-RS spec suggested option
> and just need those parameters at application startup time (as opposed
> to per request for instance), maybe a provider class can help? (Note
> that you can inject your Application subclass into the provider class
> too if you want to share any variables).
>
I appreciate the help but this might not be sufficient in my case.
I'm trying to solve
https://java.net/jira/browse/JERSEY-1950 and in this
case I need to ensure that the HK2-Guice bridge is fully initialized
before any user code tries to run. Anyway, thanks for your help and I'll
keep on looking.
Gili
>
> Regards,
>
> Dies Koper
>
> *From:*cowwoc [mailto:cowwoc_at_bbs.darktech.org]
> *Sent:* Monday, October 28, 2013 1:30 AM
> *To:* users_at_jersey.java.net
> *Subject:* [Jersey] Re: Digest for list users_at_jersey.java.net
>
>
> So, it seems that the celebration was premature. When I inject
> ServletContext into the application, it has a value of null. Here is
> my code:
>
> public class MyApplication extends ResourceConfig
> {
> @Inject
> public MyApplication(ServiceLocator serviceLocator, @Context
> ServletContext context)
> {
> }
> }
>
> Looking at
> http://stackoverflow.com/questions/19450202/get-servletcontext-in-application
> I'm not the only one. Injecting ServletContext into a Resource would
> be too late. I need the servlet init parameters in the application
> constructor.
>
> Gili
>
> On 26/10/2013 9:20 PM, cowwoc wrote:
>
> Hi Simon,
>
> Great answer. Thank you!
>
> I've got a follow-up question. In Jersey 1.0 I configured the
> servlet used for unit tests as follows:
>
> new JerseyTest(new WebAppDescriptor.Builder().
> contextListenerClass(MyContextListener.class).
> contextParam("modules", "GuiceModule1;GuiceModule2").
> filterClass(GuiceFilter.class).servletPath("/").
> clientConfig(getClientConfig()).build()
>
> I don't see a similar mechanism in Jersey 2.0. Any ideas?
>
> Gili
>
> On 26/10/2013 10:10 AM, Simon Roberts wrote:
>
> 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
> <mailto: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
> <mailto:adam.lindenthal_at_oracle.com>>
> 2. [Jersey] Jersey2: How to map URI to Resource? - cowwoc
> <cowwoc_at_bbs.darktech.org <mailto:cowwoc_at_bbs.darktech.org>>
> 3. [Jersey] Jersey2: How to pass parameters from web.xml to
> the Application? - cowwoc <cowwoc_at_bbs.darktech.org
> <mailto:cowwoc_at_bbs.darktech.org>>
> 4. [Jersey] Re: Jersey2: How to pass parameters from web.xml
> to the Application? - Ivar <ivarconr_at_gmail.com
> <mailto:ivarconr_at_gmail.com>>
> 5. [Jersey] Re: Jersey2: How to pass parameters from web.xml
> to the Application? - Joseph Mocker <jmocker_at_velti.com
> <mailto:jmocker_at_velti.com>>
> 6. [Jersey] Re: Jersey2: How to pass parameters from web.xml
> to the Application? - cowwoc <cowwoc_at_bbs.darktech.org
> <mailto: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
> <mailto: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 <mailto: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
> <mailto: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 <mailto: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
> <mailto:jmocker_at_velti.com>>
>
>
>
> ---------- Forwarded message ----------
> From: Adam Lindenthal <adam.lindenthal_at_oracle.com
> <mailto:adam.lindenthal_at_oracle.com>>
> To: users_at_jersey.java.net <mailto: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 <mailto: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
> <mailto:cowwoc_at_bbs.darktech.org>>
> To: users_at_jersey.java.net <mailto: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. 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
> <mailto:cowwoc_at_bbs.darktech.org>>
> To: users_at_jersey.java.net <mailto: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
>
> 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 <mailto:ivarconr_at_gmail.com>>
> To: users_at_jersey.java.net <mailto: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 <mailto:jmocker_at_velti.com>>
> To: "users_at_jersey.java.net <mailto:users_at_jersey.java.net>"
> <users_at_jersey.java.net <mailto: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 <tel:%2B1.415.315.4314> m +1.650.566.7033
> <tel:%2B1.650.566.7033>
> e jmocker_at_velti.com <mailto: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
> <mailto:ivarconr_at_gmail.com>> wrote:
>
> > Use regular jvm properties to set a debug property?
> >
> > Ivar
>
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org
> <mailto:cowwoc_at_bbs.darktech.org>>
> To: users_at_jersey.java.net <mailto: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 <tel:%2B1.415.315.4314> m +1.650.566.7033
> <tel:%2B1.650.566.7033>
> e jmocker_at_velti.com <mailto: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
> <mailto:ivarconr_at_gmail.com>> wrote:
>
> Use regular jvm properties to set a debug property?
>
> Ivar
>
>
>
>
> ---------- Forwarded message ----------
> From: Joseph Mocker <jmocker_at_velti.com <mailto:jmocker_at_velti.com>>
> To: "users_at_jersey.java.net <mailto:users_at_jersey.java.net>"
> <users_at_jersey.java.net <mailto: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
> <mailto: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 <tel:%2B1.415.315.4314> m
> +1.650.566.7033 <tel:%2B1.650.566.7033>
> >> e jmocker_at_velti.com <mailto: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
> <mailto: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
> <mailto:bvan_at_slac.stanford.edu>>
> To: "users_at_jersey.java.net <mailto:users_at_jersey.java.net>"
> <users_at_jersey.java.net <mailto: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
> <mailto: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 <tel:%2B1.415.315.4314> m
> +1.650.566.7033 <tel:%2B1.650.566.7033>
> >> e jmocker_at_velti.com <mailto: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
> <mailto:ivarconr_at_gmail.com>> wrote:
> >>
> >>> Use regular jvm properties to set a debug property?
> >>>
> >>> Ivar
> >
>
>
>
> ---------- Forwarded message ----------
> From: cowwoc <cowwoc_at_bbs.darktech.org
> <mailto:cowwoc_at_bbs.darktech.org>>
> To: users_at_jersey.java.net <mailto: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
> <mailto: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 <tel:%2B1.415.315.4314> m +1.650.566.7033
> <tel:%2B1.650.566.7033>
> e jmocker_at_velti.com <mailto: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
> <mailto: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
> <mailto:bvan_at_slac.stanford.edu>>
> To: "users_at_jersey.java.net <mailto:users_at_jersey.java.net>"
> <users_at_jersey.java.net <mailto: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
> <mailto: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 <mailto: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 <tel:%2B1.415.315.4314> m
> +1.650.566.7033 <tel:%2B1.650.566.7033>
> >>>> e jmocker_at_velti.com <mailto: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
> <mailto:ivarconr_at_gmail.com>> wrote:
> >>>>
> >>>>> Use regular jvm properties to set a debug property?
> >>>>>
> >>>>> Ivar
> >
>
>
>
> ---------- Forwarded message ----------
> From: Joseph Mocker <jmocker_at_velti.com <mailto:jmocker_at_velti.com>>
> To: "users_at_jersey.java.net <mailto:users_at_jersey.java.net>"
> <users_at_jersey.java.net <mailto: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 <tel:%2B1.415.315.4314> m +1.650.566.7033
> <tel:%2B1.650.566.7033>
> e jmocker_at_velti.com <mailto: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 <mailto: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
> <mailto: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 <mailto: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 <tel:%2B1.415.315.4314> m
> +1.650.566.7033 <tel:%2B1.650.566.7033>
> >>>>> e jmocker_at_velti.com <mailto: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
> <mailto: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
> <mailto:users_at_jersey.java.net> - Sat, 26 Oct 2013
>
>
>
> --
> Simon Roberts
> Certified Professional Photographer
> http://dancingcloudphotography.com
> (303) 249 3613
>