Links: Table of Contents | Single HTML

Jersey 2.29.1 User Guide


Table of Contents

Preface
1. Getting Started
1.1. Creating a New Project from Maven Archetype
1.2. Exploring the Newly Created Project
1.3. Running the Project
1.4. Creating a JavaEE Web Application
1.5. Creating a Web Application that can be deployed on Heroku
1.5.1. Deploy it on Heroku
1.6. Exploring Other Jersey Examples
2. Modules and dependencies
2.1. Java SE Compatibility
2.2. Introduction to Jersey dependencies
2.3. Common Jersey Use Cases
2.3.1. Servlet based application on Glassfish
2.3.2. Servlet based server-side application
2.3.3. Client application on JDK
2.3.4. Server-side application on supported containers
2.4. List of modules
3. JAX-RS Application, Resources and Sub-Resources
3.1. Root Resource Classes
3.1.1. @Path
3.1.2. @GET, @PUT, @POST, @DELETE, ... (HTTP Methods)
3.1.3. @Produces
3.1.4. @Consumes
3.2. Parameter Annotations (@*Param)
3.3. Sub-resources
3.4. Life-cycle of Root Resource Classes
3.5. Rules of Injection
3.6. Use of @Context
3.7. Programmatic resource model
4. Application Deployment and Runtime Environments
4.1. Introduction
4.2. JAX-RS Application Model
4.3. Auto-Discoverable Features
4.3.1. Configuring Feature Auto-discovery Mechanism
4.4. Configuring the Classpath Scanning
4.5. Java SE Deployment Environments
4.5.1. HTTP servers
4.6. Creating programmatic JAX-RS endpoint
4.7. Servlet-based Deployment
4.7.1. Servlet 2.x Container
4.7.2. Servlet 3.x Container
4.7.3. Jersey Servlet container modules
4.8. Java EE Platform
4.8.1. Managed Beans
4.8.2. Context and Dependency Injection (CDI)
4.8.3. Enterprise Java Beans (EJB)
4.8.4. Java EE Servers
4.9. OSGi
4.9.1. Enabling the OSGi shell in Glassfish
4.9.2. WAB Example
4.9.3. HTTP Service Example
4.10. Other Environments
4.10.1. Oracle Java Cloud Service
5. Client API
5.1. Uniform Interface Constraint
5.2. Ease of use and reusing JAX-RS artifacts
5.3. Overview of the Client API
5.3.1. Getting started with the client API
5.3.2. Creating and configuring a Client instance
5.3.3. Targeting a web resource
5.3.4. Identifying resource on WebTarget
5.3.5. Invoking a HTTP request
5.3.6. Example summary
5.3.7. Setting ExecutorService and ScheduledExecutorService
5.4. Java instances and types for representations
5.4.1. Adding support for new representations
5.5. Client Transport Connectors
5.6. Using client request and response filters
5.7. Closing connections
5.8. Injections into client providers
5.9. Securing a Client
5.9.1. Http Authentication Support
6. Reactive JAX-RS Client API
6.1. Motivation for Reactive Client Extension
6.2. Usage and Extension Modules
6.3. Supported Reactive Libraries
6.3.1. RxJava (Observable)
6.3.2. RxJava (Flowable)
6.3.3. Guava (ListenableFuture and Futures)
6.4. Implementing Support for Custom Reactive Libraries (SPI)
7. Representations and Responses
7.1. Representations and Java Types
7.2. Building Responses
7.3. WebApplicationException and Mapping Exceptions to Responses
7.4. Conditional GETs and Returning 304 (Not Modified) Responses
8. JAX-RS Entity Providers
8.1. Introduction
8.2. How to Write Custom Entity Providers
8.2.1. MessageBodyWriter
8.2.2. MessageBodyReader
8.3. Entity Provider Selection
8.4. Jersey MessageBodyWorkers API
8.5. Default Jersey Entity Providers
9. Support for Common Media Type Representations
9.1. JSON
9.1.1. Approaches to JSON Support
9.1.2. MOXy
9.1.3. Java API for JSON Processing (JSON-P)
9.1.4. Jackson (1.x and 2.x)
9.1.5. Jettison
9.1.6. @JSONP - JSON with Padding Support
9.2. XML
9.2.1. Low level XML support
9.2.2. Getting started with JAXB
9.2.3. POJOs
9.2.4. Using custom JAXBContext
9.2.5. MOXy
9.3. Multipart
9.3.1. Overview
9.3.2. Client
9.3.3. Server
10. Filters and Interceptors
10.1. Introduction
10.2. Filters
10.2.1. Server filters
10.2.2. Client filters
10.3. Interceptors
10.4. Filter and interceptor execution order
10.5. Name binding
10.6. Dynamic binding
10.7. Priorities
11. Asynchronous Services and Clients
11.1. Asynchronous Server API
11.1.1. Asynchronous Server-side Callbacks
11.1.2. Chunked Output
11.2. Client API
11.2.1. Asynchronous Client Callbacks
11.2.2. Chunked input
12. URIs and Links
12.1. Building URIs
12.2. Resolve and Relativize
12.3. Link
13. Declarative Hyperlinking
13.1. Dependency
13.2. Links in Representations
13.3. List of Link Injection
13.4. Links from Resources
13.5. Binding Template Parameters
13.6. Conditional Link Injection
13.7. Link Headers
13.8. Prevent Recursive Injection
13.9. Meta-annotation support
13.10. Configure and register
14. Programmatic API for Building Resources
14.1. Introduction
14.2. Programmatic Hello World example
14.2.1. Deployment of programmatic resources
14.3. Additional examples
14.4. Model processors
15. Server-Sent Events (SSE) Support
15.1. What are Server-Sent Events
15.2. When to use Server-Sent Events
15.3. Server-Sent Events API
15.4. Implementing SSE support in a JAX-RS resource (with JAX-RS SSE API)
15.4.1. Simple SSE resource method
15.4.2. Broadcasting with Jersey SSE
15.5. Consuming SSE events within Jersey clients
15.5.1. SseEventSource reconnect support
15.6. Jersey-specific Server-Sent Events API
15.6.1. Implementing SSE support in a JAX-RS resource
15.6.2. Consuming SSE events with Jersey clients
16. Security
16.1. Securing server
16.1.1. SecurityContext
16.1.2. Authorization - securing resources
16.2. Client Security
16.3. OAuth Support
16.3.1. OAuth 1
16.3.2. OAuth 2 Support
17. WADL Support
17.1. WADL introduction
17.2. Configuration
17.3. Extended WADL support
18. Bean Validation Support
18.1. Bean Validation Dependencies
18.2. Enabling Bean Validation in Jersey
18.3. Configuring Bean Validation Support
18.4. Validating JAX-RS resources and methods
18.4.1. Constraint Annotations
18.4.2. Annotation constraints and Validators
18.4.3. Entity Validation
18.4.4. Annotation Inheritance
18.5. @ValidateOnExecution
18.6. Injecting
18.7. Error Reporting
18.7.1. ValidationError
18.8. Example
19. Entity Data Filtering
19.1. Enabling and configuring Entity Filtering in your application
19.2. Components used to describe Entity Filtering concepts
19.3. Using custom annotations to filter entities
19.3.1. Server-side Entity Filtering
19.3.2. Client-side Entity Filtering
19.4. Role-based Entity Filtering using (javax.annotation.security) annotations
19.5. Entity Filtering based on dynamic and configurable query parameters
19.6. Defining custom handling for entity-filtering annotations
19.7. Supporting Entity Data Filtering in custom entity providers or frameworks
19.8. Modules with support for Entity Data Filtering
19.9. Examples
20. MVC Templates
20.1. Viewable
20.2. @Template
20.2.1. Annotating Resource methods
20.2.2. Annotating Resource classes
20.3. Absolute vs. Relative template reference
20.3.1. Relative template reference
20.3.2. Absolute template reference
20.4. Handling errors with MVC
20.4.1. MVC & Bean Validation
20.5. Registration and Configuration
20.6. Supported templating engines
20.6.1. Mustache
20.6.2. Freemarker
20.6.3. JSP
20.7. Writing Custom Templating Engines
20.8. Other Examples
21. Logging
21.1. Logging traffic
21.1.1. Introduction
21.1.2. Configuration and registering
22. Monitoring and Diagnostics
22.1. Monitoring Jersey Applications
22.1.1. Introduction
22.1.2. Event Listeners
22.2. Tracing Support
22.2.1. Configuration options
22.2.2. Tracing Log
22.2.3. Configuring tracing support via HTTP request headers
22.2.4. Format of the HTTP response headers
22.2.5. Tracing Examples
23. Custom Injection and Lifecycle Management
23.1. Implementing Custom Injection Provider
23.2. Defining Custom Injection Annotation
23.3. Custom Life Cycle Management
24. Jersey CDI Container Agnostic Support
24.1. Introduction
24.2. Containers Known to Work With Jersey CDI Support
24.3. Request Scope Binding
24.4. Jersey Weld SE Support
25. Spring DI
25.1. Dependencies
25.2. Registration and Configuration
25.3. Example
26. Jersey Test Framework
26.1. Basics
26.2. Supported Containers
26.3. Running TestNG Tests
26.4. Advanced features
26.4.1. JerseyTest Features
26.4.2. External container
26.4.3. Test Client configuration
26.4.4. Accessing the logged test records programmatically
26.5. Parallel Testing with Jersey Test Framework
27. Building and Testing Jersey
27.1. Checking Out the Source
27.2. Building the Source
27.3. Testing
27.4. Using NetBeans
28. Migration Guide
28.1. Migrating from Jersey 2.23 to 2.27
28.1.1. Breaking Changes
28.1.2. Breaking Changes - Injection Manager
28.1.3. Removed deprecated APIs
28.2. Migrating from Jersey 2.22.1 to 2.23
28.2.1. Release 2.23 Highlights
28.2.2. Deprecated APIs
28.3. Breaking Changes
28.4. Migrating from Jersey 2.22 to 2.22.1
28.4.1. Breaking Changes
28.5. Migrating from Jersey 2.21 to 2.22
28.5.1. Breaking Changes
28.6. Migrating from Jersey 2.19 to 2.20
28.6.1. Breaking Changes
28.7. Migrating from Jersey 2.18 to 2.19
28.7.1. Breaking Changes
28.8. Migrating from Jersey 2.17 to 2.18
28.8.1. Release 2.18 Highlights
28.8.2. Removed deprecated APIs
28.8.3. Breaking Changes
28.9. Migrating from Jersey 2.16 to 2.17
28.9.1. Release 2.17 Highlights
28.10. Migrating from Jersey 2.15 to 2.16
28.10.1. Release 2.16 Highlights
28.10.2. Deprecated APIs
28.10.3. Breaking Changes
28.11. Migrating to 2.15
28.11.1. Release 2.15 Highlights
28.11.2. Breaking Changes
28.12. Migrating from Jersey 2.11 to 2.12
28.12.1. Release 2.12 Highlights
28.12.2. Breaking Changes
28.13. Migrating from Jersey 2.10 to 2.11
28.13.1. Release 2.11 Highlights
28.14. Migrating from Jersey 2.9 to 2.10
28.14.1. Removed deprecated APIs
28.15. Migrating from Jersey 2.8 to 2.9
28.15.1. Release 2.9 Highlights
28.15.2. Changes
28.16. Migrating from Jersey 2.7 to 2.8
28.16.1. Changes
28.17. Migrating from Jersey 2.6 to 2.7
28.17.1. Changes
28.18. Migrating from Jersey 2.5.1 to 2.6
28.18.1. Guava and ASM have been embedded
28.18.2. Deprecated APIs
28.18.3. Removed deprecated APIs
28.19. Migrating from Jersey 2.5 to 2.5.1
28.20. Migrating from Jersey 2.4.1 to 2.5
28.20.1. Client-side API and SPI changes
28.20.2. Other changes
28.21. Migrating from Jersey 2.4 to 2.4.1
28.22. Migrating from Jersey 2.3 to 2.4
28.23. Migrating from Jersey 2.0, 2.1 or 2.2 to 2.3
28.24. Migrating from Jersey 1.x to 2.0
28.24.1. Server API
28.24.2. Migrating Jersey Client API
28.24.3. JSON support changes
A. Configuration Properties
A.1. Common (client/server) configuration properties
A.2. Server configuration properties
A.3. Servlet configuration properties
A.4. Client configuration properties

