Java Reference
In-Depth Information
... the implementation ...
}
The only caveat with this approach is that the concrete subclass must annotate itself with the
@Path annotation to identify it as a service class to the JAX-RS provider.
Deploying Our Service
It is easiest to deploy JAX-RS within a Java EE-certified application server (e.g., JBoss) or
standalone Servlet 3 container (e.g., Tomcat). Before we can do that, we need to write one
simple class that extends javax.ws.rs.core.Application . This class tells our application
server which JAX-RS components we want to register.
package
package javax . ws . rs . core ;
import
import java.util.Collections
java.util.Collections ;
import
import java.util.Set
java.util.Set ;
public
public abstract
abstract class
class Application
Application {
private
private static
static final
final Set < Object > emptySet = Collections . emptySet ();
public
public abstract
abstract Set < Class <?>> getClasses ();
public
public Set < Object > getSingletons () {
return
return emptySet ;
}
}
The getClasses() method returns a list of JAX-RS service classes (and providers, but I'll
get to that in Chapter 6 ). Any JAX-RS service class returned by this method will follow the
per-request model mentioned earlier. When the JAX-RS vendor implementation determines
that an HTTP request needs to be delivered to a method of one of these classes, an instance
of it will be created for the duration of the request and thrown away. You are delegating the
creation of these objects to the JAX-RS runtime.
The getSingletons() method returns a list of JAX-RS service objects (and providers,
too—again, see Chapter 6 ). You, as the application programmer, are responsible for creating
and initializing these objects.
These two methods tell the JAX-RS vendor which services you want deployed. Here's an ex-
ample:
Search WWH ::




Custom Search