users@jersey.java.net

Re: [Jersey] web.xml for multiple resource classes

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 11 Sep 2009 08:28:40 -0400

On Sep 10, 2009, at 5:02 PM, dloy wrote:

> Hi Marc
> I currently create a single jar that may have multiple classes with
> Jersey annotations. Two classes may have identical @Path annotations
> but only one class would be called in a specific servlet.
>
> Example
> storage servlet calls JerseyStorage.class
> node servlet calls JerseyNode.class
>
> One approach is that each war would only contain one of the resource
> classes. I was hoping there was some web.xml directive to force
> Jersey to resolve its resources to a single application or possibly
> a single project. I have seen some references to ResourceConfig
> extensions on the web but I wasn't clear what was needed to get this
> to work.
>
For each servlet you create a subclass of javax.ws.rs.core.Application
that lists the required resource classes and providers. In web.xml you
add an init parameter to each servlet that points to the respective
Application subclass using an init-param with a name of
"javax.ws.rs.core.Application" and a value of the fully qualified name
of the Application subclass. See:

https://jsr311.dev.java.net/nonav/releases/1.0/spec/
spec3.html#x3-160002.3.2

With JAX-RS 1.1 we'll make this simpler by removing the need for the
web.xml but for 1.0 you need the above.

HTH,
Marc.

>
> Marc Hadley wrote:
>> Can you say a little more about what you are trying to do. Jersey
>> can handle (and will normally discover) multiple resource classes
>> in a single application and will route requests to the appropriate
>> resource class according to the algorithm here:
>>
>> https://jsr311.dev.java.net/nonav/releases/1.0/spec/
>> spec3.html#x3-340003.7
>>
>> Marc.
>>
>> On Sep 10, 2009, at 3:39 PM, dloy wrote:
>>
>>> I have successfully been able to use a Jersey resource class using
>>> a web.xml containing only:
>>> <servlet-
>>> class>com.sun.jersey.spi.container.servlet.ServletContainer</
>>> servlet-class>
>>> Letting Jersey discover the resources.
>>>
>>> I now require having multiple classes that have overlapping
>>> resource @Path. What is the preferred method for directing Jersey
>>> to a specific class or project for resolving the resources.
>>>
>>> I've encountered a number of suggestions on the Web which resulted
>>> in:
>>>
>>> is not a super class of class com.sun.jersey.api.core.ResourceConfig
>>>
>>> Could someone direct me to documentation for doing this (an
>>> example would be useful if it requires class modification -
>>> extending ResourceConfig).
>>>
>>> Thanks
>>> David
>>>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>