Links: Table of Contents | Single HTML

Jersey 3.0.0 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
5.10. InvocationInterceptors
5.10.1. PreInvocationInterceptor
5.10.2. PostInvocationInterceptor
5.11. InvocationBuilderListener
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.1.7. Java API for JSON Binding (JSON-B)
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. Jersey configuration
15.1. Jersey default configuration provider
15.2. Micro profile configuration provider
16. Server-Sent Events (SSE) Support
16.1. What are Server-Sent Events
16.2. When to use Server-Sent Events
16.3. Server-Sent Events API
16.4. Implementing SSE support in a JAX-RS resource (with JAX-RS SSE API)
16.4.1. Simple SSE resource method
16.4.2. Broadcasting with Jersey SSE
16.5. Consuming SSE events within Jersey clients
16.5.1. SseEventSource reconnect support
16.6. Jersey-specific Server-Sent Events API
16.6.1. Implementing SSE support in a JAX-RS resource
16.6.2. Consuming SSE events with Jersey clients
17. Security
17.1. Securing server
17.1.1. SecurityContext
17.1.2. Authorization - securing resources
17.2. Client Security
17.3. OAuth Support
17.3.1. OAuth 1
17.3.2. OAuth 2 Support
18. WADL Support
18.1. WADL introduction
18.2. Configuration
18.3. Extended WADL support
19. Bean Validation Support
19.1. Bean Validation Dependencies
19.2. Enabling Bean Validation in Jersey
19.3. Configuring Bean Validation Support
19.4. Validating JAX-RS resources and methods
19.4.1. Constraint Annotations
19.4.2. Annotation constraints and Validators
19.4.3. Entity Validation
19.4.4. Annotation Inheritance
19.5. @ValidateOnExecution
19.6. Injecting
19.7. Error Reporting
19.7.1. ValidationError
19.8. Example
20. Entity Data Filtering
20.1. Enabling and configuring Entity Filtering in your application
20.2. Components used to describe Entity Filtering concepts
20.3. Using custom annotations to filter entities
20.3.1. Server-side Entity Filtering
20.3.2. Client-side Entity Filtering
20.4. Role-based Entity Filtering using (jakarta.annotation.security) annotations
20.5. Entity Filtering based on dynamic and configurable query parameters
20.6. Defining custom handling for entity-filtering annotations
20.7. Supporting Entity Data Filtering in custom entity providers or frameworks
20.8. Modules with support for Entity Data Filtering
20.9. Examples
21. MVC Templates
21.1. Viewable
21.2. @Template
21.2.1. Annotating Resource methods
21.2.2. Annotating Resource classes
21.3. Absolute vs. Relative template reference
21.3.1. Relative template reference
21.3.2. Absolute template reference
21.4. Handling errors with MVC
21.4.1. MVC & Bean Validation
21.5. Registration and Configuration
21.6. Supported templating engines
21.6.1. Mustache
21.6.2. Freemarker
21.6.3. JSP
21.7. Writing Custom Templating Engines
21.8. Other Examples
22. Logging
22.1. Logging traffic
22.1.1. Introduction
22.1.2. Configuration and registering
23. Monitoring and Diagnostics
23.1. Monitoring Jersey Applications
23.1.1. Introduction
23.1.2. Event Listeners
23.2. Tracing Support
23.2.1. Configuration options
23.2.2. Tracing Log
23.2.3. Configuring tracing support via HTTP request headers
23.2.4. Format of the HTTP response headers
23.2.5. Tracing Examples
24. Custom Injection and Lifecycle Management
24.1. Implementing Custom Injection Provider
24.2. Defining Custom Injection Annotation
24.3. Custom Life Cycle Management
25. Jersey CDI Container Agnostic Support
25.1. Introduction
25.2. Containers Known to Work With Jersey CDI Support
25.3. Request Scope Binding
25.4. Jersey Weld SE Support
26. Spring DI
26.1. Dependencies
26.2. Registration and Configuration
26.3. Example
27. Jersey Test Framework
27.1. Basics
27.2. Supported Containers
27.3. Running TestNG Tests
27.4. Advanced features
27.4.1. JerseyTest Features
27.4.2. External container
27.4.3. Test Client configuration
27.4.4. Accessing the logged test records programmatically
27.5. Parallel Testing with Jersey Test Framework
28. Building and Testing Jersey
28.1. Checking Out the Source
28.2. Building the Source
28.3. Testing
28.4. Using NetBeans
29. Migration Guide
29.1. Migrating from Jersey 2.25 to 3.0.0.
29.1.1. Breaking Changes
29.1.2. Breaking Changes - Injection Manager
29.1.3. Removed deprecated APIs
29.2. Migrating from Jersey 2.22.1 to 2.25
29.2.1. Release 2.23 Highlights
29.2.2. Deprecated APIs
29.3. Breaking Changes
29.4. Migrating from Jersey 2.22 to 2.22.1
29.4.1. Breaking Changes
29.5. Migrating from Jersey 2.21 to 2.22
29.5.1. Breaking Changes
29.6. Migrating from Jersey 2.19 to 2.20
29.6.1. Breaking Changes
29.7. Migrating from Jersey 2.18 to 2.19
29.7.1. Breaking Changes
29.8. Migrating from Jersey 2.17 to 2.18
29.8.1. Release 2.18 Highlights
29.8.2. Removed deprecated APIs
29.8.3. Breaking Changes
29.9. Migrating from Jersey 2.16 to 2.17
29.9.1. Release 2.17 Highlights
29.10. Migrating from Jersey 2.15 to 2.16
29.10.1. Release 2.16 Highlights
29.10.2. Deprecated APIs
29.10.3. Breaking Changes
29.11. Migrating to 2.15
29.11.1. Release 2.15 Highlights
29.11.2. Breaking Changes
29.12. Migrating from Jersey 2.11 to 2.12
29.12.1. Release 2.12 Highlights
29.12.2. Breaking Changes
29.13. Migrating from Jersey 2.10 to 2.11
29.13.1. Release 2.11 Highlights
29.14. Migrating from Jersey 2.9 to 2.10
29.14.1. Removed deprecated APIs
29.15. Migrating from Jersey 2.8 to 2.9
29.15.1. Release 2.9 Highlights
29.15.2. Changes
29.16. Migrating from Jersey 2.7 to 2.8
29.16.1. Changes
29.17. Migrating from Jersey 2.6 to 2.7
29.17.1. Changes
29.18. Migrating from Jersey 2.5.1 to 2.6
29.18.1. Guava and ASM have been embedded
29.18.2. Deprecated APIs
29.18.3. Removed deprecated APIs
29.19. Migrating from Jersey 2.5 to 2.5.1
29.20. Migrating from Jersey 2.4.1 to 2.5
29.20.1. Client-side API and SPI changes
29.20.2. Other changes
29.21. Migrating from Jersey 2.4 to 2.4.1
29.22. Migrating from Jersey 2.3 to 2.4
29.23. Migrating from Jersey 2.0, 2.1 or 2.2 to 2.3
29.24. Migrating from Jersey 1.x to 2.0
29.24.1. Server API
29.24.2. Migrating Jersey Client API
29.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. ContextResolver<Jsonb>
9.32. Register the feature and ContextResolver<Jsonb>
9.33. Low level XML test - methods added to HelloWorldResource.java
9.34. Planet class
9.35. Resource class
9.36. Method for consuming Planet
9.37. Resource class - JAXBElement
9.38. Client side - JAXBElement
9.39. PlanetJAXBContextProvider
9.40. Using Provider with JAX-RS client
9.41. Add jersey-media-moxy dependency.
9.42. Register the MoxyXmlFeature class.
9.43. Configure and register an MoxyXmlFeature instance.
9.44. Building client with MultiPart feature enabled.
9.45. Creating JAX-RS application with MultiPart feature enabled.
9.46. MultiPart entity
9.47. MultiPart entity in HTTP message.
9.48. FormDataMultiPart entity
9.49. FormDataMultiPart entity in HTTP message.
9.50. Multipart - sending files.
9.51. Resource method using MultiPart as input parameter / return value.
9.52. 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
16.1. Adding the SSE dependency
16.2. Simple SSE resource method
16.3. Broadcasting SSE messages (with JAX-RS 2.1 API)
16.4. Consuming SSE events with SseEventSource
16.5. SseEventSource subscribe() methods
16.6. Add jersey-media-sse dependency.
16.7. Simple SSE resource method
16.8. Broadcasting SSE messages
16.9. Registering EventListener with EventSource
16.10. Overriding EventSource.onEvent(InboundEvent) method
17.1. Using SecurityContext for a Resource Selection
17.2. Injecting SecurityContext into a singleton resource
17.3. Securing resources using web.xml
17.4. Registering RolesAllowedDynamicFeature using ResourceConfig
17.5. Registering RolesAllowedDynamicFeature by extending ResourceConfig
17.6. Applying jakarta.annotation.security to JAX-RS resource methods.
17.7. Build the authorization flow utility
17.8. Perform the OAuth Authorization Flow
17.9. Authenticated requests
17.10. Build feature from Access Token
17.11. Specifying Access Token on a Request.
17.12. Creating Public/Private RSA-SHA1 keys
17.13. Building OAuth 2 Authorization Flow.
18.1. A simple WADL example - JAX-RS resource definition
18.2. A simple WADL example - WADL content
18.3. OPTIONS method returning WADL
18.4. More complex WADL example - JAX-RS resource definition
18.5. More complex WADL example - WADL content
19.1. Configuring Jersey specific properties for Bean Validation.
19.2. Using ValidationConfig to configure Validator.
19.3. Constraint annotations on input parameters
19.4. Constraint annotations on fields
19.5. Constraint annotations on class
19.6. Definition of a constraint annotation
19.7. Validator implementation.
19.8. Entity validation
19.9. Entity validation 2
19.10. Response entity validation
19.11. Validate getter on execution
19.12. Injecting UriInfo into a ConstraintValidator
19.13. Support for injecting Jersey's resources/providers via ConstraintValidatorFactory.
19.14. ValidationError to text/plain
19.15. ValidationError to text/html
19.16. ValidationError to application/xml
19.17. ValidationError to application/json
20.1. Registering and configuring entity-filtering feature on server.
20.2. Registering and configuring entity-filtering feature with security annotations on server.
20.3. Registering and configuring entity-filtering feature based on dynamic and configurable query parameters.
20.4. Registering and configuring entity-filtering feature on client.
20.5. Project
20.6. User
20.7. Task
20.8. ProjectsResource
20.9. ProjectDetailedView
20.10. Annotated Project
20.11. Annotated User
20.12. Annotated Task
20.13. ProjectsResource - Response entity-filtering annotations
20.14. ProjectsResource - Entity-filtering annotations on methods
20.15. Client - Request entity-filtering annotations
20.16. Client - Request entity-filtering annotations
20.17. Sever - Query Parameter driven entity-filtering
20.18.
20.19. Entity-filtering annotation with custom meaning
20.20. Entity Data Filtering support in MOXy JSON binding provider
21.1. Using Viewable in a resource class
21.2. Using @Template on a resource method
21.3. Using @Template on a resource class
21.4. Using absolute path to template in Viewable
21.5. Using @ErrorTemplate on a resource method
21.6. Using @ErrorTemplate with Bean Validation
21.7. Iterating through ValidationError in JSP
21.8. Registering MvcFeature
21.9. Registering FreemarkerMvcFeature
21.10. Setting MvcFeature.TEMPLATE_BASE_PATH value in ResourceConfig
21.11. Setting FreemarkerMvcProperties.TEMPLATE_BASE_PATH value in web.xml
21.12. Including JSP page into JSP page
21.13. Custom TemplateProcessor
21.14. Registering custom TemplateProcessor
22.1. Logging on the client side
22.2. Register LoggingFeature via constructor
22.3. Register LoggingFeature class
23.1. Application event listener
23.2. Request event listener
23.3. Event listener test resource
23.4. Injecting MonitoringStatistics
23.5. Summary level messages
23.6. On demand request, snippet of MVC JSP forwarding
25.1. Bootstrapping Jersey application with Weld support on Grizzly
29.1. Jersey 1 reloader implementation
29.2. Jersey 1 reloader registration
29.3. Jersey 2 reloader implementation
29.4. Jersey 2 reloader registration
29.5. Initializing JAXB-based support with MOXy