<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jersey 2.23.2 User Guide</title><link rel="stylesheet" type="text/css" href="css/documentation.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3160303-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'js/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body class="contents"><div class="contents" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div style="float:right"><a href="https://jersey.java.net"><img src="images/jersey_logo.png"></a></div><small>Links:
<a href="index.html">
Table of Contents
</a> | <a href="user-guide.html">
Single HTML
</a></small><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e2"></a>Jersey 2.23.2 User Guide</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="#preface">Preface</a></span></dt><dt><span class="chapter"><a href="#getting-started">1. Getting Started</a></span></dt><dd><dl><dt><span class="section"><a href="#new-from-archetype">1.1. Creating a New Project from Maven Archetype</a></span></dt><dt><span class="section"><a href="#new-project-structure">1.2. Exploring the Newly Created Project</a></span></dt><dt><span class="section"><a href="#running-project">1.3. Running the Project</a></span></dt><dt><span class="section"><a href="#new-webapp">1.4. Creating a JavaEE Web Application</a></span></dt><dt><span class="section"><a href="#heroku-webapp">1.5. Creating a Web Application that can be deployed on Heroku</a></span></dt><dd><dl><dt><span class="section"><a href="#deploy-it-on-heroku">1.5.1. Deploy it on Heroku</a></span></dt></dl></dd><dt><span class="section"><a href="#exploring-jersey-examples">1.6. Exploring Other Jersey Examples</a></span></dt></dl></dd><dt><span class="chapter"><a href="#modules-and-dependencies">2. Modules and dependencies</a></span></dt><dd><dl><dt><span class="section"><a href="#d0e559">2.1. Java SE Compatibility</a></span></dt><dt><span class="section"><a href="#d0e570">2.2. Introduction to Jersey dependencies</a></span></dt><dt><span class="section"><a href="#dependencies">2.3. Common Jersey Use Cases</a></span></dt><dd><dl><dt><span class="section"><a href="#servlet-app-glassfish">2.3.1. Servlet based application on Glassfish</a></span></dt><dt><span class="section"><a href="#servlet-app-general">2.3.2. Servlet based server-side application</a></span></dt><dt><span class="section"><a href="#client-jdk">2.3.3. Client application on JDK</a></span></dt><dt><span class="section"><a href="#server-jdk">2.3.4. Server-side application on supported containers</a></span></dt></dl></dd><dt><span class="section"><a href="#modules">2.4. List of modules</a></span></dt></dl></dd><dt><span class="chapter"><a href="#jaxrs-resources">3. JAX-RS Application, Resources and Sub-Resources</a></span></dt><dd><dl><dt><span class="section"><a href="#d0e1993">3.1. Root Resource Classes</a></span></dt><dd><dl><dt><span class="section"><a href="#d0e2032">3.1.1. @Path</a></span></dt><dt><span class="section"><a href="#d0e2082">3.1.2. @GET, @PUT, @POST, @DELETE, ... (HTTP Methods)</a></span></dt><dt><span class="section"><a href="#d0e2120">3.1.3. @Produces</a></span></dt><dt><span class="section"><a href="#d0e2199">3.1.4. @Consumes</a></span></dt></dl></dd><dt><span class="section"><a href="#d0e2224">3.2. Parameter Annotations (@*Param)</a></span></dt><dt><span class="section"><a href="#d0e2495">3.3. Sub-resources</a></span></dt><dt><span class="section"><a href="#d0e2642">3.4. Life-cycle of Root Resource Classes</a></span></dt><dt><span class="section"><a href="#d0e2713">3.5. Rules of Injection</a></span></dt><dt><span class="section"><a href="#d0e2821">3.6. Use of @Context</a></span></dt><dt><span class="section"><a href="#d0e2849">3.7. Programmatic resource model</a></span></dt></dl></dd><dt><span class="chapter"><a href="#deployment">4. Application Deployment and Runtime Environments</a></span></dt><dd><dl><dt><span class="section"><a href="#deployment.intro">4.1. Introduction</a></span></dt><dt><span class="section"><a href="#environmenmt.appmodel">4.2. JAX-RS Application Model</a></span></dt><dt><span class="section"><a href="#deployment.autodiscoverable">4.3. Auto-Discoverable Features</a></span></dt><dd><dl><dt><span class="section"><a href="#deployment.autodiscovery.config">4.3.1. Configuring Feature Auto-discovery Mechanism</a></span></dt></dl></dd><dt><span class="section"><a href="#deployment.classpath-scanning">4.4. Configuring the Classpath Scanning</a></span></dt><dt><span class="section"><a href="#deployment.javase">4.5. Java SE Deployment Environments</a></span></dt><dd><dl><dt><span class="section"><a href="#deployment.http">4.5.1. HTTP servers</a></span></dt></dl></dd><dt><span class="section"><a href="#deployment.jaxrs.endpoint">4.6. Creating programmatic JAX-RS endpoint</a></span></dt><dt><span class="section"><a href="#deployment.servlet">4.7. Servlet-based Deployment</a></span></dt><dd><dl><dt><span class="section"><a href="#deployment.servlet.2">4.7.1. Servlet 2.x Container</a></span></dt><dt><span class="section"><a href="#deployment.servlet.3">4.7.2. Servlet 3.x Container</a></span></dt><dt><span class="section"><a href="#deployment.servlet.containers">4.7.3. Jersey Servlet container modules</a></span></dt></dl></dd><dt><span class="section"><a href="#deployment.javaee">4.8. Java EE Platform</a></span></dt><dd><dl><dt><span class="section"><a href="#deployment.javaee.managed">4.8.1. Managed Beans</a></span></dt><dt><span class="section"><a href="#deployment.javaee.cdi">4.8.2. Context and Dependency Injection (CDI)</a></span></dt><dt><span class="section"><a href="#deployment.javaee.ejb">4.8.3. Enterprise Java Beans (EJB)</a></span></dt><dt><span class="section"><a href="#deployment.appservers">4.8.4. Java EE Servers</a></span></dt></dl></dd><dt><span class="section"><a href="#deployment.osgi">4.9. OSGi</a></span></dt><dd><dl><dt><span class="section"><a href="#osgi.shell">4.9.1. Enabling the OSGi shell in Glassfish</a></span></dt><dt><span class="section"><a href="#osgi.wab">4.9.2. WAB Example</a></span></dt><dt><span class="section"><a href="#osgi.httpservice">4.9.3. HTTP Service Example</a></span></dt></dl></dd><dt><span class="section"><a href="#deployment.other">4.10. Other Environments</a></span></dt><dd><dl><dt><span class="section"><a href="#deployment.other.cloud">4.10.1. Oracle Java Cloud Service</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#client">5. Client API</a></span></dt><dd><dl><dt><span class="section"><a href="#d0e4160">5.1. Uniform Interface Constraint</a></span></dt><dt><span class="section"><a href="#d0e4203">5.2. Ease of use and reusing JAX-RS artifacts</a></span></dt><dt><span class="section"><a href="#d0e4319">5.3. Overview of the Client API</a></span></dt><dd><dl><dt><span class="section"><a href="#d0e4322">5.3.1. Getting started with the client API</a></span></dt><dt><span class="section"><a href="#d0e4341">5.3.2.
Creating and configuring a Client instance
</a></span></dt><dt><span class="section"><a href="#d0e4525">5.3.3. Targeting a web resource</a></span></dt><dt><span class="section"><a href="#d0e4593">5.3.4. Identifying resource on WebTarget</a></span></dt><dt><span class="section"><a href="#d0e4669">5.3.5. Invoking a HTTP request</a></span></dt><dt><span class="secti