Java Reference
In-Depth Information
You will need to define a web.xml file for your JAX-RS deployments. How JAX-RS is de-
ployed within a servlet container varies between JAX-RS-aware (like within Java EE applic-
ation servers or standalone Servlet 3.x containers like Tomcat) and older JAX-RS-unaware
servlet containers. Let's dive into these details.
The Application Class
Before looking at what we have to do to configure a web.xml file, we need to learn about the class. The Application class is the only portable way of
telling JAX-RS which web services ( @Path annotated classes) as well as which filters, inter-
ceptors, MessageBodyReader s, MessageBodyWriter s, and ContextResolver s (providers)
you want deployed. I first introduced you to the Application class back in Chapter 3 :
package javax . ws . rs . core ;
import java.util.Collections
java.util.Collections ;
import java.util.Set
java.util.Set ;
public abstract
abstract class
class Application
Application {
private static
static final
final Set < Object > emptySet =
Collections . emptySet ();
public abstract
abstract Set < Class <?>> getClasses ();
public Set < Object > getSingletons () {
return emptySet ;
The Application class is very simple. All it does is list classes and objects that JAX-RS is
supposed to deploy. The getClasses() method returns a list of JAX-RS web service and
provider classes. JAX-RS web service classes follow the per-request model mentioned in
Chapter 3 . Provider classes are instantiated by the JAX-RS container and registered once per
The getSingletons() method returns a list of preallocated JAX-RS web services and pro-
viders. You, as the application programmer, are responsible for creating these objects. The
JAX-RS runtime will iterate through the list of objects and register them internally. When
these objects are registered, JAX-RS will also inject values for @Context annotated fields
and setter methods.
Search WWH ::

Custom Search