users@jersey.java.net

[Jersey] Re: Question about HEAD

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Tue, 05 Nov 2013 22:45:32 +0100

Hi Russ,

consider a resource like this:

@Path("helloworld")
@Produces("text/plain")
public class HelloWorldResource {

     @GET
     public String getHello() {
         return "Hello World!";
     }

     @HEAD
     public String headHello() {
         return "Hello World!";
     }
}

If you call, via your client, HTTP HEAD method on this resource the
HelloWorldResource#headHello() method would be invoked (for HTTP GET it
would be HelloWorldResource#getHello()).

If we change the resource to something like this:

@Path("helloworld")
@Produces("text/plain")
public class HelloWorldResource {

     @GET
     public String getHello() {
         return "Hello World!";
     }
}

Then for both HTTP GET and HTTP HEAD the HelloWorldResource#getHello()
would be invoked.

If you're experiencing different behaviour, please, describe your
use-case in more detail or file an issue into our JIRA.

Michal

On 05.11.2013, 22:30 , Russ Baker wrote:
>
> I'm running a web application and I want to access a resource with
> "HEAD". Whenever I call "HEAD" Jersey will go and use the
> corresponding "GET". I read in the documentation that "For HEAD the
> runtime will invoke the implemented GET method (if present) and ignore
> the response entity (if set)." How do I force the client to make the
> "HEAD" call instead of the "GET"?
>
> Thanks in advance,
>
> Russ Baker
>