users@jersey.java.net

Re: [Jersey] Resource sub-locators not working as expected.

From: Cameron Jones <cmhjones_at_gmail.com>
Date: Wed, 22 Apr 2009 17:38:33 +1000

Can sub-resource classes have multiple http methods per path? eg:

// @Path("resource/subresource")
public class SubResource {

@Path("collection")
@Consumes("application/json");
public Response putSubPath() {
        ...
}

@Path("collection")
@Consumes(""application/json");
public Response postSubPath() {
        ...
}

}

On 22/04/2009, at 8:18 AM, Marc Hadley wrote:

> Remove the @GET on getModelResource. Sub-resource locators don't
> have a method designator.
>
> Marc.
>
> On Apr 21, 2009, at 2:58 PM, Jalpesh Patadia wrote:
>
>> Hello everyone,
>>
>> Thanks to Paul for responding to my earlier issue. I have resolved
>> that, and am facing another issue; which I think may be a bug in
>> the implementation. Here’s some dummy code which explains this:
>>
>> Resource 1 : Car Resource
>>
>> @Path("/1.0/cars")
>> public class CarResource extends AbstractResource
>> {
>> @GET
>> @Path("list") // lists all the cars -- general pattern for
>> listing a resource
>> @Produces({"application/xml","application/json","text/
>> csv"}) // optional, but putting it will help documentation
>> public List<Car> getFormattedCarList(@HeaderParam("Accept")
>> String accept, @Context HttpServletRequest req)
>> {
>> System.out.println("Accept : " + accept);
>> System.out.println("Request: " + req);
>> return super.getCarList();
>> }
>> …
>> @Path("model")
>> @GET
>> public CarModelResource getModelResource()
>> {
>> return new CarModelResource();
>> }
>> }
>>
>>
>> Resource 2 : CarModelResource
>>
>> // @Path("/1.0/cars/model")
>> public class CarModelResource extends AbstractResource
>> {
>> @Documentation(description="Get a list of car models detail list")
>> @GET
>> @Path("list")
>> public List<CarModel> getCarModelListFormatted()
>> {
>> System.out.println("+++++ Returning formatted list +++++");
>> return super.getCarModelList();
>> }
>> }
>>
>> Now, according to the spec, the CarModelResource is a sub-resource
>> with a sub-resource locator getCarModelListFormatted. What I’m
>> seeing is that when I type in http://myurl.../1.0/cars/model/list
>> this code is returning me a 404 – Not found error. Maybe I’m not
>> reading the spec correctly, but upon reading the JAX-RS Spec,
>> section 3.4.1 – Sub Resources it implied that this should work.
>> Could somebody shed some light why it’s not working ?
>>
>> Now, interestingly I got this working by uncommenting the @Path
>> annotation in CarModelResource, so it’s not a problem. But at that
>> point, I don’t think it’s actually a sub-resource locator anymore
>> but just a regular resource mapping. In the example described in
>> the spec the WidgetResource class does not have a @Path annotation
>> on it, so I assumed that it’s not needed.
>>
>> I just needed to understand what is the correct behavior.
>>
>>
>> Thanks,
>>
>> Jalpesh.
>>
>> PS : I’m using the com.sun.jersey…..SpringServlet in web.xml as my
>> servlet handler. I have verified that all the beans are registered
>> correctly in the applicationContext files.
>>
>>
>> PRIVILEGED AND CONFIDENTIAL
>> This transmission may contain privileged, proprietary or
>> confidential information. If you are not the intended recipient,
>> you are instructed not to review this transmission. If you are not
>> the intended recipient, please notify the sender that you received
>> this message and delete this transmission from your system.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>