Java Reference
In-Depth Information
Here, we have defined a new
@org.rest.LOCK
annotation using
@HttpMethod
to specify the
HTTP operation it binds to. We can then use it on JAX-RS resource methods:
@Path
(
"/customers"
)
public
public class
class
CustomerResource
CustomerResource
{
@Path
(
"{id}"
)
@LOCK
public
public
void
void
lockIt
(
@PathParam
(
"id"
)
String id
) {
...
}
}
Now WebDAV clients can invoke
LOCK
operations on our web server and they will be dis-
patched to the
lockIt()
method.
WARNING
Do not use
@HttpMethod
to define your own application-specific HTTP methods.
@HttpMethod
ex-
ists to hook into new methods defined by standards bodies like the W3C. The purpose of the uni-
form interface is to define a set of well-known behaviors across companies and organizations on the
Web. Defining your own methods breaks this architectural principle.
@Path
There's more to the
@javax.ws.rs.Path
annotation than what we saw in our simple ex-
specific about what requests get bound to which incoming URIs.
@Path
can also be used on a
Java method as sort of an object factory for subresources of your application. We'll examine
both in this section.
Binding URIs
The
@javax.ws.rs.Path
annotation in JAX-RS is used to define a URI matching pattern for
incoming HTTP requests. It can be placed upon a class or on one or more Java methods. For
a Java class to be eligible to receive any HTTP requests, the class must be annotated with at
least the
@Path("/")
expression. These types of classes are called JAX-RS
root resources
.
The value of the
@Path
annotation is an expression that denotes a relative URI to the context
root of your JAX-RS application. For example, if you are deploying into a WAR archive of a