Java Reference
In-Depth Information
If however, an application contains a servlet that contains an initialization parameter of
javax.ws.rs.core.Application , and whose value is the fully qualified name of the Application subclass, then
no additional configuration is necessary.
Once an application has been configured to use JAX-RS or contains a servlet that handles the application,
resource classes and providers can be implemented. To invoke the JobsService REST service that was implemented in
the example, deploy the application that has been configured to accordingly, and load the appropriate URL
( http://localhost:8080/IntroToJavaEE7/rest/jobsService ) into a web browser. In this case, the application is
named IntroToJavaEE7 , since you are working with the topic sources. Table 8-1 describes the possible annotations
that can be used to create a REST service.
Table 8-1. REST Service Annotations
Annotation
Description
@POST
Request method designator that processes HTTP POST requests.
@GET
Request method designator that processes HTTP GET requests.
@PUT
Request method designator that processes HTTP PUT requests.
@DELETE
Request method designator that processes HTTP DELETE requests.
@HEAD
Request method designator that corresponds to the HTTP HEAD method. It processes HTTP HEAD
requests.
@Path
The value of this annotation should correlate to the relative URI path that indicates where the
Java class will be hosted. Variables can be embedded in the URIs to make a URI path template.
@Context
Injects an instance of a supported resource.
@MatrixParam
A type of parameter that can be extracted for use in the resource class. Matrix parameters are
extracted from the request.
@CookieParam
Extracts the value of a cookie.
@HeaderParam
Extracts the value of a header.
@PathParam
A type of parameter that can be extracted for use in the resource class. URI path parameters are
extracted from the request URI, and the parameter names correspond to the URI path template
variable names specified in the @Path class-level annotation.
@QueryParam
A type of parameter that can be extracted for use in the resource class. Query parameters are
extracted from the request.
@Consumes
Used to specify the MIME media types of representations that a resource can consume.
@Produces
Used to specify the MIME media types of representations that a resource can produce.
@Provider
Used to specify a provider class for automatic discovery.
To designate a class a REST service, the @Path annotation must be placed prior to the class or before at least one
of the class method signatures. The @Path annotation is responsible for constructing the URI that will be used for
accessing the web resource. To learn more detail regarding @Path , please see the following section, “Constructing
Meaningful URIs.”
Designate methods with the @GET , @POST , @PUT , or @DELETE designator to process the type of web service request
that is desired. Methods annotated as such are also known as resource methods. Adding resource methods to a
resource class generates web service functionality. If more than one resource method exists within a REST web
service implementation and @Path is specified only at the class level and not at the method level, then the method
that returns the MIME type the client requires will be invoked. If you want your method to display content, designate
 
 
Search WWH ::




Custom Search