Download Jersey 2.0.1 User Guide
Transcript
Table of Contents ..................................................................................................................................... viii 1. Preface ............................................................................................................... viii 1. Getting Started ............................................................................................................... 1 1.1. Creating a New Project from Maven Archetype ......................................................... 1 1.2. Exploring the Newly Created Project ....................................................................... 1 1.3. Customizing the JAX-RS Resource .......................................................................... 1 1.4. Running the Project .............................................................................................. 1 1.5. Creating a JavaEE Web Application ........................................................................ 1 1.6. Exploring Other Jersey Examples ............................................................................ 1 2. Jersey Modules and Dependencies ..................................................................................... 2 2.1. Sample Scenarios ................................................................................................. 2 2.1.1. Basic Server-Side Application ...................................................................... 2 3. JAX-RS Application, Resources and Sub-Resources .............................................................. 4 3.1. Root Resource Classes .......................................................................................... 4 3.1.1. @Path ...................................................................................................... 5 3.1.2. @GET, @PUT, @POST, @DELETE, ... (HTTP Methods) ................................ 6 3.1.3. @Produces ................................................................................................ 6 3.1.4. @Consumes .............................................................................................. 8 3.2. Parameter Annotations (@*Param) .......................................................................... 8 3.3. Sub-resources ..................................................................................................... 13 3.4. Life-cycle of Root Resource Classes ...................................................................... 17 3.5. Rules of Injection ............................................................................................... 18 3.6. Use of @Context ................................................................................................ 22 3.7. Programmatic resource model ............................................................................... 23 4. Representations and Responses ........................................................................................ 24 4.1. Representations and Java Types ............................................................................ 24 4.2. Building Responses ............................................................................................. 25 4.3. WebApplicationException and Mapping Exceptions to Responses ................................ 25 4.4. Conditional GETs and Returning 304 (Not Modified) Responses ................................. 27 5. URIs and Links ............................................................................................................ 29 5.1. Building URIs .................................................................................................... 29 6. Deploying a RESTful Web Service .................................................................................. 31 7. Client API ................................................................................................................... 34 7.1. Uniform Interface Constraint ................................................................................ 34 7.2. Ease of use and reusing JAX-RS artifacts ................................................................ 35 7.3. Getting started with the Jersey client ...................................................................... 36 7.4. Overview of the API ........................................................................................... 36 7.4.1. Configuring a Client and WebResource ........................................................ 36 7.4.2. Building a request .................................................................................... 37 7.4.3. Receiving a response ................................................................................ 38 7.4.4. Creating new WebResources from a WebResource ......................................... 38 7.4.5. Java instances and types for representations ................................................... 39 7.5. Adding support for new representations .................................................................. 39 7.6. Using filters ....................................................................................................... 40 7.6.1. Supported filters ....................................................................................... 41 7.7. Testing services .................................................................................................. 41 7.8. Security with Http(s)URLConnection ..................................................................... 42 7.8.1. With Http(s)URLConnection ...................................................................... 42 7.8.2. With Apache HTTP client .......................................................................... 43 8. Filters and Interceptors ................................................................................................... 44 9. Message Body Workers .................................................................................................. 45 iii