users@jersey.java.net

[Jersey] Re: question about ResourceConfig

From: Richard Sand <rsand_at_idfconnect.com>
Date: Tue, 30 Jul 2013 23:45:42 -0400

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