users@jersey.java.net

Re: [Jersey] Two Resource classes with the same path

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 26 Jan 2009 13:31:51 +0100

Hi Alex,

Jersey should warn you or fail to load the application if two or more
root resource classes have the same path. So i this respect it is a
bug, could you log an issue?

You need to implement all methods associated with a resource from
within the same resource class. Of course if the different HTTP method
implementations are long and involved your could defer to further
classes, for example:

   @GET
   public ... get(...) {
       return new Get(...).process(...);
   }

   @POST
   public ... post(...) {
       return new Post(...).process(...);
   }

and keep the controller (the resource class) fairly light weight.

Paul.

On Jan 25, 2009, at 9:23 PM, Alex K wrote:

>
> Hi,
>
> I'm new to Jersey and so far I'm happy to what the framework is
> providing.
>
> Today I experienced a problem and wanted to ask if anyone has seen
> the same
> issue as me.
>
> I have two Ressource classes :
> @Path("repository")
> public class DownloadResource
>
> that contains the @GET and
>
> @Path("repository")
> public class UploadResource
>
> that contains the @POST. The processing methods are a bit long and do
> different things so that's why I wanted to separate them.
>
> I was using them for a while (1-2 days) like that but today I was
> having
> problems. When I run the server, I received the requests either in the
> DownloadResource or UploadResource. It's really strange and I was
> not able
> to get a pattern of what's happening. Firefox didn't say a thing
> (blank
> page) and IE told me it is 405 Method Not Allowed.
>
> When I debugged the application I noticed a problem with the path
> templates
> and then I came to think that the problem is that I have the same
> path for
> two different classes that are registered with Jersey. I put the code
> together and everything works now.
>
> Can someone more experienced confirm that there is a limitation and
> the
> @Path should be unique on a class? Shouldn't there be a warning if two
> classes compete for a URI (maybe it is not easy to track)?
>
> Any comments are welcome. Thank you for the attention.
>
> Alex K
>
>
> --
> View this message in context: http://n2.nabble.com/-Jersey--Two-Resource-classes-with-the-same-path-tp2214595p2214595.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>