web.xml for multiple resource classes

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

web.xml for multiple resource classes

dloy
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: web.xml for multiple resource classes

Marc Hadley
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: web.xml for multiple resource classes

dloy
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.

I hope this is helps clarify.
Thanks
David


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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: web.xml for multiple resource classes

Naresh-11
In reply to this post by dloy
Hi David,

  may be the recent Jersey Servlet 3.0 integration that Paul has done
would be helpful for you.
Please refer the samples that he has provided in the mail thread [1].
Please note, however, that you will have to add the following dependency
to be able to build and run the sample "annotatedapp" which uses the
@ApplicationPath annotation:

 <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.1-ea</version>
  </dependency>


[1]
http://markmail.org/search/?q=Jersey%20servlet%203.0#query:Jersey%20servlet%203.0+page:1+mid:bi4orphv6sdyojjw+state:results 


Hope this helps,
Naresh


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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: web.xml for multiple resource classes

Marc Hadley
In reply to this post by dloy
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: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: web.xml for multiple resource classes

Paul Sandoz
Administrator
In reply to this post by dloy

On Sep 10, 2009, at 11: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
>

You can experiment with the Servlet 3.0 support as Naresh indicates  
but you can also explicitly refer to classes that extend from  
javax.ws.rs.core.Application, or ResourceConfig, if you are more  
comfortable working from stable releases.

See here:

   https://jersey.dev.java.net/nonav/documentation/1.1.2-ea/user-guide.html 
#d4e115

You can essentially declare two servlets referencing two different  
application classes that register your root resources.

Alternatively you can explicitly declare your root resource classes  
using Jersey specific package scanning (see the above link) or  
explicit declare the classes, see:

https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/core/ClassNamesResourceConfig.html

Paul.

> 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.
>
> I hope this is helps clarify.
> Thanks
> David
>
>
> 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: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]