users@jersey.java.net

Re: Multiple UriTemplate Annotations for Generic 'Handler' Classes?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 11 Jan 2008 10:40:46 +0100

Hi Stew,

If you want an explicit dynamic solution you can do the following:

   @Path("/")
   public class VirtualRoot {
     @Path("virtual-res1")
     public Object getVirtualRes2() { ... }

     @Path("virtual-res2")
     public Object getVirtualRes2() { ... }

   }

   @Path("atomic-res1")
   public class Atomic { ... }


Or follow Marc's proposal of a non-explicit dynamic solution:

   @Path("/")
   public class VirtualRoot {
     @Path("virtual-{res}")
     public Object getVirtualRes2(@PathParam("res") String r) { ... }
     // Note that @UriParam was renamed to @PathParam
     // but only for 0.6 onwards, so is not in the 0.5 release of Jersey
   }

   @Path("atomic-res1")
   public class Atomic { ... }

Thus you don't have to use a 'virtual' parent path.


A non-dynamic explicit way to do this is to have an abstract class from
which you extend, as follows:

   public class AVR {
     // HTTP methods on AVR class
   }

   @Path("virtual-res1")
   public class VirtualResource1 extends ARV {}

   @Path("virtual-res2")
   public static class VirtualResource1 extends ARV {}

   @Path("atomic-res1")
   public class Atomic { ... }

Or a non-dynamic implicit way:

   @Path("virtual-{res}")
   public class VirtualResource {
     public VirtualResource(@PathParam("res") String r) { ... }
   }

   @Path("atomic-res1")
   public class Atomic { ... }


I suspect that sub-locators is the way for you to go to return something
dynamic based on looking up what the virtual resource is. This allows
different virtual resources to have different methods and URI spaces
(you could even download such resources classes from the network!).

Hope this helps,
Paul.

stewart.welbourne_at_bt.com wrote:
>
> Marc
> many thanks for your concise response - I feel pretty comfortable that
> there is a 'technical' capability to address my particular requirement.
> As such I see how I can get the level of control I need but I'm
> concerned about the potential implications for my 'clean' namespace. For
> example if I have say 3 root resources in my public resource namespace
> (those published to my clients as part of their interface contract), one
> of which has a concrete representation and two of which have a
> dynamically assembled representation as follows:
>
> ___http://res.domain.com/atomic-res1_ //served directly from an atomic
> datasource via entity class
> _http://res.domain.com/virtual-res2_ //assembled via back-end integration
> _http://res.domain.com/virtual-res3_ //assembled via back-end integration
>
> Then are you suggesting that I would need to inject a root 'branch' to
> explicitly segregate the 'virtuals' in order to exploit the capability
> you've outlined along the lines of:
>
> /atomic-res1
> /virtual/virtual-res2
> /virtual/virtual-res3
> ...
>
> Such that I would have something like this:
>
> @Path("/atomic-res1") /
> public class AtomicResource1 {
> //standard O/R based represnetation production
> }
>
>
>
> @Path("/virtual")
> public class VirtualResourceRouter {
> @Path("{resource}")
> public Object resolve(@PathParam("resource") String resource) {
> if (resource.equals("virtual-res2")
> return new VirtualResource2(...);
> else
> return new VirtualResource3(...);
>
> }
> }
>
> So whilst I understand how this can work - I introduce
> technology-induced padding into my resource namespace which I'm
> attempting to keep clean and meaningful. This may seem like a small,
> cosmetic observation but purity in the namespace is an area of great
> sensitivity in our work to date.
>
> Sitting back and thinking about this (for the sake of argument) I'm
> thinking I 'could' technically push all my root resources via this
> front-end router (rooter :-) but that's sort of working against the
> benefits of the scheme. On the other hand, unless I've misinterpreted
> you, my published namespace is gonna be impacted - where my ideal
> scenario means I could add my two virtual root resources "/virtual-res2"
> and "/virtual-res3" @Path annotations to the router class without
> impacting my URI scheme.
>
> Thanks
> Stewart
>
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109