cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: JAX-RS Annotations and path resolution
Date Tue, 06 Dec 2011 11:04:25 GMT
On 06/12/11 10:11, Jeff Wang wrote:
> Ok, I think I'm getting away from what I'm trying to accomplish, which
> is to figure out the best way to annotate sub-resources.  Currently, I
> have foo, which is a sub-resource of bar.  so I'd like to GET
> /bar/1/foo for the list of Foos that bar 1 has.  or POST /bar/1/foo to
> create a new foo.  or GET /bar/1/foo/3, to get foo 3.
> Currently, I have created two separate service beans, have with a
> class level @PATH annotation of "/bar" and "/bar/{barId}/foo"
> respectively, and individual @PATH additions as required (for fooId
> and barId as appropriate.
> Right now, Bar, the POJO has a very simple JPA and XML mapping.
> @XMLRootElement
> @Entity
> public class Bar {
>    @Column(name="fooId")
>    public Foo;
> }
> (getters, setters, and other fields removed.)  How would a equivalent
> mapping be expressed in a sub-resource locator?  Would it be actually
> easier to read?

Not sure if it answers your question, here is one example:

public class BarResource {

  public Foos getFoos(@PathParam("id") int id) {}
  public void addFoo(Foo foo) {}

  // optional: @GET
  public Foo getFoo (@PathParam("id") int id, @PathParam("fooid") int 
foo_id) {}

Additionally you can have a "/bar" path on a Bar itself and register it 
as another root resource, or push the above "{id}/foo" to the 3 existing 
methods and a GET which will return Bar - that would cover /bar only

Cheers, Sergey

> thanks
> Jeff Wang

Sergey Beryozkin

Talend Community Coders


View raw message