users@jersey.java.net

[Jersey] Re: question about ResourceConfig

From: Richard Sand <rsand_at_idfconnect.com>
Date: Wed, 07 Aug 2013 13:09:48 -0400

Hi Jakub - thanks for the reply and taking the time to answer my questions.

I can probably achieve what I'm trying to do using the injection method
by injecting a String containing the path to the configuration file. I
can then define that String in the web.xml.

I'm still not understanding the purpose of ResourceConfig. Can you just
explain it in one sentence, e.g. "ResourceConfig is used to do ......
and it gets used/invoked by....."?

-Richard

> Jakub Podlesak <mailto:jakub.podlesak_at_oracle.com>
> Monday, August 05, 2013 5:58 AM
> Hi Richard,
>
> i apologize for delayed response. Please see my comments inline.
>
> On Aug 2, 2013, at 5:17 PM, Richard Sand <rsand_at_idfconnect.com
> <mailto:rsand_at_idfconnect.com>> wrote:
>
>> Hi all - I'm still stuck on understanding how properly to use
>> ResourceConfig. I can frame my question another way:
>>
>> 1) What is the Jersey2 pattern for configuring a web application with
>> environment-specific parameters (e.g. backend database connection info)?
>
> An example for configuring a backend db connection on an application
> server could be found here:
>
> https://github.com/jersey/jersey/blob/master/examples/bookmark-em/src/main/java/org/glassfish/jersey/examples/bookmark_em/resource/UsersResource.java
> https://github.com/jersey/jersey/blob/master/examples/bookmark-em/src/main/webapp/WEB-INF/web.xml
>
> The above uses injected entity manager. Another similar example is also:
> https://github.com/jersey/jersey/tree/master/examples/bookmark
>
>>
>> 2) Can I use ResourceConfig for this purpose? If so, can someone
>> point to an example of how to use it to configure an Application in a
>> Jersey Server?
>
> I am afraid, that at the moment, you can not use Jersey's
> ResourceConfig the way you suggested (having an external config file
> configured as a servlet init parameter). You would require access to
> init parameters in your ResourceConfig
> and that is not possible at the moment if i am not mistaken (please
> feel free to file a new RFE for this).
>
> Anyway, I hope you would be able to use the approach used in the
> examples referred above.
>
> HTH,
>
> ~Jakub
>
>
>>
>> 3) Whatever the pattern is, can I use this pattern to configure the
>> Jersey Server, and also to configure the applications when launched
>> via JerseyTest?
>>
>> Thanks for any help!
>>
>> Best regards,
>>
>> Richard
>>
>>> Richard Sand <mailto:rsand_at_idfconnect.com>
>>> Tuesday, July 30, 2013 11:45 PM
>>> Hi Jakub - thanks for your reply. But what I'm asking about is how
>>> to pass
>>> configuration parameters into my app. The links you provided are about
>>> getting the app itself deployed, which I'm past. I'm asking about
>>> deployment-specific configurations. I'm probably misunderstanding the
>>> purpose of ResourceConfig...
>>>
>>> Here's a simple example of what I'm doing with my regular servlets - I'm
>>> asking what the proper technique is to do this with Jersey2, since
>>> it seems
>>> to provide the proper mechanism. In my web.xml:
>>>
>>> <servlet>
>>> <servlet-name>MyServlet</servlet-name>
>>> <servlet-class>com.idfconnect.MyServlet</servlet-class>
>>> <init-param>
>>> <param-name>myAppConfigFile</param-name>
>>> <param-value>/etc/idfconnect/myapp.conf</param-value>
>>> </init-param>
>>> </servlet>
>>>
>>> My servlet reads the param, gets the path to the conf file, and
>>> loads the
>>> conf file, which has all of its environment-specific configuration
>>> properties.
>>>
>>> I want to use a similar approach with my Jersey2 application - when
>>> deployed
>>> on a Jersey server, I have some mechanism via the deployment
>>> descriptor to
>>> pass in initialization parameters, and when deployed using JerseyTest, I
>>> have an alternate mechanism to pass in such parameters. My question
>>> is what
>>> is the proper technique in Jersey2 to accomplish this?
>>>
>>> Thanks for your help!
>>>
>>> Best regards,
>>>
>>> Richard
>>>
>>>
>>>
>>> -------------------------------------
>>>
>>> From: Jakub Podlesak [mailto:jakub.podlesak_at_oracle.com
>>> <http://oracle.com>]
>>> Sent: Monday, July 29, 2013 7:20 AM
>>> To: users_at_jersey.java.net <mailto:users_at_jersey.java.net>
>>> Subject: [Jersey] Re: question about ResourceConfig
>>>
>>> Hi Richard,
>>>
>>> I am not 100 % sure i understand your question. I am confused with
>>> the reference to Jersey 1. Anyway, to configure a specific
>>> ResourceConfig
>>> subclass
>>> in your web application, you may want to use the following servlet init
>>> parameter in your web.xml descriptor:
>>> javax.ws.rs.Application (see [1])
>>> An example can be found at [2].
>>> To achieve JAX-RS 2.0 portability, the referred application class
>>> would directly extend the JAX-RS Application (as in [3]).
>>>
>>> Please clarify if you asked for something else.
>>>
>>> Thanks,
>>>
>>> ~Jakub
>>>
>>> [1]https://jersey.java.net/apidocs/2.1/jersey/org/glassfish/jersey/servlet/S
>>> ervletProperties.html#JAXRS_APPLICATION_CLASS
>>> [2]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/s
>>> rc/main/webapp/WEB-INF/web.xml
>>> [3]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/s
>>> rc/main/java/org/glassfish/jersey/examples/helloworld/webapp/MyApplication.j
>>> ava
>>>
>>>
>>> On Jul 26, 2013, at 8:07 PM, Richard Sand <rsand_at_idfconnect.com
>>> <mailto:rsand_at_idfconnect.com>> wrote:
>>>
>>>
>>> Hey all - apologies for a newbie question - I'm using Jersey2 for
>>> the first
>>> time (I've used Jersey1.17 before) and am writing an app to be
>>> deployed on
>>> Tomcat7, and am trying to figure out how ResourceConfigs work.
>>> Typically to
>>> make my web apps portable between environments, I'd have a
>>> context-param in
>>> the web.xml holding the path to an external config file (which may
>>> be java
>>> properties, an xml config file, or such). What's the proper pattern for
>>> doing this technique in Jersey2?
>>>
>>> Thanks for any input!
>>>
>>> -Richard
>>>
>>>
>>>
>>>
>>> Jakub Podlesak <mailto:jakub.podlesak_at_oracle.com>
>>> Monday, July 29, 2013 7:20 AM
>>> Hi Richard,
>>>
>>> I am not 100 % sure i understand your question. I am confused with
>>> the reference to Jersey 1. Anyway, to configure a specific
>>> ResourceConfig subclass
>>> in your web application, you may want to use the following servlet
>>> init parameter in your web.xml descriptor:
>>> javax.ws.rs.Application (see [1])
>>> An example can be found at [2].
>>> To achieve JAX-RS 2.0 portability, the referred application class
>>> would directly extend the JAX-RS Application (as in [3]).
>>>
>>> Please clarify if you asked for something else.
>>>
>>> Thanks,
>>>
>>> ~Jakub
>>>
>>> [1]https://jersey.java.net/apidocs/2.1/jersey/org/glassfish/jersey/servlet/ServletProperties.html#JAXRS_APPLICATION_CLASS
>>> [2]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/src/main/webapp/WEB-INF/web.xml
>>> [3]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/src/main/java/org/glassfish/jersey/examples/helloworld/webapp/MyApplication.java
>>>
>>>
>>>
>>>
>>> Richard Sand <mailto:rsand_at_idfconnect.com>
>>> Friday, July 26, 2013 2:07 PM
>>> Hey all - apologies for a newbie question - I'm using Jersey2 for
>>> the first
>>> time (I've used Jersey1.17 before) and am writing an app to be
>>> deployed on
>>> Tomcat7, and am trying to figure out how ResourceConfigs work.
>>> Typically to
>>> make my web apps portable between environments, I'd have a
>>> context-param in
>>> the web.xml holding the path to an external config file (which may
>>> be java
>>> properties, an xml config file, or such). What's the proper pattern for
>>> doing this technique in Jersey2?
>>>
>>> Thanks for any input!
>>>
>>> -Richard
>>>
>>
>
> Richard Sand <mailto:rsand_at_idfconnect.com>
> Friday, August 02, 2013 11:17 AM
> Hi all - I'm still stuck on understanding how properly to use
> ResourceConfig. I can frame my question another way:
>
> 1) What is the Jersey2 pattern for configuring a web application with
> environment-specific parameters (e.g. backend database connection info)?
>
> 2) Can I use ResourceConfig for this purpose? If so, can someone point
> to an example of how to use it to configure an Application in a Jersey
> Server?
>
> 3) Whatever the pattern is, can I use this pattern to configure the
> Jersey Server, and also to configure the applications when launched
> via JerseyTest?
>
> Thanks for any help!
>
> Best regards,
>
> Richard
>
> Richard Sand <mailto:rsand_at_idfconnect.com>
> Tuesday, July 30, 2013 11:45 PM
> Hi Jakub - thanks for your reply. But what I'm asking about is how to pass
> configuration parameters into my app. The links you provided are about
> getting the app itself deployed, which I'm past. I'm asking about
> deployment-specific configurations. I'm probably misunderstanding the
> purpose of ResourceConfig...
>
> Here's a simple example of what I'm doing with my regular servlets - I'm
> asking what the proper technique is to do this with Jersey2, since it
> seems
> to provide the proper mechanism. In my web.xml:
>
> <servlet>
> <servlet-name>MyServlet</servlet-name>
> <servlet-class>com.idfconnect.MyServlet</servlet-class>
> <init-param>
> <param-name>myAppConfigFile</param-name>
> <param-value>/etc/idfconnect/myapp.conf</param-value>
> </init-param>
> </servlet>
>
> My servlet reads the param, gets the path to the conf file, and loads the
> conf file, which has all of its environment-specific configuration
> properties.
>
> I want to use a similar approach with my Jersey2 application - when
> deployed
> on a Jersey server, I have some mechanism via the deployment descriptor to
> pass in initialization parameters, and when deployed using JerseyTest, I
> have an alternate mechanism to pass in such parameters. My question is
> what
> is the proper technique in Jersey2 to accomplish this?
>
> Thanks for your help!
>
> Best regards,
>
> Richard
>
>
>
> -------------------------------------
>
> From: Jakub Podlesak [mailto:jakub.podlesak_at_oracle.com]
> Sent: Monday, July 29, 2013 7:20 AM
> To: users_at_jersey.java.net
> Subject: [Jersey] Re: question about ResourceConfig
>
> Hi Richard,
>
> I am not 100 % sure i understand your question. I am confused with
> the reference to Jersey 1. Anyway, to configure a specific ResourceConfig
> subclass
> in your web application, you may want to use the following servlet init
> parameter in your web.xml descriptor:
> javax.ws.rs.Application (see [1])
> An example can be found at [2].
> To achieve JAX-RS 2.0 portability, the referred application class
> would directly extend the JAX-RS Application (as in [3]).
>
> Please clarify if you asked for something else.
>
> Thanks,
>
> ~Jakub
>
> [1]https://jersey.java.net/apidocs/2.1/jersey/org/glassfish/jersey/servlet/S
> ervletProperties.html#JAXRS_APPLICATION_CLASS
> [2]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/s
> rc/main/webapp/WEB-INF/web.xml
> [3]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/s
> rc/main/java/org/glassfish/jersey/examples/helloworld/webapp/MyApplication.j
> ava
>
>
> On Jul 26, 2013, at 8:07 PM, Richard Sand <rsand_at_idfconnect.com> wrote:
>
>
> Hey all - apologies for a newbie question - I'm using Jersey2 for the
> first
> time (I've used Jersey1.17 before) and am writing an app to be deployed on
> Tomcat7, and am trying to figure out how ResourceConfigs work.
> Typically to
> make my web apps portable between environments, I'd have a
> context-param in
> the web.xml holding the path to an external config file (which may be java
> properties, an xml config file, or such). What's the proper pattern for
> doing this technique in Jersey2?
>
> Thanks for any input!
>
> -Richard
>
>
>
> Jakub Podlesak <mailto:jakub.podlesak_at_oracle.com>
> Monday, July 29, 2013 7:20 AM
> Hi Richard,
>
> I am not 100 % sure i understand your question. I am confused with
> the reference to Jersey 1. Anyway, to configure a specific
> ResourceConfig subclass
> in your web application, you may want to use the following servlet
> init parameter in your web.xml descriptor:
> javax.ws.rs.Application (see [1])
> An example can be found at [2].
> To achieve JAX-RS 2.0 portability, the referred application class
> would directly extend the JAX-RS Application (as in [3]).
>
> Please clarify if you asked for something else.
>
> Thanks,
>
> ~Jakub
>
> [1]https://jersey.java.net/apidocs/2.1/jersey/org/glassfish/jersey/servlet/ServletProperties.html#JAXRS_APPLICATION_CLASS
> [2]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/src/main/webapp/WEB-INF/web.xml
> [3]https://github.com/jersey/jersey/blob/master/examples/helloworld-webapp/src/main/java/org/glassfish/jersey/examples/helloworld/webapp/MyApplication.java
>
>
>
>
> Richard Sand <mailto:rsand_at_idfconnect.com>
> Friday, July 26, 2013 2:07 PM
> Hey all - apologies for a newbie question - I'm using Jersey2 for the
> first
> time (I've used Jersey1.17 before) and am writing an app to be deployed on
> Tomcat7, and am trying to figure out how ResourceConfigs work.
> Typically to
> make my web apps portable between environments, I'd have a
> context-param in
> the web.xml holding the path to an external config file (which may be java
> properties, an xml config file, or such). What's the proper pattern for
> doing this technique in Jersey2?
>
> Thanks for any input!
>
> -Richard
>