dev@jsr311.java.net

Re: JSR311: PathParam question in regards to Locators

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Thu, 07 Feb 2008 11:09:00 -0500

On Feb 7, 2008, at 10:14 AM, Bill Burke wrote:

> This is legal I assume? Two PathParams that are "id"
>
Yes, the most recent value is extracted by @PathParam.

> public class Base {
> @Path("/{id}")
> public Resource getResource(@PathParam("id") int id) {
> return new Resource();
> }
> }
>
> public class Resource {
>
> @GET @Path("/{id}")
> public String get(@PathParam("id") int id) {
> ...
> }
> }
>
> which leads me to my next question:
>
> If we inject UriInfo into both Base and Resource,
> getTemplateParameters() should return a different map, correct?

Yes, from Base you'd only have one value for key "id", from Resource
you'd have two.

> Also, does UriInfo for Resource have a different baseUri?
>
No, the base URI is constant. For servlet-based deployment it would be
the servlet context.

For an additional brain teaser consider:

public class Resource {

   @GET @Path("{foo}") @ProduceMime("application/foo")
   public String getFoo(@PathParam("foo") int foo) {...}

   @GET @Path("{bar}") @ProduceMime("application/bar")
   public String getBar(@PathParam("bar") int bar) {...}

}

The two paths are essentially the same but the methods are
distinguished by media type. In getFoo UriInfo.getTemplateParameters
return a map with a "foo" key but no "bar" key. In getBar the map has
a "bar" key but no "foo" key...

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.