uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

24.3.2 Built-in request method identifier

This subsection describes the request method identifiers supported by the JAX-RS engine.

Organization of this subsection
(1) javax.ws.rs.DELETE annotation
(2) javax.ws.rs.GET annotation
(3) javax.ws.rs.HEAD annotation
(4) javax.ws.rs.OPTIONS annotation
(5) javax.ws.rs.POST annotation
(6) javax.ws.rs.PUT annotation

(1) javax.ws.rs.DELETE annotation

The javax.ws.rs.DELETE annotation indicates that an annotated method processes an HTTP DELETE request. You can use the javax.ws.rs.DELETE annotation in:

(2) javax.ws.rs.GET annotation

The javax.ws.rs.GET annotation indicates that an annotated method processes an HTTP GET request. You can use the javax.ws.rs.GET annotation in:

(3) javax.ws.rs.HEAD annotation

The javax.ws.rs.HEAD annotation indicates that an annotated method processes an HTTP HEAD request. You can use the javax.ws.rs.HEAD annotation in:

When an HTTP HEAD request is received, the JAX-RS engine operates in the following priority sequence:

  1. Calls a method annotated by the HEAD annotation, if such a method exists.
  2. Calls a method annotated by the GET annotation, if no method annotated by the HEAD annotation exists. Note that if the method annotated by the GET annotation returns a value, the return value is ignored.

The following is an example of the root resource class that processes the HTTP HEAD request .

package com.sample.resources;
 
import javax.ws.rs.HEAD;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
 
//Root resource class
@Path("/root")
public class Resource {
 
  //Resource method
  @HEAD
  public Response getValue() {
 
    String customHeader = "foo";
    String customHeaderValue = "bar";
    int httpStatus = 200;
 
    //Build the Response object by using ResponseBuilder
 
    return Response.status(httpStatus).header(customHeader,
        customHeaderValue).build();
  }
}

Consider the context root of the Web application (WAR file) containing the root resource class com.sample.resources.Resource to be example, and that the Web application is published on a host named sample.com. In this example, the HTTP HEAD request corresponding to the URL http://sample.com/example/root is dispatched to the getValue() method. Even if the Response object returned by the getValue() method contains an entity body, the object is ignored.

(4) javax.ws.rs.OPTIONS annotation

The javax.ws.rs.OPTIONS annotation indicates that an annotated method processes an HTTP OPTIONS request. You can use the javax.ws.rs.OPTIONS annotation in:

The JAX-RS engine handles the HTTP OPTIONS request as follows:

  1. Calls a method annotated by the javax.ws.rs.OPTIONS annotation.
  2. If a method annotated by the javax.ws.rs.OPTIONS annotation does not exist, the JAX-RS engine responds automatically by using the annotation information of the Web resource.

The following is an example of the root resource class that processes the HTTP OPTIONS request:

package com.sample.resources;
 
import javax.ws.rs.OPTIONS;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
 
//Root resource class
@Path("/root")
public class Resource {
 
  //Resource method
  @OPTIONS
  public Response getValue() {
    String entity = "Some Contents";
    String customHeader = "foo";
    String customHeaderValue = "bar";
    int httpStatus = 200;
 
    //Build the Response object by using ResponseBuilder
 
    return Response.status(httpStatus).header(customHeader,
        customHeaderValue).entity(entity).build();
 
  }
}

Consider the context root of the Web application (WAR file) containing the root resource class com.sample.resources.Resource to be example, and that the Web application is published on a host named sample.com. In this example, the HTTP OPTIONS request corresponding to the URL http://sample.com/example/root is dispatched to the getValue() method.

(5) javax.ws.rs.POST annotation

The javax.ws.rs.POST annotation indicates that an annotated method processes an HTTP POST request. You can use the javax.ws.rs.POST annotation in:

(6) javax.ws.rs.PUT annotation

The javax.ws.rs.PUT annotation indicates that an annotated method processes an HTTP PUT request. You can use the javax.ws.rs.PUT annotation in: