Java Reference
In-Depth Information
package
package javax . ws . rs ;
import
import ...
... ;
@Target ({ ElementType . METHOD })
@Retention ( RetentionPolicy . RUNTIME )
@HttpMethod ( HttpMethod . GET )
public
public @interface GET {
}
@GET , by itself, does not mean anything special to the JAX-RS provider. In other words,
JAX-RS is not hardcoded to look for this annotation when deciding whether or not to dis-
patch an HTTP GET request. What makes the @GET annotation meaningful to a JAX-RS pro-
vider is the meta-annotation @javax.ws.rs.HttpMethod . Meta-annotations are simply an-
notations that annotate other annotations. When the JAX-RS provider examines a Java meth-
od, it looks for any method annotations that use the meta-annotation @HttpMethod . The
value of this meta-annotation is the actual HTTP operation that you want your Java method
to bind to.
HTTP Method Extensions
What are the implications of this? This means that you can create new annotations that bind
to HTTP methods other than GET, POST, DELETE, HEAD, and PUT. While HTTP is a ubi-
quitous, stable protocol, it is still constantly evolving. For example, consider the WebDAV
standard. [ 3 ] The WebDAV protocol makes the Web an interactive readable and writable me-
dium. It allows users to create, change, and move documents on web servers. It does this by
adding a bunch of new methods to HTTP like MOVE, COPY, MKCOL, LOCK, and
UNLOCK.
Although JAX-RS does not define any WebDAV-specific annotations, we could create them
ourselves using the @HttpMethod annotation:
package
package org . rest . webdav ;
import
import ...
... ;
@Target ({ ElementType . METHOD })
@Retention ( RetentionPolicy . RUNTIME )
@HttpMethod ( "LOCK" )
public
public @interface LOCK {
}
 
Search WWH ::




Custom Search