users@jersey.java.net

Using the _at_Head method when a corresponding _at_GET method is defined with same resource URL

From: Jalpesh Patadia <jrp_at_clickbank.com>
Date: Mon, 1 Jun 2009 14:01:15 -0700

Hello,

I went through the spec, and think this scenario should be supported. Basically in my resource class, I have the following definition:

@Path("/jsr311")
public class MyResource() {
    @HEAD
    @Path("{receipt}")
    public void isActiveOrder(....) throws ParseException
    {
         // standard head request stuff....
     }

    @GET
    @Path("{receipt}")
    @Produces( { "application/xml", "application/json", "text/csv" })
    public OrderData[] getOrderByReceipt(....) throws ParseException
    {
           // get the order data.
    }
}

So the isActiveOrder method should be called for an active order, while getOrderByReceipt should be called for an GET request. What I'm seeing is that the latter (getOrderByReceipt) is being called in both the cases, with the exception that when it's being called with the HEAD call, it returns a 200.

Interestingly, if I remove the @Produces(....) annotation in the getOrderByReceipt() method, things work fine and the isActiveOrder is called for the head request; and upon successful return I get a 204 (NO CONTENT) from the server. I can fix this by changing the @Path annotation for either one of my methods, but I prefer to keep the same URL for my resource (since it ties closely with the REST style)


I just wanted to confirm if this is a known defect or not. I have tried 1.0.3 and 1.1.0-ea and both exhibit the same behavior.


Note that I do not have an "Accept" header defined in my request, so I am using the defaults assumed by the container.


Thanks,


Jalpesh

________________________________
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.