You are previewing RESTful Java with JAX-RS.

RESTful Java with JAX-RS

Cover of RESTful Java with JAX-RS by Bill Burke Published by O'Reilly Media, Inc.
O'Reilly logo


All the examples in this book so far have been simple and pretty self-contained. Your RESTful web services will probably need to sit in front of a database and interact with other local and remote services. Your services will also need configuration settings that are described outside of code. I don’t want to get into too much detail, but the servlet and Java EE specifications provide annotations and XML configuration that allow you to get access to various Java EE services and configuration information. Let’s look at how JAX-RS can take advantage of these features.

Older Java EE Containers

Any JAX-RS implementation, whether it sits within a JAX-RS-aware or -unaware servlet container, must support the @Context injection of the javax.servlet.ServletContext and javax.servlet.ServletConfig interfaces. Through these interfaces, you can get access to configuration information expressed in the WAR’s web.xml deployment descriptor. Let’s take this web.xml file, for example:

<?xml version="1.0"?>
   </context-param> <servlet> <servlet-name>JAXRS</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <init-param> <param-name> </param-name> <param-value> </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Rest</servlet-name> <url-pattern>/*</url-pattern> ...

The best content for your career. Discover unlimited learning on demand for around $1/day.