List of Examples

3.1. Simple hello world root resource class
3.2. Specifying URI path parameter
3.3. PUT method
3.4. Specifying output MIME type
3.5. Using multiple output MIME types
3.6. Server-side content negotiation
3.7. Specifying input MIME type
3.8. Query parameters
3.9. Custom Java type for consuming request parameters
3.10. Processing POSTed HTML form
3.11. Obtaining general map of URI path and/or query parameters
3.12. Obtaining general map of header parameters
3.13. Obtaining general map of form parameters
3.14. Example of the bean which will be used as @BeanParam
3.15. Injection of MyBeanParam as a method parameter:
3.16. Injection of more beans into one resource methods:
3.17. Sub-resource methods
3.18. Sub-resource locators
3.19. Sub-resource locators with empty path
3.20. Sub-resource locators returning sub-type
3.21. Sub-resource locators created from classes
3.22. Sub-resource locators returning resource model
3.23. Injection
3.24. Wrong injection into a singleton scope
3.25. Injection of proxies into singleton
3.26. Example of possible injections
4.1. Deployment agnostic application model
4.2. Reusing Jersey implementation in your custom application model
4.3. Registering SPI implementations using ResourceConfig
4.4. Registering SPI implementations using ResourceConfig subclass
4.5. Using Jersey with JDK HTTP Server
4.6. Using Jersey with Grizzly HTTP Server
4.7. Using Jersey with the Simple framework
4.8. Using Jersey with Jetty HTTP Server
4.9. Using Jersey with Netty HTTP Server
4.10. Hooking up Jersey as a Servlet
4.11. Hooking up Jersey as a Servlet Filter
4.12. Configuring Jersey container Servlet or Filter to use custom Application subclass
4.13. Configuring Jersey container Servlet or Filter to use package scanning
4.14. Configuring Jersey container Servlet or Filter to use a list of classes
4.15. Deployment of a JAX-RS application using @ApplicationPath with Servlet 3.0
4.16. Configuration of maven-war-plugin to ignore missing web.xml
4.17. Deployment of a JAX-RS application using web.xml with Servlet 3.0
4.18. web.xml of a JAX-RS application without an Application subclass
4.19.
4.20.
5.1. POST request with form parameters
5.2. Using JAX-RS Client API
5.3. Using JAX-RS Client API fluently
5.4. Setting JAX-RS Client ExecutorService
5.5. Sending restricted headers with HttpUrlConnector
5.6. Closing connections
5.7. ServiceLocatorClientProvider example
6.1. Excerpt from a synchronous approach while implementing the orchestration layer
6.2. Excerpt from an asynchronous approach while implementing the orchestration layer
6.3. Excerpt from a reactive approach while implementing the orchestration layer
6.4. Synchronous invocation of HTTP requests
6.5. Asynchronous invocation of HTTP requests
6.6. Reactive invocation of HTTP requests
6.7. Creating JAX-RS Client with RxJava reactive extension
6.8. Obtaining Observable<Response> from Jersey/RxJava Client
6.9. Creating JAX-RS Client with RxJava2 reactive extension
6.10. Obtaining Flowable<Response> from Jersey/RxJava Client
6.11. Creating Jersey/Guava Client
6.12. Obtaining ListenableFuture<Response> from Jersey/Guava Client
6.13. Extending RxIvoker
6.14. Extending RxInvokerProvider
7.1. Using File with a specific media type to produce a response
7.2. Returning 201 status code and adding Location header in response to POST request
7.3. Adding an entity body to a custom response
7.4. Throwing exceptions to control response
7.5. Application specific exception implementation
7.6. Mapping generic exceptions to responses
7.7. Conditional GET support
8.1. Example resource class
8.2. MyBean entity class
8.3. MessageBodyWriter example
8.4. Example of assignment of annotations to a response entity
8.5. Client code testing MyBeanMessageBodyWriter
8.6. Result of MyBeanMessageBodyWriter test
8.7. MessageBodyReader example
8.8. Testing MyBeanMessageBodyReader
8.9. Result of testing MyBeanMessageBodyReader
8.10. MessageBodyReader registered on a JAX-RS client
8.11. Result of client code execution
8.12. Usage of MessageBodyWorkers interface
9.1. Simple JAXB bean implementation
9.2. JAXB bean used to generate JSON representation
9.3. Tweaking JSON format using JAXB
9.4. JAXB bean creation
9.5. Constructing a JsonObject (JSON-Processing)
9.6. Constructing a JSONObject (Jettison)
9.7. MoxyJsonConfig - Setting properties.
9.8. Creating ContextResolver<MoxyJsonConfig>
9.9. Setting properties for MOXy providers into Configurable
9.10. Building client with MOXy JSON feature enabled.
9.11. Creating JAX-RS application with MOXy JSON feature enabled.
9.12. Building client with JSON-Processing JSON feature enabled.
9.13. Creating JAX-RS application with JSON-Processing JSON feature enabled.
9.14. ContextResolver<ObjectMapper>
9.15. Building client with Jackson JSON feature enabled.
9.16. Creating JAX-RS application with Jackson JSON feature enabled.
9.17. JAXB beans for JSON supported notations description, simple address bean
9.18. JAXB beans for JSON supported notations description, contact bean
9.19. JAXB beans for JSON supported notations description, initialization
9.20. XML namespace to JSON mapping configuration for Jettison based mapped notation
9.21. JSON expression with XML namespaces mapped into JSON
9.22. JSON Array configuration for Jettison based mapped notation
9.23. JSON expression with JSON arrays explicitly configured via Jersey
9.24. JSON expression produced using badgerfish notation
9.25. ContextResolver<ObjectMapper>
9.26. Building client with Jettison JSON feature enabled.
9.27. Creating JAX-RS application with Jettison JSON feature enabled.
9.28. Simplest case of using @JSONP
9.29. JaxbBean for @JSONP example
9.30. Example of @JSONP with configured parameters.
9.31. Low level XML test - methods added to HelloWorldResource.java
9.32. Planet class
9.33. Resource class
9.34. Method for consuming Planet
9.35. Resource class - JAXBElement
9.36. Client side - JAXBElement
9.37. PlanetJAXBContextProvider
9.38. Using Provider with JAX-RS client
9.39. Add jersey-media-moxy dependency.
9.40. Register the MoxyXmlFeature class.
9.41. Configure and register an MoxyXmlFeature instance.
9.42. Building client with MultiPart feature enabled.
9.43. Creating JAX-RS application with MultiPart feature enabled.
9.44. MultiPart entity
9.45. MultiPart entity in HTTP message.
9.46. FormDataMultiPart entity
9.47. FormDataMultiPart entity in HTTP message.
9.48. Multipart - sending files.
9.49. Resource method using MultiPart as input parameter / return value.
9.50. Use of @FormDataParam annotation
10.1. Container response filter
10.2. Container request filter
10.3. Pre-matching request filter
10.4. Client request filter
10.5. GZIP writer interceptor
10.6. GZIP reader interceptor
10.7. @NameBinding example
10.8. Dynamic binding example
10.9. Priorities example
11.1. Simple async resource
11.2. Simple async method with timeout
11.3. CompletionCallback example
11.4. ChunkedOutput example
11.5. Simple client async invocation
11.6. Simple client fluent async invocation
11.7. Client async callback
11.8. Client async callback for specific entity
11.9. ChunkedInput example
12.1. URI building
12.2. Building URIs using query parameters
13.1. Creating JAX-RS application with Declarative Linking feature enabled.
14.1. A standard resource class
14.2. A programmatic resource
14.3. A programmatic resource
14.4. A programmatic resource
14.5. A programmatic resource
14.6. A programmatic resource
15.1. Adding the SSE dependency
15.2. Simple SSE resource method
15.3. Broadcasting SSE messages (with JAX-RS 2.1 API)
15.4. Consuming SSE events with SseEventSource
15.5. SseEventSource subscribe() methods
15.6. Add jersey-media-sse dependency.
15.7. Simple SSE resource method
15.8. Broadcasting SSE messages
15.9. Registering EventListener with EventSource
15.10. Overriding EventSource.onEvent(InboundEvent) method
16.1. Using SecurityContext for a Resource Selection
16.2. Injecting SecurityContext into a singleton resource
16.3. Securing resources using web.xml
16.4. Registering RolesAllowedDynamicFeature using ResourceConfig
16.5. Registering RolesAllowedDynamicFeature by extending ResourceConfig
16.6. Applying javax.annotation.security to JAX-RS resource methods.
16.7. Build the authorization flow utility
16.8. Perform the OAuth Authorization Flow
16.9. Authenticated requests
16.10. Build feature from Access Token
16.11. Specifying Access Token on a Request.
16.12. Creating Public/Private RSA-SHA1 keys
16.13. Building OAuth 2 Authorization Flow.
17.1. A simple WADL example - JAX-RS resource definition
17.2. A simple WADL example - WADL content
17.3. OPTIONS method returning WADL
17.4. More complex WADL example - JAX-RS resource definition
17.5. More complex WADL example - WADL content
18.1. Configuring Jersey specific properties for Bean Validation.
18.2. Using ValidationConfig to configure Validator.
18.3. Constraint annotations on input parameters
18.4. Constraint annotations on fields
18.5. Constraint annotations on class
18.6. Definition of a constraint annotation
18.7. Validator implementation.
18.8. Entity validation
18.9. Entity validation 2
18.10. Response entity validation
18.11. Validate getter on execution
18.12. Injecting UriInfo into a ConstraintValidator
18.13. Support for injecting Jersey's resources/providers via ConstraintValidatorFactory.
18.14. ValidationError to text/plain
18.15. ValidationError to text/html
18.16. ValidationError to application/xml
18.17. ValidationError to application/json
19.1. Registering and configuring entity-filtering feature on server.
19.2. Registering and configuring entity-filtering feature with security annotations on server.
19.3. Registering and configuring entity-filtering feature based on dynamic and configurable query parameters.
19.4. Registering and configuring entity-filtering feature on client.
19.5. Project
19.6. User
19.7. Task
19.8. ProjectsResource
19.9. ProjectDetailedView
19.10. Annotated Project
19.11. Annotated User
19.12. Annotated Task
19.13. ProjectsResource - Response entity-filtering annotations
19.14. ProjectsResource - Entity-filtering annotations on methods
19.15. Client - Request entity-filtering annotations
19.16. Client - Request entity-filtering annotations
19.17. Sever - Query Parameter driven entity-filtering
19.18.
19.19. Entity-filtering annotation with custom meaning
19.20. Entity Data Filtering support in MOXy JSON binding provider
20.1. Using Viewable in a resource class
20.2. Using @Template on a resource method
20.3. Using @Template on a resource class
20.4. Using absolute path to template in Viewable
20.5. Using @ErrorTemplate on a resource method
20.6. Using @ErrorTemplate with Bean Validation
20.7. Iterating through ValidationError in JSP
20.8. Registering MvcFeature
20.9. Registering FreemarkerMvcFeature
20.10. Setting MvcFeature.TEMPLATE_BASE_PATH value in ResourceConfig
20.11. Setting FreemarkerMvcProperties.TEMPLATE_BASE_PATH value in web.xml
20.12. Including JSP page into JSP page
20.13. Custom TemplateProcessor
20.14. Registering custom TemplateProcessor
21.1. Logging on the client side
21.2. Register LoggingFeature via constructor
21.3. Register LoggingFeature class
22.1. Application event listener
22.2. Request event listener
22.3. Event listener test resource
22.4. Injecting MonitoringStatistics
22.5. Summary level messages
22.6. On demand request, snippet of MVC JSP forwarding
24.1. Bootstrapping Jersey application with Weld support on Grizzly
28.1. Jersey 1 reloader implementation
28.2. Jersey 1 reloader registration
28.3. Jersey 2 reloader implementation
28.4. Jersey 2 reloader registration
28.5. Initializing JAXB-based support with MOXy