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.
Any JAX-RS implementation, whether it sits within a
JAX-RS-aware or -unaware servlet container, must support the
@Context injection of the
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
<?xml version="1.0"?> <web-app> <context-param> <param-name>max-customers-size</param-name> <param-value>10</param-value> </context-param> <servlet> <servlet-name>JAXRS</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <init-param> <param-name> javax.ws.rs.Application </param-name> <param-value> com.restfully.shop.services.ShoppingApplication </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Rest</servlet-name> <url-pattern>/*</url-pattern> ...