Java Reference
In-Depth Information
8.3.5. JAX-RS annotations
In this section we're going to examine a key subset of the JAX-RS annotations. These will
cover the basic cases and the code from ActionBazaar we just examined. Entire topics have
been written on JAX-RS, so if you choose to expose EJBs as RESTful web services, further
investigation will be required. Implementing RESTful web services is still much simpler
than SOAP.
To get a RESTful web service up and running, you'll need at least the following annota-
tions:
@javax.ws.rs.Path— This annotation must appear on the class providing the
RESTful web service.
@javax.ws.rs.GET / POST / PUT / DELETE —One of these annotations must be
placed on a method. HTTP method annotations are uppercase and take no paramet-
ers.
With @Path on a class and an HTTP method annotating a class method, a simple RESTful
web service is up and running. Let's examine the key annotation starting with @GET . Note
that we won't cover every JAX-RS annotation—that's beyond the scope of this chapter.
Using the @GET annotation
The @javax.ws.rs.GET annotation is a marker annotation for signaling that the web
service is invoked via an HTTP GET . The following code snippet is all there is to the GET
annotation:
@Target(value = {ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
@HttpMethod(value = "GET")
public @interface GET {}
If you're passing in parameters via GET , you should be aware that there's an upper limit on
the size of the request URI. The HTTP specification doesn't define a limit so it would be
dependent on the browser. Web browsers have traditionally limited the URI to anywhere
from 4 KB to 8 KB.
Search WWH ::




Custom Search