Close

JAX-RS - @HEAD Examples

JAX-RS JAVA EE 

@Path("/")
public class ExampleResource {

@Path("/test")
@HEAD
public Response handle(@QueryParam("param1") String param1) {
System.out.printf("param1: %s%n", param1);
Response r = Response.ok("this body will be ignored")
.header("someHeader", "someHeaderValue")
.build();
return r;
}


@Path("/test2")
@GET
public Response handle2() {
Response r = Response.ok("some body content")
.header("someHeader2", "someHeaderValue2")
.build();
return r;
}

@Path("/test3")
public Response handle3() {
Response r = Response.ok("some body content")
.header("someHeader3", "someHeaderValue3")
.build();
return r;
}
}
Original Post




@Path("/")
public class MyResource {

@Path("/test")
@GET
public Response handle() {
Response r = Response.ok("test with GET, body content")
.build();
return r;
}


@Path("/test2")
@GET
public Response handle2() {
Response r = Response.ok("test2 with GET, body content")
.build();
return r;
}

@Path("/test2")
@POST
public Response handle3() {
Response r = Response.ok("test2 with POST, body content")
.build();
return r;
}

@Path("/test2")
@HEAD
public Response handle4() {
Response r = Response.ok("test2 with HEAD, body content")
.build();
return r;
}

@Path("/test3")
@GET
public Response handle5(){
Response r = Response.ok("test3 with GET, body content")
.build();
return r;
}

@Path("/test3")
@OPTIONS
public Response handle6(){
Response r = Response.ok("test3 with OPTIONS, body content")
.header("Allow", "GET")
.header("Allow", "OPTIONS")
.build();
return r;
}
}
Original Post




@Path("/")
public class MyResource {

@Path("/test")
@GET
public Response handle() {
Response r = Response.ok("test with GET, body content")
.build();
return r;
}


@Path("/test2")
@GET
public Response handle2() {
Response r = Response.ok("test2 with GET, body content")
.build();
return r;
}

@Path("/test2")
@POST
public Response handle3() {
Response r = Response.ok("test2 with POST, body content")
.build();
return r;
}

@Path("/test2")
@HEAD
public Response handle4() {
Response r = Response.ok("test2 with HEAD, body content")
.build();
return r;
}

@Path("/test3")
@GET
public Response handle5() {
Response r = Response.ok("test3 with GET, body content")
.build();
return r;
}

@Path("/test3")
@OPTIONS
public Response handle6() {
Response r = Response.ok("test3 with OPTIONS, body content")
.header("Allow", "GET")
.header("Allow", "OPTIONS")
.build();
return r;
}

@Path("/test4")
@DELETE
public Response handle7() {
Response r = Response.ok("test4 with DELETE, body content")
.build();
return r;
}

@Path("/test4")
@PUT
public Response handle8() {
Response r = Response.ok("test4 with PUT, body content")
.build();
return r;
}
}
Original Post




See Also