users@jersey.java.net

[Jersey] Re: Question about HEAD

From: Russ Baker <rbaker_at_ghx.com>
Date: Tue, 5 Nov 2013 23:04:09 +0000

Hello Michal,

Your suggestion did not work. Here are what my endpoints look like:

    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("helloworld/{id}")
   public MyBoundObject getMyBoundObject(){
...
}

    @HEAD
    @Path("helloworld/{id}")
   public MyBoundObject headMyBoundObject(){
...
}


Each time I do a call using "HEAD" the "GET" is executed.

-Russ

From: Michal Gajdos [mailto:michal.gajdos_at_oracle.com]
Sent: Tuesday, November 05, 2013 2:46 PM
To: users_at_jersey.java.net
Subject: [Jersey] Re: Question about HEAD

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