Contents
Preface
Audience
Documentation Accessibility
Before You Read This Book
Related Documentation
Conventions
Default Paths and File Names
Part I Introduction
1 Overview
1.1 Java EE 7 Platform Highlights
1.2 Java EE Application Model
1.3 Distributed Multitiered Applications
1.3.1 Security
1.3.2 Java EE Components
1.3.3 Java EE Clients
1.3.3.1 Web Clients
1.3.3.2 Application Clients
1.3.3.3 Applets
1.3.3.4 The JavaBeans Component Architecture
1.3.3.5 Java EE Server Communications
1.3.4 Web Components
1.3.5 Business Components
1.3.6 Enterprise Information System Tier
1.4 Java EE Containers
1.4.1 Container Services
1.4.2 Container Types
1.5 Web Services Support
1.5.1 XML
1.5.2 SOAP Transport Protocol
1.5.3 WSDL Standard Format
1.6 Java EE Application Assembly and Deployment
1.7 Development Roles
1.7.1 Java EE Product Provider
1.7.2 Tool Provider
1.7.3 Application Component Provider
1.7.3.1 Enterprise Bean Developer
1.7.3.2 Web Component Developer
1.7.3.3 Application Client Developer
1.7.4 Application Assembler
1.7.5 Application Deployer and Administrator
1.8 Java EE 7 APIs
1.8.1 Enterprise JavaBeans Technology
1.8.2 Java Servlet Technology
1.8.3 JavaServer Faces Technology
1.8.4 JavaServer Pages Technology
1.8.5 JavaServer Pages Standard Tag Library
1.8.6 Java Persistence API
1.8.7 Java Transaction API
1.8.8 Java API for RESTful Web Services
1.8.9 Managed Beans
1.8.10 Contexts and Dependency Injection for Java EE
1.8.11 Dependency Injection for Java
1.8.12 Bean Validation
1.8.13 Java Message Service API
1.8.14 Java EE Connector Architecture
1.8.15 JavaMail API
1.8.16 Java Authorization Contract for Containers
1.8.17 Java Authentication Service Provider Interface for Containers
1.8.18 Java API for WebSocket
1.8.19 Java API for JSON Processing
1.8.20 Concurrency Utilities for Java EE
1.8.21 Batch Applications for the Java Platform
1.9 Java EE 7 APIs in the Java Platform, Standard Edition 7
1.9.1 Java Database Connectivity API
1.9.2 Java Naming and Directory Interface API
1.9.3 JavaBeans Activation Framework
1.9.4 Java API for XML Processing
1.9.5 Java Architecture for XML Binding
1.9.6 Java API for XML Web Services
1.9.7 SOAP with Attachments API for Java
1.9.8 Java Authentication and Authorization Service
1.9.9 Common Annotations for the Java Platform
1.10 GlassFish Server Tools
2 Using the Tutorial Examples
2.1 Required Software
2.1.1 Java EE 7 Software Development Kit
2.1.1.1 SDK Installation Tips
2.1.2 Java Platform, Standard Edition
2.1.3 Java EE 7 Tutorial Component
2.1.3.1 To Obtain the Tutorial Component Using the Update Tool
2.1.4 NetBeans IDE
2.1.4.1 To Install NetBeans IDE without GlassFish Server
2.1.4.2 To Add GlassFish Server as a Server in NetBeans IDE
2.1.5 Apache Maven
2.2 Starting and Stopping the GlassFish Server
2.2.1 To Start the GlassFish Server Using NetBeans IDE
2.2.2 To Stop the GlassFish Server Using NetBeans IDE
2.2.3 To Start the GlassFish Server from the Command Line
2.2.4 To Stop the GlassFish Server from the Command Line
2.3 Starting the Administration Console
2.3.1 To Start the Administration Console in NetBeans IDE
2.4 Starting and Stopping the Java DB Server
2.4.1 To Start the Database Server Using NetBeans IDE
2.5 Building the Examples
2.6 Tutorial Example Directory Structure
2.7 Java EE 7 Maven Archetypes in the Tutorial
2.7.1 Installing the Tutorial Archetypes
2.7.1.1 Installing the Tutorial Archetypes from NetBeans IDE
2.7.1.2 Installing the Tutorial Archetypes Using Maven
2.8 Getting the Latest Updates to the Tutorial
2.8.1 To Update the Tutorial Using the Command Line
2.8.2 To Update the Tutorial Using NetBeans IDE
2.9 Debugging Java EE Applications
2.9.1 Using the Server Log
2.9.1.1 To Use the Administration Console Log Viewer
2.9.2 Using a Debugger
2.9.2.1 To Debug an Application Using a Debugger
Part II Platform Basics
3 Resource Creation
3.1 Resources and JNDI Naming
3.2 DataSource Objects and Connection Pools
3.3 Creating Resources Administratively
4 Injection
4.1 Resource Injection
4.2 Dependency Injection
4.3 Main Differences Between Resource Injection and Dependency Injection
5 Packaging
5.1 Packaging Applications
5.2 Packaging Enterprise Beans
5.2.1 Packaging Enterprise Beans in EJB JAR Modules
5.2.2 Packaging Enterprise Beans in WAR Modules
5.3 Packaging Web Archives
5.4 Packaging Resource Adapter Archives
Part III The Web Tier
6 Getting Started with Web Applications
6.1 Web Applications
6.2 Web Application Lifecycle
6.3 A Web Module That Uses JavaServer Faces Technology: The hello1 Example
6.3.1 To View the hello1 Web Module Using NetBeans IDE
6.3.1.1 Introduction to Scopes
6.3.2 Packaging and Deploying the hello1 Web Module
6.3.2.1 To Build and Package the hello1 Web Module Using NetBeans IDE
6.3.2.2 To Build and Package the hello1 Web Module Using Maven
6.3.3 Viewing Deployed Web Modules
6.3.3.1 To View Deployed Web Modules Using the Administration Console
6.3.3.2 To View Deployed Web Modules Using the asadmin Command
6.3.3.3 To View Deployed Web Modules Using NetBeans IDE
6.3.4 Running the Deployed hello1 Web Module
6.3.4.1 Dynamic Reloading of Deployed Modules
6.3.5 Undeploying the hello1 Web Module
6.3.5.1 To Undeploy the hello1 Web Module Using NetBeans IDE
6.3.5.2 To Undeploy the hello1 Web Module Using the asadmin Command
6.4 A Web Module That Uses Java Servlet Technology: The hello2 Example
6.4.1 Mapping URLs to Web Components
6.4.2 Examining the hello2 Web Module
6.4.2.1 To View the hello2 Web Module Using NetBeans IDE
6.4.3 Running the hello2 Example
6.4.3.1 To Run the hello2 Example Using NetBeans IDE
6.4.3.2 To Run the hello2 Example Using Maven
6.5 Configuring Web Applications
6.5.1 Setting Context Parameters
6.5.1.1 To Add a Context Parameter Using NetBeans IDE
6.5.1.2 To Create a web.xml File Using NetBeans IDE
6.5.2 Declaring Welcome Files
6.5.3 Mapping Errors to Error Screens
6.5.3.1 To Set Up Error Mapping Using NetBeans IDE
6.5.4 Declaring Resource References
6.5.4.1 Declaring a Reference to a Resource
6.5.4.2 Declaring a Reference to a Web Service
6.6 Further Information about Web Applications
7 JavaServer Faces Technology
7.1 What Is a JavaServer Faces Application?
7.2 JavaServer Faces Technology Benefits
7.3 A Simple JavaServer Faces Application
7.4 User Interface Component Model
7.4.1 User Interface Component Classes
7.4.2 Component Rendering Model
7.4.3 Conversion Model
7.4.4 Event and Listener Model
7.4.5 Validation Model
7.5 Navigation Model
7.6 The Lifecycle of a JavaServer Faces Application
7.6.1 Overview of the JavaServer Faces Lifecycle
7.6.2 Restore View Phase
7.6.3 Apply Request Values Phase
7.6.4 Process Validations Phase
7.6.5 Update Model Values Phase
7.6.6 Invoke Application Phase
7.6.7 Render Response Phase
7.7 Further Information about JavaServer Faces Technology
8 Introduction to Facelets
8.1 What Is Facelets?
8.2 The Lifecycle of a Facelets Application
8.3 Developing a Simple Facelets Application
8.3.1 Creating a Facelets Application
8.3.1.1 Developing a Managed Bean
8.3.1.2 Creating Facelets Views
8.3.2 Configuring the Application
8.3.3 Running the guessnumber-jsf Facelets Example
8.3.3.1 To Build, Package, and Deploy the guessnumber-jsf Example Using NetBeans IDE
8.3.3.2 To Build, Package, and Deploy the guessnumber-jsf Example Using Maven
8.3.3.3 To Run the guessnumber-jsf Example
8.4 Using Facelets Templates
8.5 Composite Components
8.6 Web Resources
8.7 Relocatable Resources
8.8 Resource Library Contracts
8.8.1 The hello1-rlc Example Application
8.8.1.1 Configuring the hello1-rlc Example
8.8.1.2 The Facelets Pages for the hello1-rlc Example
8.8.1.3 To Build, Package, and Deploy the hello1-rlc Example Using NetBeans IDE
8.8.1.4 To Build, Package, and Deploy the hello1-rlc Example Using Maven and the asadmin Command
8.8.1.5 To Run the hello1-rlc Example
8.9 HTML5 Friendly Markup
8.9.1 Using Pass-through Elements
8.9.2 Using Pass-through Attributes
8.9.3 The reservation Example Application
8.9.3.1 The Facelets Pages for the reservation Application
8.9.3.2 The Managed Bean for the reservation Application
8.9.3.3 To Build, Package, and Deploy the reservation Example Using NetBeans IDE
8.9.3.4 To Build, Package, and Deploy the reservation Example Using Maven and the asadmin Command
8.9.3.5 To Run the reservation Example
9 Expression Language
9.1 Overview of the EL
9.2 Immediate and Deferred Evaluation Syntax
9.2.1 Immediate Evaluation
9.2.2 Deferred Evaluation
9.3 Value and Method Expressions
9.3.1 Value Expressions
9.3.1.1 Referencing Objects Using Value Expressions
9.3.1.2 Referring to Object Properties Using Value Expressions
9.3.1.3 Where Value Expressions Can Be Used
9.3.2 Method Expressions
9.3.2.1 Parameterized Method Calls
9.4 Literal Expressions
9.5 Operators
9.6 Reserved Words
9.7 Examples of EL Expressions
10 Using JavaServer Faces Technology in Web Pages
10.1 Setting Up a Page
10.2 Adding Components to a Page Using HTML Tag Library Tags
10.2.1 Common Component Tag Attributes
10.2.1.1 The id Attribute
10.2.1.2 The immediate Attribute
10.2.1.3 The rendered Attribute
10.2.1.4 The style and styleClass Attributes
10.2.1.5 The value and binding Attributes
10.2.2 Adding HTML Head and Body Tags
10.2.3 Adding a Form Component
10.2.4 Using Text Components
10.2.4.1 Rendering a Field with the h:inputText Tag
10.2.4.2 Rendering a Password Field with the h:inputSecret Tag
10.2.4.3 Rendering a Label with the h:outputLabel Tag
10.2.4.4 Rendering a Link with the h:outputLink Tag
10.2.4.5 Displaying a Formatted Message with the h:outputFormat Tag
10.2.5 Using Command Component Tags for Performing Actions and Navigation
10.2.5.1 Rendering a Button with the h:commandButton Tag
10.2.5.2 Rendering a Link with the h:commandLink Tag
10.2.6 Adding Graphics and Images with the h:graphicImage Tag
10.2.7 Laying Out Components with the h:panelGrid and h:panelGroup Tags
10.2.8 Displaying Components for Selecting One Value
10.2.8.1 Displaying a Check Box Using the h:selectBooleanCheckbox Tag
10.2.8.2 Displaying a Menu Using the h:selectOneMenu Tag
10.2.9 Displaying Components for Selecting Multiple Values
10.2.10 Using the f:selectItem and f:selectItems Tags
10.2.10.1 Using the f:selectItems Tag
10.2.10.2 Using the f:selectItem Tag
10.2.11 Displaying the Results from Selection Components
10.2.12 Using Data-Bound Table Components
10.2.13 Displaying Error Messages with the h:message and h:messages Tags
10.2.14 Creating Bookmarkable URLs with the h:button and h:link Tags
10.2.15 Using View Parameters to Configure Bookmarkable URLs
10.2.16 The bookmarks Example Application
10.2.16.1 To Build, Package, and Deploy the bookmarks Example Using NetBeans IDE
10.2.16.2 To Build, Package, and Deploy the bookmarks Example Using Maven and the asadmin Command
10.2.16.3 To Run the bookmarks Example
10.2.17 Resource Relocation Using h:outputScript and h:outputStylesheet Tags
10.3 Using Core Tags
11 Using Converters, Listeners, and Validators
11.1 Using the Standard Converters
11.1.1 Converting a Component's Value
11.1.2 Using DateTimeConverter
11.1.3 Using NumberConverter
11.2 Registering Listeners on Components
11.2.1 Registering a Value-Change Listener on a Component
11.2.2 Registering an Action Listener on a Component
11.3 Using the Standard Validators
11.3.1 Validating a Component's Value
11.3.2 Using LongRangeValidator
11.4 Referencing a Managed Bean Method
11.4.1 Referencing a Method That Performs Navigation
11.4.2 Referencing a Method That Handles an Action Event
11.4.3 Referencing a Method That Performs Validation
11.4.4 Referencing a Method That Handles a Value-Change Event
12 Developing with JavaServer Faces Technology
12.1 Managed Beans in JavaServer Faces Technology
12.1.1 Creating a Managed Bean
12.1.2 Using the EL to Reference Managed Beans
12.2 Writing Bean Properties
12.2.1 Writing Properties Bound to Component Values
12.2.1.1 UIInput and UIOutput Properties
12.2.1.2 UIData Properties
12.2.1.3 UISelectBoolean Properties
12.2.1.4 UISelectMany Properties
12.2.1.5 UISelectOne Properties
12.2.1.6 UISelectItem Properties
12.2.1.7 UISelectItems Properties
12.2.2 Writing Properties Bound to Component Instances
12.2.3 Writing Properties Bound to Converters, Listeners, or Validators
12.3 Writing Managed Bean Methods
12.3.1 Writing a Method to Handle Navigation
12.3.2 Writing a Method to Handle an Action Event
12.3.3 Writing a Method to Perform Validation
12.3.4 Writing a Method to Handle a Value-Change Event
12.4 Using Bean Validation
12.4.1 Validating Null and Empty Strings
13 Using Ajax with JavaServer Faces Technology
13.1 Overview of Ajax
13.2 Using Ajax Functionality with JavaServer Faces Technology
13.3 Using Ajax with Facelets
13.3.1 Using the f:ajax Tag
13.4 Sending an Ajax Request
13.4.1 Using the event Attribute
13.4.2 Using the execute Attribute
13.4.3 Using the immediate Attribute
13.4.4 Using the listener Attribute
13.5 Monitoring Events on the Client
13.6 Handling Errors
13.7 Receiving an Ajax Response
13.8 Partial Processing and Partial Rendering
13.9 Ajax Request Lifecycle
13.10 Grouping of Components
13.11 Loading JavaScript as a Resource
13.11.1 Using JavaScript API in a Facelets Application
13.11.2 Using the @ResourceDependency Annotation in a Bean Class
13.12 The ajaxguessnumber Example Application
13.12.1 The ajaxguessnumber Source Files
13.12.1.1 The ajaxgreeting.xhtml Facelets Page
13.12.1.2 The UserNumberBean Backing Bean
13.12.1.3 The DukesNumberBean CDI Bean
13.12.2 Running the ajaxguessnumber Example
13.12.2.1 To Build, Package, and Deploy the ajaxguessnumber Example Using NetBeans IDE
13.12.2.2 To Build, Package, and Deploy the ajaxguessnumber Example Using Maven
13.12.2.3 To Run the ajaxguessnumber Example
13.13 Further Information about Ajax in JavaServer Faces Technology
14 Composite Components: Advanced Topics and Example
14.1 Attributes of a Composite Component
14.2 Invoking a Managed Bean
14.3 Validating Composite Component Values
14.4 The compositecomponentlogin Example Application
14.4.1 The Composite Component File
14.4.2 The Using Page
14.4.3 The Managed Bean
14.4.4 Running the compositecomponentlogin Example
14.4.4.1 To Build, Package, and Deploy the compositecomponentlogin Example Using NetBeans IDE
14.4.4.2 To Build, Package, and Deploy the compositecomponentlogin Example Using Maven
14.4.4.3 To Run the compositecomponentlogin Example
15 Creating Custom UI Components and Other Custom Objects
15.1 Determining Whether You Need a Custom Component or Renderer
15.1.1 When to Use a Custom Component
15.1.2 When to Use a Custom Renderer
15.1.3 Component, Renderer, and Tag Combinations
15.2 Understanding the Image Map Example
15.2.1 Why Use JavaServer Faces Technology to Implement an Image Map?
15.2.2 Understanding the Rendered HTML
15.2.3 Understanding the Facelets Page
15.2.4 Configuring Model Data
15.2.5 Summary of the Image Map Application Classes
15.3 Steps for Creating a Custom Component
15.4 Creating Custom Component Classes
15.4.1 Specifying the Component Family
15.4.2 Performing Encoding
15.4.3 Performing Decoding
15.4.4 Enabling Component Properties to Accept Expressions
15.4.5 Saving and Restoring State
15.5 Delegating Rendering to a Renderer
15.5.1 Creating the Renderer Class
15.5.2 Identifying the Renderer Type
15.6 Implementing an Event Listener
15.6.1 Implementing Value-Change Listeners
15.6.2 Implementing Action Listeners
15.7 Handling Events for Custom Components
15.8 Defining the Custom Component Tag in a Tag Library Descriptor
15.9 Using a Custom Component
15.10 Creating and Using a Custom Converter
15.10.1 Creating a Custom Converter
15.10.2 Using a Custom Converter
15.11 Creating and Using a Custom Validator
15.11.1 Implementing the Validator Interface
15.11.2 Specifying a Custom Tag
15.11.3 Using a Custom Validator
15.12 Binding Component Values and Instances to Managed Bean Properties
15.12.1 Binding a Component Value to a Property
15.12.2 Binding a Component Value to an Implicit Object
15.12.3 Binding a Component Instance to a Bean Property
15.13 Binding Converters, Listeners, and Validators to Managed Bean Properties
16 Configuring JavaServer Faces Applications
16.1 Using Annotations to Configure Managed Beans
16.1.1 Using Managed Bean Scopes
16.1.1.1 Eager Application-Scoped Beans
16.2 Application Configuration Resource File
16.2.1 Ordering of Application Configuration Resource Files
16.3 Using Faces Flows
16.3.1 Packaging Flows in an Application
16.3.2 The Simplest Possible Flow: The simple-flow Example Application
16.3.2.1 To Build, Package, and Deploy the simple-flow Example Using NetBeans IDE
16.3.2.2 To Build, Package, and Deploy the simple-flow Example Using Maven and the asadmin Command
16.3.2.3 To Run the simple-flow Example
16.3.3 The checkout-module Example Application
16.3.3.1 The Facelets Pages for the checkout-module Example
16.3.3.2 Using a Configuration File to Configure a Flow
16.3.3.3 Using a Java Class to Configure a Flow
16.3.3.4 The Flow-Scoped Managed Beans
16.3.3.5 To Build, Package, and Deploy the checkout-module Example Using NetBeans IDE
16.3.3.6 To Build, Package, and Deploy the checkout-module Example Using Maven and the asadmin Command
16.3.3.7 To Run the checkout-module Example
16.4 Configuring Managed Beans
16.4.1 Using the managed-bean Element
16.4.2 Initializing Properties Using the managed-property Element
16.4.2.1 Referencing a Java Enum Type
16.4.2.2 Referencing a Context Initialization Parameter
16.4.2.3 Initializing Map Properties
16.4.2.4 Initializing Array and List Properties
16.4.2.5 Initializing Managed Bean Properties
16.4.3 Initializing Maps and Lists
16.5 Registering Application Messages
16.5.1 Using FacesMessage to Create a Message
16.5.2 Referencing Error Messages
16.6 Using Default Validators
16.7 Registering a Custom Validator
16.8 Registering a Custom Converter
16.9 Configuring Navigation Rules
16.9.1 To Configure a Navigation Rule
16.10 Registering a Custom Renderer with a Render Kit
16.11 Registering a Custom Component
16.12 Basic Requirements of a JavaServer Faces Application
16.12.1 Configuring an Application with a Web Deployment Descriptor
16.12.1.1 Identifying the Servlet for Lifecycle Processing
16.12.1.2 To Specify a Path to an Application Configuration Resource File
16.12.1.3 To Specify Where State Is Saved
16.12.2 Configuring Project Stage
16.12.3 Including the Classes, Pages, and Other Resources
17 Java Servlet Technology
17.1 What Is a Servlet?
17.2 Servlet Lifecycle
17.2.1 Handling Servlet Lifecycle Events
17.2.1.1 Defining the Listener Class
17.2.2 Handling Servlet Errors
17.3 Sharing Information
17.3.1 Using Scope Objects
17.3.2 Controlling Concurrent Access to Shared Resources
17.4 Creating and Initializing a Servlet
17.5 Writing Service Methods
17.5.1 Getting Information from Requests
17.5.2 Constructing Responses
17.6 Filtering Requests and Responses
17.6.1 Programming Filters
17.6.2 Programming Customized Requests and Responses
17.6.3 Specifying Filter Mappings
17.6.3.1 To Specify Filter Mappings Using NetBeans IDE
17.7 Invoking Other Web Resources
17.7.1 Including Other Resources in the Response
17.7.2 Transferring Control to Another Web Component
17.8 Accessing the Web Context
17.9 Maintaining Client State
17.9.1 Accessing a Session
17.9.2 Associating Objects with a Session
17.9.3 Session Management
17.9.3.1 To Set the Timeout Period Using NetBeans IDE
17.9.4 Session Tracking
17.10 Finalizing a Servlet
17.10.1 Tracking Service Requests
17.10.2 Notifying Methods to Shut Down
17.10.3 Creating Polite Long-Running Methods
17.11 Uploading Files with Java Servlet Technology
17.11.1 The @MultipartConfig Annotation
17.11.2 The getParts and getPart Methods
17.12 Asynchronous Processing
17.12.1 Asynchronous Processing in Servlets
17.12.2 Waiting for a Resource
17.13 Non-Blocking I/O
17.13.1 Reading a Large HTTP POST Request Using Non-Blocking I/O
17.14 Protocol Upgrade Processing
17.15 The mood Example Application
17.15.1 Components of the mood Example Application
17.15.2 Running the mood Example
17.15.2.1 To Run the mood Example Using NetBeans IDE
17.15.2.2 To Run the mood Example Using Maven
17.16 The fileupload Example Application
17.16.1 Architecture of the fileupload Example Application
17.16.2 Running the fileupload Example
17.16.2.1 To Build, Package, and Run the fileupload Example Using NetBeans IDE
17.16.2.2 To Build, Package, and Deploy the fileupload Example Using Maven
17.16.2.3 To Run the fileupload Example
17.17 The dukeetf Example Application
17.17.1 Architecture of the dukeetf Example Application
17.17.1.1 The Servlet
17.17.1.2 The Enterprise Bean
17.17.1.3 The HTML Page
17.17.2 Running the dukeetf Example Application
17.17.2.1 To Run the dukeetf Example Application Using NetBeans IDE
17.17.2.2 To Run the dukeetf Example Application Using Maven
17.18 Further Information about Java Servlet Technology
18 Java API for WebSocket
18.1 Introduction to WebSocket
18.2 Creating WebSocket Applications in Java EE
18.3 Programmatic Endpoints
18.4 Annotated Endpoints
18.5 Sending and Receiving Messages
18.5.1 Sending Messages
18.5.1.1 Sending Messages to All Peers Connected to an Endpoint
18.5.2 Receiving Messages
18.6 Maintaining Client State
18.7 Using Encoders and Decoders
18.7.1 Implementing Encoders to Convert Java Objects into WebSocket Messages
18.7.2 Implementing Decoders to Convert WebSocket Messages into Java Objects
18.8 Path Parameters
18.9 Handling Errors
18.10 The dukeetf2 Example Application
18.10.1 Architecture of the dukeetf2 Sample Application
18.10.1.1 The Endpoint
18.10.1.2 The Enterprise Bean
18.10.1.3 The HTML Page
18.10.2 Running the dukeetf2 Example Application
18.10.2.1 To Run the dukeetf2 Example Application Using NetBeans IDE
18.10.2.2 To Run the dukeetf2 Example Application Using Maven
18.11 The websocketbot Example Application
18.11.1 Architecture of the websocketbot Example Application
18.11.1.1 The CDI Bean
18.11.1.2 The WebSocket Endpoint
18.11.1.3 The Application Messages
18.11.1.4 The Encoder Classes
18.11.1.5 The Message Decoder
18.11.1.6 The HTML Page
18.11.2 Running the websocketbot Example Application
18.11.2.1 To Configure a Proxy Server in the GlassFish Server
18.11.2.2 To Run the websocketbot Example Application Using NetBeans IDE
18.11.2.3 To Run the websocketbot Example Application Using Maven
18.11.2.4 To Test the websocketbot Example Application
18.12 Further Information about WebSocket
19 JSON Processing
19.1 Introduction to JSON
19.1.1 JSON Syntax
19.1.2 Uses of JSON
19.1.3 Generating and Parsing JSON Data
19.2 JSON Processing in Java EE
19.3 Using the Object Model API
19.3.1 Creating an Object Model from JSON Data
19.3.2 Creating an Object Model from Application Code
19.3.3 Navigating an Object Model
19.3.4 Writing an Object Model to a Stream
19.4 Using the Streaming API
19.4.1 Reading JSON Data Using a Parser
19.4.2 Writing JSON Data Using a Generator
19.5 JSON in Java EE RESTful Web Services
19.6 The jsonpmodel Example Application
19.6.1 Components of the jsonpmodel Example Application
19.6.2 Running the jsonpmodel Example Application
19.6.2.1 To Run the jsonpmodel Example Application Using NetBeans IDE
19.6.2.2 To Run the jsonpmodel Example Application using Maven
19.7 The jsonpstreaming Example Application
19.7.1 Components of the jsonpstreaming Example Application
19.7.2 Running the jsonpstreaming Example Application
19.7.2.1 To Run the jsonpstreaming Example Application Using NetBeans IDE
19.7.2.2 To Run the jsonpstreaming Example Application Using Maven
19.8 Further Information about the Java API for JSON Processing
20 Internationalizing and Localizing Web Applications
20.1 Java Platform Localization Classes
20.2 Providing Localized Messages and Labels
20.2.1 Establishing the Locale
20.2.2 Setting the Resource Bundle
20.2.3 Retrieving Localized Messages
20.3 Date and Number Formatting
20.4 Character Sets and Encodings
20.4.1 Character Sets
20.4.2 Character Encoding
Part IV Web Services
21 Introduction to Web Services
21.1 What Are Web Services?
21.2 Types of Web Services
21.2.1 "Big" Web Services
21.2.2 RESTful Web Services
21.3 Deciding Which Type of Web Service to Use
22 Building Web Services with JAX-WS
22.1 Creating a Simple Web Service and Clients with JAX-WS
22.1.1 Requirements of a JAX-WS Endpoint
22.1.2 Coding the Service Endpoint Implementation Class
22.1.3 Building, Packaging, and Deploying the Service
22.1.3.1 To Build, Package, and Deploy the Service Using NetBeans IDE
22.1.3.2 To Build, Package, and Deploy the Service Using Maven
22.1.4 Testing the Methods of a Web Service Endpoint
22.1.4.1 To Test the Service without a Client
22.1.5 A Simple JAX-WS Application Client
22.1.5.1 Coding the Application Client
22.1.5.2 Running the Application Client
22.1.6 A Simple JAX-WS Web Client
22.1.6.1 Coding the Servlet
22.1.6.2 Running the Web Client
22.2 Types Supported by JAX-WS
22.2.1 Schema-to-Java Mapping
22.2.2 Java-to-Schema Mapping
22.3 Web Services Interoperability and JAX-WS
22.4 Further Information about JAX-WS
23 Building RESTful Web Services with JAX-RS
23.1 What Are RESTful Web Services?
23.2 Creating a RESTful Root Resource Class
23.2.1 Developing RESTful Web Services with JAX-RS
23.2.2 Overview of a JAX-RS Application
23.2.3 The @Path Annotation and URI Path Templates
23.2.4 Responding to HTTP Methods and Requests
23.2.4.1 The Request Method Designator Annotations
23.2.4.2 Using Entity Providers to Map HTTP Response and Request Entity Bodies
23.2.5 Using @Consumes and @Produces to Customize Requests and Responses
23.2.5.1 The @Produces Annotation
23.2.5.2 The @Consumes Annotation
23.2.6 Extracting Request Parameters
23.3 Example Applications for JAX-RS
23.3.1 Creating A Simple RESTful Web Service
23.3.1.1 To Create a RESTful Web Service Using NetBeans IDE
23.3.2 The rsvp Example Application
23.3.2.1 Components of the rsvp Example Application
23.3.2.2 Running the rsvp Example Application
23.3.3 Real-World Examples
23.4 Further Information about JAX-RS
24 Accessing REST Resources with the JAX-RS Client API
24.1 Overview of the Client API
24.1.1 Creating a Basic Client Request using the Client API
24.1.1.1 Obtaining the Client Instance
24.1.1.2 Setting the Client Target
24.1.1.3 Setting Path Parameters in Targets
24.1.1.4 Invoking the Request
24.2 Using the Client API in the JAX-RS Example Applications
24.2.1 The Client API in the rsvp Example Application
24.2.2 The Client API in the customer Example Application
24.3 Advanced Features of the Client API
24.3.1 Configuring the Client Request
24.3.1.1 Setting Message Headers in the Client Request
24.3.1.2 Setting Cookies in the Client Request
24.3.1.3 Adding Filters to the Client
24.3.2 Asynchronous Invocations in the Client API
24.3.2.1 Using Custom Callbacks in Asynchronous Invocations
25 JAX-RS: Advanced Topics and Example
25.1 Annotations for Field and Bean Properties of Resource Classes
25.1.1 Extracting Path Parameters
25.1.2 Extracting Query Parameters
25.1.3 Extracting Form Data
25.1.4 Extracting the Java Type of a Request or Response
25.2 Validating Resource Data with Bean Validation
25.2.1 Using Constraint Annotations on Resource Methods
25.2.2 Validating Entity Data
25.2.3 Validation Exception Handling and Response Codes
25.3 Subresources and Runtime Resource Resolution
25.3.1 Subresource Methods
25.3.2 Subresource Locators
25.4 Integrating JAX-RS with EJB Technology and CDI
25.5 Conditional HTTP Requests
25.6 Runtime Content Negotiation
25.7 Using JAX-RS With JAXB
25.7.1 Using Java Objects to Model Your Data
25.7.2 Starting from an Existing XML Schema Definition
25.7.3 Using JSON with JAX-RS and JAXB
25.8 The customer Example Application
25.8.1 Overview of the customer Example Application
25.8.2 The Customer and Address Entity Classes
25.8.3 The CustomerService Class
25.8.4 Using the JAX-RS Client in the CustomerBean Classes
25.8.5 Running the customer Example
25.8.5.1 To Build, Package, and Deploy the customer Example Using NetBeans IDE
25.8.5.2 To Build, Package, and Deploy the customer Example Using Maven
Part V Enterprise Beans
26 Enterprise Beans
26.1 What Is an Enterprise Bean?
26.1.1 Benefits of Enterprise Beans
26.1.2 When to Use Enterprise Beans
26.1.3 Types of Enterprise Beans
26.2 What Is a Session Bean?
26.2.1 Types of Session Beans
26.2.1.1 Stateful Session Beans
26.2.1.2 Stateless Session Beans
26.2.1.3 Singleton Session Beans
26.2.2 When to Use Session Beans
26.3 What Is a Message-Driven Bean?
26.3.1 What Makes Message-Driven Beans Different from Session Beans?
26.3.2 When to Use Message-Driven Beans
26.4 Accessing Enterprise Beans
26.4.1 Using Enterprise Beans in Clients
26.4.1.1 Portable JNDI Syntax
26.4.2 Deciding on Remote or Local Access
26.4.3 Local Clients
26.4.3.1 Accessing Local Enterprise Beans Using the No-Interface View
26.4.3.2 Accessing Local Enterprise Beans That Implement Business Interfaces
26.4.4 Remote Clients
26.4.5 Web Service Clients
26.4.6 Method Parameters and Access
26.4.6.1 Isolation
26.4.6.2 Granularity of Accessed Data
26.5 The Contents of an Enterprise Bean
26.6 Naming Conventions for Enterprise Beans
26.7 The Lifecycles of Enterprise Beans
26.7.1 The Lifecycle of a Stateful Session Bean
26.7.2 The Lifecycle of a Stateless Session Bean
26.7.3 The Lifecycle of a Singleton Session Bean
26.7.4 The Lifecycle of a Message-Driven Bean
26.8 Further Information about Enterprise Beans
27 Getting Started with Enterprise Beans
27.1 Creating the Enterprise Bean
27.1.1 Coding the Enterprise Bean Class
27.1.2 Creating the converter Web Client
27.1.3 Running the converter Example
27.1.3.1 To Run the converter Example in NetBeans IDE
27.1.3.2 To Run the converter Example Using Maven
27.2 Modifying the Java EE Application
27.2.1 To Modify a Class File
28 Running the Enterprise Bean Examples
28.1 The cart Example
28.1.1 The Business Interface
28.1.2 Session Bean Class
28.1.2.1 Lifecycle Callback Methods
28.1.2.2 Business Methods
28.1.3 The @Remove Method
28.1.4 Helper Classes
28.1.5 Running the cart Example
28.1.5.1 To Run the cart Example Using NetBeans IDE
28.1.5.2 To Run the cart Example Using Maven
28.2 A Singleton Session Bean Example: counter
28.2.1 Creating a Singleton Session Bean
28.2.1.1 Initializing Singleton Session Beans
28.2.1.2 Managing Concurrent Access in a Singleton Session Bean
28.2.1.3 Handling Errors in a Singleton Session Bean
28.2.2 The Architecture of the counter Example
28.2.3 Running the counter Example
28.2.3.1 To Run the counter Example Using NetBeans IDE
28.2.3.2 To Run the counter Example Using Maven
28.3 A Web Service Example: helloservice
28.3.1 The Web Service Endpoint Implementation Class
28.3.2 Stateless Session Bean Implementation Class
28.3.3 Running the helloservice Example
28.3.3.1 To Build, Package, and Deploy the helloservice Example Using NetBeans IDE
28.3.3.2 To Build, Package, and Deploy the helloservice Example Using Maven
28.3.3.3 To Test the Service without a Client
28.4 Using the Timer Service
28.4.1 Creating Calendar-Based Timer Expressions
28.4.1.1 Specifying Multiple Values in Calendar Expressions
28.4.2 Programmatic Timers
28.4.2.1 The @Timeout Method
28.4.2.2 Creating Programmatic Timers
28.4.3 Automatic Timers
28.4.4 Canceling and Saving Timers
28.4.5 Getting Timer Information
28.4.6 Transactions and Timers
28.4.7 The timersession Example
28.4.8 Running the timersession Example
28.4.8.1 To Run the timersession Example Using NetBeans IDE
28.4.8.2 To Build, Package, and Deploy the timersession Example Using Maven
28.4.8.3 To Run the Web Client
28.5 Handling Exceptions
29 Using the Embedded Enterprise Bean Container
29.1 Overview of the Embedded Enterprise Bean Container
29.2 Developing Embeddable Enterprise Bean Applications
29.2.1 Running Embedded Applications
29.2.2 Creating the Enterprise Bean Container
29.2.2.1 Explicitly Specifying Enterprise Bean Modules to be Initialized
29.2.3 Looking Up Session Bean References
29.2.4 Shutting Down the Enterprise Bean Container
29.3 The standalone Example Application
29.3.1 Runing the standalone Example Application in NetBeans IDE
29.3.2 Running the standalone Example Application using Maven
30 Using Asynchronous Method Invocation in Session Beans
30.1 Asynchronous Method Invocation
30.1.1 Creating an Asynchronous Business Method
30.1.2 Calling Asynchronous Methods from Enterprise Bean Clients
30.1.2.1 Retrieving the Final Result from an Asynchronous Method Invocation
30.1.2.2 Cancelling an Asynchronous Method Invocation
30.1.2.3 Checking the Status of an Asynchronous Method Invocation
30.2 The async Example Application
30.2.1 Architecture of the async Example Application
30.2.2 Running the async Example
30.2.2.1 To Configure the Keystore and Truststore in GlassFish Server
30.2.2.2 To Run the async Example Application Using NetBeans IDE
30.2.2.3 To Run the async Example Application Using Maven
Part VI Contexts and Dependency Injection for Java EE
31 Introduction to Contexts and Dependency Injection for Java EE
31.1 Getting Started
31.2 Overview of CDI
31.3 About Beans
31.4 About CDI Managed Beans
31.5 Beans as Injectable Objects
31.6 Using Qualifiers
31.7 Injecting Beans
31.8 Using Scopes
31.9 Giving Beans EL Names
31.10 Adding Setter and Getter Methods
31.11 Using a Managed Bean in a Facelets Page
31.12 Injecting Objects by Using Producer Methods
31.13 Configuring a CDI Application
31.14 Using the @PostConstruct and @PreDestroy Annotations With CDI Managed Bean Classes
31.14.1 To Initialize a Managed Bean Using the @PostConstruct Annotation
31.14.2 To Prepare for the Destruction of a Managed Bean Using the @PreDestroy Annotation
31.15 Further Information about CDI
32 Running the Basic Contexts and Dependency Injection Examples
32.1 The simplegreeting CDI Example
32.1.1 The simplegreeting Source Files
32.1.2 The Facelets Template and Page
32.1.3 Running the simplegreeting Example
32.1.3.1 To Build, Package, and Run the simplegreeting Example Using NetBeans IDE
32.1.3.2 To Build, Package, and Deploy the simplegreeting Example Using Maven
32.1.3.3 To Run the simplegreeting Example
32.2 The guessnumber-cdi CDI Example
32.2.1 The guessnumber-cdi Source Files
32.2.1.1 The @MaxNumber and @Random Qualifier Interfaces
32.2.1.2 The Generator Managed Bean
32.2.1.3 The UserNumberBean Managed Bean
32.2.2 The Facelets Page
32.2.3 Running the guessnumber-cdi Example
32.2.3.1 To Build, Package, and Deploy the guessnumber-cdi Example Using NetBeans IDE
32.2.3.2 To Build, Package, and Deploy the guessnumber-cdi Example Using Maven
32.2.3.3 To Run the guessnumber Example
33 Contexts and Dependency Injection for Java EE: Advanced Topics
33.1 Packaging CDI Applications
33.2 Using Alternatives in CDI Applications
33.2.1 Using Specialization
33.3 Using Producer Methods, Producer Fields, and Disposer Methods in CDI Applications
33.3.1 Using Producer Methods
33.3.2 Using Producer Fields to Generate Resources
33.3.3 Using a Disposer Method
33.4 Using Predefined Beans in CDI Applications
33.5 Using Events in CDI Applications
33.5.1 Defining Events
33.5.2 Using Observer Methods to Handle Events
33.5.3 Firing Events
33.6 Using Interceptors in CDI Applications
33.7 Using Decorators in CDI Applications
33.8 Using Stereotypes in CDI Applications
34 Running the Advanced Contexts and Dependency Injection Examples
34.1 The encoder Example: Using Alternatives
34.1.1 The Coder Interface and Implementations
34.1.2 The encoder Facelets Page and Managed Bean
34.1.3 Running the encoder Example
34.1.3.1 To Build, Package, and Deploy the encoder Example Using NetBeans IDE
34.1.3.2 To Run the encoder Example Using NetBeans IDE
34.1.3.3 To Build, Package, and Deploy the encoder Example Using Maven
34.1.3.4 To Run the encoder Example Using Maven
34.2 The producermethods Example: Using a Producer Method To Choose a Bean Implementation
34.2.1 Components of the producermethods Example
34.2.2 Running the producermethods Example
34.2.2.1 To Build, Package, and Deploy the producermethods Example Using NetBeans IDE
34.2.2.2 To Build, Package, and Deploy the producermethods Example Using Maven
34.2.2.3 To Run the producermethods Example
34.3 The producerfields Example: Using Producer Fields to Generate Resources
34.3.1 The Producer Field for the producerfields Example
34.3.2 The producerfields Entity and Session Bean
34.3.3 The producerfields Facelets Pages and Managed Bean
34.3.4 Running the producerfields Example
34.3.4.1 To Build, Package, and Deploy the producerfields Example Using NetBeans IDE
34.3.4.2 To Build, Package, and Deploy the producerfields Example Using Maven
34.3.4.3 To Run the producerfields Example
34.4 The billpayment Example: Using Events and Interceptors
34.4.1 The PaymentEvent Event Class
34.4.2 The PaymentHandler Event Listener
34.4.3 The billpayment Facelets Pages and Managed Bean
34.4.4 The LoggedInterceptor Interceptor Class
34.4.5 Running the billpayment Example
34.4.5.1 To Build, Package, and Deploy the billpayment Example Using NetBeans IDE
34.4.5.2 To Build, Package, and Deploy the billpayment Example Using Maven
34.4.5.3 To Run the billpayment Example
34.5 The decorators Example: Decorating a Bean
34.5.1 Components of the decorators Example
34.5.2 Running the decorators Example
34.5.2.1 To Build, Package, and Deploy the decorators Example Using NetBeans IDE
34.5.2.2 To Build, Package, and Deploy the decorators Example Using Maven
34.5.2.3 To Run the decorators Example
Part VII Persistence
35 Introduction to the Java Persistence API
35.1 Entities
35.1.1 Requirements for Entity Classes
35.1.2 Persistent Fields and Properties in Entity Classes
35.1.2.1 Persistent Fields
35.1.2.2 Persistent Properties
35.1.2.3 Using Collections in Entity Fields and Properties
35.1.2.4 Validating Persistent Fields and Properties
35.1.3 Primary Keys in Entities
35.1.4 Multiplicity in Entity Relationships
35.1.5 Direction in Entity Relationships
35.1.5.1 Bidirectional Relationships
35.1.5.2 Unidirectional Relationships
35.1.5.3 Queries and Relationship Direction
35.1.5.4 Cascade Operations and Relationships
35.1.5.5 Orphan Removal in Relationships
35.1.6 Embeddable Classes in Entities
35.2 Entity Inheritance
35.2.1 Abstract Entities
35.2.2 Mapped Superclasses
35.2.3 Non-Entity Superclasses
35.2.4 Entity Inheritance Mapping Strategies
35.2.4.1 The Single Table per Class Hierarchy Strategy
35.2.4.2 The Table per Concrete Class Strategy
35.2.4.3 The Joined Subclass Strategy
35.3 Managing Entities
35.3.1 The EntityManager Interface
35.3.1.1 Container-Managed Entity Managers
35.3.1.2 Application-Managed Entity Managers
35.3.1.3 Finding Entities Using the EntityManager
35.3.1.4 Managing an Entity Instance's Lifecycle
35.3.1.5 Persisting Entity Instances
35.3.1.6 Removing Entity Instances
35.3.1.7 Synchronizing Entity Data to the Database
35.3.2 Persistence Units
35.4 Querying Entities
35.5 Further Information about Persistence
36 Running the Persistence Examples
36.1 The order Application
36.1.1 Entity Relationships in the order Application
36.1.1.1 Self-Referential Relationships
36.1.1.2 One-to-One Relationships
36.1.1.3 One-to-Many Relationship Mapped to Overlapping Primary and Foreign Keys
36.1.1.4 Unidirectional Relationships
36.1.2 Primary Keys in the order Application
36.1.2.1 Generated Primary Keys
36.1.2.2 Compound Primary Keys
36.1.3 Entity Mapped to More Than One Database Table
36.1.4 Cascade Operations in the order Application
36.1.5 BLOB and CLOB Database Types in the order Application
36.1.6 Temporal Types in the order Application
36.1.7 Managing the order Application's Entities
36.1.7.1 Creating Entities
36.1.7.2 Finding Entities
36.1.7.3 Setting Entity Relationships
36.1.7.4 Using Queries
36.1.7.5 Removing Entities
36.1.8 Running the order Example
36.1.8.1 To Run the order Example Using NetBeans IDE
36.1.8.2 To Run the order Example Using Maven
36.2 The roster Application
36.2.1 Relationships in the roster Application
36.2.1.1 The Many-To-Many Relationship in roster
36.2.2 Entity Inheritance in the roster Application
36.2.3 Criteria Queries in the roster Application
36.2.3.1 Metamodel Classes in the roster Application
36.2.3.2 Obtaining a CriteriaBuilder Instance in RequestBean
36.2.3.3 Creating Criteria Queries in RequestBean's Business Methods
36.2.4 Automatic Table Generation in the roster Application
36.2.5 Running the roster Example
36.2.5.1 To Run the roster Example Using NetBeans IDE
36.2.5.2 To Run the roster Example Using Maven
36.3 The address-book Application
36.3.1 Bean Validation Constraints in address-book
36.3.2 Specifying Error Messages for Constraints in address-book
36.3.3 Validating Contact Input from a JavaServer Faces Application
36.3.4 Running the address-book Example
36.3.4.1 To Run the address-book Example Using NetBeans IDE
36.3.4.2 To Run the address-book Example Using Maven
37 The Java Persistence Query Language
37.1 Query Language Terminology
37.2 Creating Queries Using the Java Persistence Query Language
37.2.1 Named Parameters in Queries
37.2.2 Positional Parameters in Queries
37.3 Simplified Query Language Syntax
37.3.1 Select Statements
37.3.2 Update and Delete Statements
37.4 Example Queries
37.4.1 Simple Queries
37.4.1.1 A Basic Select Query
37.4.1.2 Eliminating Duplicate Values
37.4.1.3 Using Named Parameters
37.4.2 Queries That Navigate to Related Entities
37.4.2.1 A Simple Query with Relationships
37.4.2.2 Navigating to Single-Valued Relationship Fields
37.4.2.3 Traversing Relationships with an Input Parameter
37.4.2.4 Traversing Multiple Relationships
37.4.2.5 Navigating According to Related Fields
37.4.3 Queries with Other Conditional Expressions
37.4.3.1 The LIKE Expression
37.4.3.2 The IS NULL Expression
37.4.3.3 The IS EMPTY Expression
37.4.3.4 The BETWEEN Expression
37.4.3.5 Comparison Operators
37.4.4 Bulk Updates and Deletes
37.4.4.1 Update Queries
37.4.4.2 Delete Queries
37.5 Full Query Language Syntax
37.5.1 BNF Symbols
37.5.2 BNF Grammar of the Java Persistence Query Language
37.5.3 FROM Clause
37.5.3.1 Identifiers
37.5.3.2 Identification Variables
37.5.3.3 Range Variable Declarations
37.5.3.4 Collection Member Declarations
37.5.3.5 Joins
37.5.4 Path Expressions
37.5.4.1 Examples of Path Expressions
37.5.4.2 Expression Types
37.5.4.3 Navigation
37.5.5 WHERE Clause
37.5.5.1 Literals
37.5.5.2 Input Parameters
37.5.5.3 Conditional Expressions
37.5.5.4 Operators and Their Precedence
37.5.5.5 BETWEEN Expressions
37.5.5.6 IN Expressions
37.5.5.7 LIKE Expressions
37.5.5.8 NULL Comparison Expressions
37.5.5.9 Empty Collection Comparison Expressions
37.5.5.10 Collection Member Expressions
37.5.5.11 Subqueries
37.5.5.12 Functional Expressions
37.5.5.13 Case Expressions
37.5.5.14 NULL Values
37.5.5.15 Equality Semantics
37.5.6 SELECT Clause
37.5.6.1 Return Types
37.5.6.2 The DISTINCT Keyword
37.5.6.3 Constructor Expressions
37.5.7 ORDER BY Clause
37.5.8 GROUP BY and HAVING Clauses
38 Using the Criteria API to Create Queries
38.1 Overview of the Criteria and Metamodel APIs
38.2 Using the Metamodel API to Model Entity Classes
38.2.1 Using Metamodel Classes
38.3 Using the Criteria API and Metamodel API to Create Basic Typesafe Queries
38.3.1 Creating a Criteria Query
38.3.2 Query Roots
38.3.3 Querying Relationships Using Joins
38.3.4 Path Navigation in Criteria Queries
38.3.5 Restricting Criteria Query Results
38.3.5.1 The Expression Interface Methods
38.3.5.2 Expression Methods in the CriteriaBuilder Interface
38.3.6 Managing Criteria Query Results
38.3.6.1 Ordering Results
38.3.6.2 Grouping Results
38.3.7 Executing Queries
38.3.7.1 Single-Valued Query Results
38.3.7.2 Collection-Valued Query Results
39 Creating and Using String-Based Criteria Queries
39.1 Overview of String-Based Criteria API Queries
39.1.1 Creating String-Based Queries
39.1.2 Executing String-Based Queries
40 Controlling Concurrent Access to Entity Data with Locking
40.1 Overview of Entity Locking and Concurrency
40.1.1 Using Optimistic Locking
40.2 Lock Modes
40.2.1 Setting the Lock Mode
40.2.2 Using Pessimistic Locking
40.2.2.1 Pessimistic Locking Timeouts
41 Using a Second-Level Cache with Java Persistence API Applications
41.1 Overview of the Second-Level Cache
41.1.1 Controlling Whether Entities May Be Cached
41.2 Specifying the Cache Mode Settings to Improve Performance
41.2.1 Setting the Cache Retrieval and Store Modes
41.2.1.1 Cache Retrieval Mode
41.2.1.2 Cache Store Mode
41.2.1.3 Setting the Cache Retrieval or Store Mode
41.2.2 Controlling the Second-Level Cache Programmatically
41.2.2.1 Checking Whether An Entity's Data is Cached
41.2.2.2 Removing an Entity from the Cache
41.2.2.3 Removing All Data from the Cache
Part VIII Messaging
42 Java Message Service Concepts
42.1 Overview of the JMS API
42.1.1 What Is Messaging?
42.1.2 What Is the JMS API?
42.1.3 When Can You Use the JMS API?
42.1.4 How Does the JMS API Work with the Java EE Platform?
42.2 Basic JMS API Concepts
42.2.1 JMS API Architecture
42.2.2 Messaging Styles
42.2.2.1 Point-to-Point Messaging Style
42.2.2.2 Publish/Subscribe Messaging Style
42.2.3 Message Consumption
42.3 The JMS API Programming Model
42.3.1 JMS Administered Objects
42.3.1.1 JMS Connection Factories
42.3.1.2 JMS Destinations
42.3.2 Connections
42.3.3 Sessions
42.3.4 JMSContext Objects
42.3.5 JMS Message Producers
42.3.6 JMS Message Consumers
42.3.6.1 JMS Message Listeners
42.3.6.2 JMS Message Selectors
42.3.6.3 Consuming Messages from Topics
42.3.6.4 Creating Durable Subscriptions
42.3.6.5 Creating Shared Subscriptions
42.3.7 JMS Messages
42.3.7.1 Message Headers
42.3.7.2 Message Properties
42.3.7.3 Message Bodies
42.3.8 JMS Queue Browsers
42.3.9 JMS Exception Handling
42.4 Using Advanced JMS Features
42.4.1 Controlling Message Acknowledgment
42.4.2 Specifying Options for Sending Messages
42.4.2.1 Specifying Message Persistence
42.4.2.2 Setting Message Priority Levels
42.4.2.3 Allowing Messages to Expire
42.4.2.4 Specifying a Delivery Delay
42.4.2.5 Using JMSProducer Method Chaining
42.4.3 Creating Temporary Destinations
42.4.4 Using JMS Local Transactions
42.4.5 Sending Messages Asynchronously
42.5 Using the JMS API in Java EE Applications
42.5.1 Creating Resources for Java EE Applications
42.5.2 Using Resource Injection in Enterprise Bean or Web Components
42.5.2.1 Injecting a ConnectionFactory, Topic, or Queue
42.5.2.2 Injecting a JMSContext Object
42.5.3 Using Java EE Components to Produce and to Synchronously Receive Messages
42.5.3.1 Managing JMS Resources in Web and EJB Components
42.5.3.2 Managing Transactions in Session Beans
42.5.4 Using Message-Driven Beans to Receive Messages Asynchronously
42.5.5 Managing JTA Transactions
42.6 Further Information about JMS
43 Java Message Service Examples
43.1 Overview of the JMS Examples
43.2 Writing Simple JMS Applications
43.2.1 Starting the JMS Provider
43.2.2 Creating JMS Administered Objects
43.2.2.1 To Create Resources for the Simple Examples
43.2.3 Building All the Simple Examples
43.2.3.1 To Build All the Simple Examples Using NetBeans IDE
43.2.3.2 To Build All the Simple Examples on the Command Line
43.2.4 Sending Messages
43.2.4.1 The Producer.java Client
43.2.4.2 To Run the Producer Client
43.2.5 Receiving Messages Synchronously
43.2.5.1 The SynchConsumer.java Client
43.2.5.2 To Run the SynchConsumer and Producer Clients
43.2.6 Using a Message Listener for Asynchronous Message Delivery
43.2.6.1 Writing the AsynchConsumer.java and TextListener.java Clients
43.2.6.2 To Run the AsynchConsumer and Producer Clients
43.2.7 Browsing Messages on a Queue
43.2.7.1 The MessageBrowser.java Client
43.2.7.2 To Run the QueueBrowser Client
43.2.8 Running Multiple Consumers on the Same Destination
43.2.9 Acknowledging Messages
43.2.9.1 To Run the ClientAckConsumer Client
43.3 Writing More Advanced JMS Applications
43.3.1 Using Durable Subscriptions
43.3.1.1 To Create Resources for the Durable Subscription Example
43.3.1.2 To Run the Durable Subscription Example
43.3.1.3 To Run the unsubscriber Example
43.3.2 Using Local Transactions
43.3.2.1 To Create Resources for the transactedexample Example
43.3.2.2 To Run the transactedexample Clients
43.4 Writing High Performance and Scalable JMS Applications
43.4.1 Using Shared Nondurable Subscriptions
43.4.1.1 Writing the Clients for the Shared Consumer Example
43.4.1.2 To Run the SharedConsumer and Producer Clients
43.4.2 Using Shared Durable Subscriptions
43.4.2.1 To Run the ShareDurableSubscriberExample and Producer Clients
43.5 Sending and Receiving Messages Using a Simple Web Application
43.5.1 The websimplemessage Facelets Pages
43.5.2 The websimplemessage Managed Beans
43.5.3 Running the websimplemessage Example
43.5.3.1 Creating Resources for the websimplemessage Example
43.5.3.2 To Package and Deploy websimplemessage Using NetBeans IDE
43.5.3.3 To Package and Deploy websimplemessage Using Maven
43.5.3.4 To Run the websimplemessage Example
43.6 Receiving Messages Asynchronously using a Message-Driven Bean
43.6.1 Overview of the simplemessage Example
43.6.2 The simplemessage Application Client
43.6.3 The simplemessage Message-Driven Bean Class
43.6.3.1 The onMessage Method
43.6.4 Running the simplemessage Example
43.6.4.1 Ereating Resources for the simplemessage Example
43.6.4.2 To Run the simplemessage Example Using NetBeans IDE
43.6.4.3 To Run the simplemessage Example Using Maven
43.7 Sending Messages from a Session Bean to an MDB
43.7.1 Writing the Application Components for the clientsessionmdb Example
43.7.1.1 Coding the Application Client: MyAppClient.java
43.7.1.2 Coding the Publisher Session Bean
43.7.1.3 Coding the Message-Driven Bean: MessageBean.java
43.7.2 Running the clientsessionmdb Example
43.7.2.1 To Run clientsessionmdb Using NetBeans IDE
43.7.2.2 To Run clientsessionmdb Using Maven
43.8 Using an Entity to Join Messages from Two MDBs
43.8.1 Overview of the clientmdbentity Example Application
43.8.2 Writing the Application Components for the clientmdbentity Example
43.8.2.1 Coding the Application Client: HumanResourceClient.java
43.8.2.2 Coding the Message-Driven Beans for the clientmdbentity Example
43.8.2.3 Coding the Entity Class for the clientmdbentity Example
43.8.3 Running the clientmdbentity Example
43.8.3.1 To Run clientmdbentity Using NetBeans IDE
43.8.3.2 To Run clientmdbentity Using Maven
43.8.3.3 Viewing the Application Output
43.9 Using NetBeans IDE to Create JMS Resources
43.9.1 To Create JMS Resources Using NetBeans IDE
43.9.2 To Delete JMS Resources Using NetBeans IDE
Part IX Security
44 Introduction to Security in the Java EE Platform
44.1 Overview of Java EE Security
44.1.1 A Simple Application Security Walkthrough
44.1.1.1 Step 1: Initial Request
44.1.1.2 Step 2: Initial Authentication
44.1.1.3 Step 3: URL Authorization
44.1.1.4 Step 4: Fulfilling the Original Request
44.1.1.5 Step 5: Invoking Enterprise Bean Business Methods
44.1.2 Features of a Security Mechanism
44.1.3 Characteristics of Application Security
44.2 Security Mechanisms
44.2.1 Java SE Security Mechanisms
44.2.2 Java EE Security Mechanisms
44.2.2.1 Application-Layer Security
44.2.2.2 Transport-Layer Security
44.2.2.3 Message-Layer Security
44.3 Securing Containers
44.3.1 Using Annotations to Specify Security Information
44.3.2 Using Deployment Descriptors for Declarative Security
44.3.3 Using Programmatic Security
44.4 Securing the GlassFish Server
44.5 Working with Realms, Users, Groups, and Roles
44.5.1 What Are Realms, Users, Groups, and Roles?
44.5.1.1 What Is a Realm?
44.5.1.2 What Is a User?
44.5.1.3 What Is a Group?
44.5.1.4 What Is a Role?
44.5.1.5 Some Other Terminology
44.5.2 Managing Users and Groups on the GlassFish Server
44.5.2.1 To Add Users to the GlassFish Server
44.5.3 Setting Up Security Roles
44.5.4 Mapping Roles to Users and Groups
44.6 Establishing a Secure Connection Using SSL
44.6.1 Verifying and Configuring SSL Support
44.7 Further Information about Security
45 Getting Started Securing Web Applications
45.1 Overview of Web Application Security
45.2 Securing Web Applications
45.2.1 Specifying Security Constraints
45.2.1.1 Specifying a Web Resource Collection
45.2.1.2 Specifying an Authorization Constraint
45.2.1.3 Specifying a Secure Connection
45.2.1.4 Specifying Security Constraints for Resources
45.2.2 Specifying Authentication Mechanisms
45.2.2.1 HTTP Basic Authentication
45.2.2.2 Form-Based Authentication
45.2.2.3 Digest Authentication
45.2.3 Specifying an Authentication Mechanism in the Deployment Descriptor
45.2.4 Declaring Security Roles
45.3 Using Programmatic Security with Web Applications
45.3.1 Authenticating Users Programmatically
45.3.2 Checking Caller Identity Programmatically
45.3.3 Example Code for Programmatic Security
45.3.4 Declaring and Linking Role References
45.4 Examples: Securing Web Applications
45.4.1 To Set Up Your System for Running the Security Examples
45.4.2 The hello2-basicauth Example: Basic Authentication with a Servlet
45.4.2.1 Specifying Security for Basic Authentication Using Annotations
45.4.2.2 To Build, Package, and Deploy the hello2-basicauth Example Using NetBeans IDE
45.4.2.3 To Build, Package, and Deploy the hello2-basicauth Example Using Maven
45.4.2.4 To Run the hello2-basicauth Example
45.4.3 The hello1-formauth Example: Form-Based Authentication with a JavaServer Faces Application
45.4.3.1 Creating the Login Form and the Error Page
45.4.3.2 Specifying Security for the Form-Based Authentication Example
45.4.3.3 To Build, Package, and Deploy the hello1-formauth Example Using NetBeans IDE
45.4.3.4 To Build, Package, and Deploy the hello1-formauth Example Using Maven and the asadmin Command
45.4.3.5 To Run the hello1-formauth Example
46 Getting Started Securing Enterprise Applications
46.1 Basic Security Tasks for Enterprise Applications
46.2 Securing Enterprise Beans
46.2.1 Securing an Enterprise Bean Using Declarative Security
46.2.1.1 Specifying Authorized Users by Declaring Security Roles
46.2.1.2 Specifying an Authentication Mechanism and Secure Connection
46.2.2 Securing an Enterprise Bean Programmatically
46.2.2.1 Accessing an Enterprise Bean Caller's Security Context
46.2.3 Propagating a Security Identity (Run-As)
46.2.3.1 Configuring a Component's Propagated Security Identity
46.2.3.2 Trust between Containers
46.2.4 Deploying Secure Enterprise Beans
46.3 Examples: Securing Enterprise Beans
46.3.1 The cart-secure Example: Securing an Enterprise Bean with Declarative Security
46.3.1.1 Annotating the Bean
46.3.1.2 To Run the cart-secure Example Using NetBeans IDE
46.3.1.3 To Run the cart-secure Example Using Maven
46.3.2 The converter-secure Example: Securing an Enterprise Bean with Programmatic Security
46.3.2.1 Modifying ConverterBean
46.3.2.2 Modifying ConverterServlet
46.3.2.3 To Run the converter-secure Example Using NetBeans IDE
46.3.2.4 To Run the converter-secure Example Using Maven
46.3.2.5 To Run the converter-secure Example
47 Java EE Security: Advanced Topics
47.1 Working with Digital Certificates
47.1.1 Creating a Server Certificate
47.1.1.1 To Use keytool to Create a Server Certificate
47.1.2 Adding Users to the Certificate Realm
47.1.3 Using a Different Server Certificate with the GlassFish Server
47.1.3.1 To Specify a Different Server Certificate
47.2 Authentication Mechanisms
47.2.1 Client Authentication
47.2.2 Mutual Authentication
47.2.2.1 Enabling Mutual Authentication over SSL
47.2.2.2 Creating a Client Certificate for Mutual Authentication
47.3 Using Form-Based Login in JavaServer Faces Web Applications
47.3.1 Using j_security_check in JavaServer Faces Forms
47.3.2 Using a Managed Bean for Authentication in JavaServer Faces Applications
47.4 Using the JDBC Realm for User Authentication
47.4.1 To Configure a JDBC Authentication Realm
47.5 Securing HTTP Resources
47.6 Securing Application Clients
47.6.1 Using Login Modules
47.6.2 Using Programmatic Login
47.7 Securing Enterprise Information Systems Applications
47.7.1 Container-Managed Sign-On
47.7.2 Component-Managed Sign-On
47.7.3 Configuring Resource Adapter Security
47.7.4 Mapping an Application Principal to EIS Principals
47.8 Configuring Security Using Deployment Descriptors
47.8.1 Specifying Security for Basic Authentication in the Deployment Descriptor
47.8.2 Specifying Non-Default Principal-to-Role Mapping in the Deployment Descriptor
47.9 Further Information about Security
Part X Java EE Supporting Technologies
48 Transactions
48.1 Transactions in Java EE Applications
48.2 What Is a Transaction?
48.3 Container-Managed Transactions
48.3.1 Transaction Attributes
48.3.1.1 Required Attribute
48.3.1.2 RequiresNew Attribute
48.3.1.3 Mandatory Attribute
48.3.1.4 NotSupported Attribute
48.3.1.5 Supports Attribute
48.3.1.6 Never Attribute
48.3.1.7 Summary of Transaction Attributes
48.3.1.8 Setting Transaction Attributes
48.3.2 Rolling Back a Container-Managed Transaction
48.3.3 Synchronizing a Session Bean's Instance Variables
48.3.4 Methods Not Allowed in Container-Managed Transactions
48.4 Bean-Managed Transactions
48.4.1 JTA Transactions
48.4.2 Returning without Committing
48.4.3 Methods Not Allowed in Bean-Managed Transactions
48.5 Transaction Timeouts
48.5.1 To Set a Transaction Timeout
48.6 Updating Multiple Databases
48.7 Transactions in Web Components
48.8 Further Information about Transactions
49 Resource Adapters and Contracts
49.1 What Is a Resource Adapter?
49.1.1 Management Contracts
49.1.1.1 Lifecycle Management
49.1.1.2 Work Management Contract
49.1.2 Generic Work Context Contract
49.1.3 Outbound and Inbound Contracts
49.2 Metadata Annotations
49.3 Common Client Interface
49.4 Using Resource Adapters With Contexts and Dependency Injection for Java EE (CDI)
49.5 Further Information about Resource Adapters
50 The Resource Adapter Examples
50.1 The outboundconnector Example
50.1.1 Using the Outbound Resource Adapter
50.1.2 Implementing the Outbound Resource Adapter
50.1.3 Running the outboundconnector Example
50.1.3.1 To Run the outboundconnector Example using NetBeans IDE
50.1.3.2 To Run the outboundconnector Example from the Command Line
50.2 The inboundconnector Example
50.2.1 Using the Inbound Resource Adapter
50.2.2 Implementing the Inbound Resource Adapter
50.2.3 Running the inboundconnector Example
50.2.3.1 To Run the inboundconnector Example using NetBeans IDE
50.2.3.2 To Run the inboundconnector Example from the Command Line
51 Bean Validation: Advanced Topics
51.1 Creating Custom Constraints
51.1.1 Using the Built-In Constraints to Make a New Constraint
51.2 Customizing Validator Messages
51.2.1 The ValidationMessages Resource Bundle
51.2.1.1 Localizing Validation Messages
51.3 Grouping Constraints
51.3.1 Customizing Group Validation Order
51.4 Using Method Constraints in Type Hierarchies
51.4.1 Rules for Using Method Constraints in Type Hierarchies
52 Using Java EE Interceptors
52.1 Overview of Interceptors
52.1.1 Interceptor Classes
52.1.2 Interceptor Lifecycle
52.1.3 Interceptors and CDI
52.2 Using Interceptors
52.2.1 Intercepting Method Invocations
52.2.1.1 Using Multiple Method Interceptors
52.2.1.2 Accessing Target Method Parameters From an Interceptor Class
52.2.2 Intercepting Lifecycle Callback Events
52.2.2.1 Using AroundConstruct Interceptor Methods
52.2.2.2 Using Multiple Lifecycle Callback Interceptors
52.2.3 Intercepting Timeout Events
52.2.3.1 Using Multiple Timeout Interceptors
52.2.4 Binding Interceptors to Components
52.2.4.1 Declaring the Interceptor Bindings on an Interceptor Class
52.2.4.2 Binding a Component to an Interceptor
52.2.5 Ordering Interceptors
52.3 The interceptor Example Application
52.3.1 Running the interceptor Example
52.3.1.1 To Run the interceptor Example Using NetBeans IDE
52.3.1.2 To Run the interceptor Example Using Maven
53 Batch Processing
53.1 Introduction to Batch Processing
53.1.1 Steps in Batch Jobs
53.1.2 Status and Decision Elements
53.1.3 Parallel Processing
53.1.4 Batch Framework Functionality
53.2 Batch Processing in Java EE
53.2.1 The Batch Processing Framework
53.2.2 Creating Batch Applications
53.2.3 Elements of a Batch Job
53.2.4 Properties and Parameters
53.2.5 Job Instances and Job Executions
53.2.6 Batch and Exit Status
53.3 Simple Use Case
53.3.1 Chunk Step
53.3.2 Task Step
53.4 Using the Job Specification Language
53.4.1 The job Element
53.4.2 The step Element
53.4.2.1 The chunk Element
53.4.2.2 The batchlet Element
53.4.2.3 The partition Element
53.4.3 The flow Element
53.4.4 The split Element
53.4.5 The decision Element
53.5 Creating Batch Artifacts
53.5.1 Batch Artifact Interfaces
53.5.2 Dependency Injection in Batch Artifacts
53.5.3 Using the Context Objects from the Batch Runtime
53.6 Submitting Jobs to the Batch Runtime
53.6.1 Starting a Job
53.6.2 Checking the Status of a Job
53.6.3 Invoking the Batch Runtime in Your Application
53.7 Packaging Batch Applications
53.8 The webserverlog Example Application
53.8.1 Architecture of the webserverlog Example Application
53.8.1.1 The Job Definition File
53.8.1.2 The LogLine and LogFilteredLine Items
53.8.1.3 The Chunk Step Batch Artifacts
53.8.1.4 The Listener Batch Artifacts
53.8.1.5 The Task Step Batch Artifact
53.8.1.6 The JavaServer Faces Pages
53.8.1.7 The Session Bean
53.8.2 Running the webserverlog Example Application
53.8.2.1 To Run the webserverlog Example Application Using NetBeans IDE
53.8.2.2 To Run the webserverlog Example Application Using Maven
53.9 The phonebilling Example Application
53.9.1 Architecture of the phonebilling Example Application
53.9.1.1 The Job Definition File
53.9.1.2 The CallRecord and PhoneBill Entities
53.9.1.3 The Call Records Chunk Step
53.9.1.4 The Phone Billing Chunk Step
53.9.1.5 The JavaServer Faces Pages
53.9.1.6 The Session Bean
53.9.2 Running the phonebilling Example Application
53.9.2.1 To Run the phonebilling Example Application Using NetBeans IDE
53.9.2.2 To Run the phonebilling Example Application Using Maven
53.10 Further Information about Batch Processing
54 Concurrency Utilities
54.1 Concurrency Basics
54.1.1 Threads and Processes
54.2 Main Components of the Concurrency Utilities
54.3 Concurrency and Transactions
54.4 Concurrency and Security
54.5 The jobs Concurrency Example
54.5.1 Running the jobs Example
54.5.1.1 To Configure GlassFish Server for the Basic Concurrency Example
54.5.1.2 To Build, Package, and Deploy the jobs Example Using NetBeans IDE
54.5.1.3 To Build, Package, and Deploy the jobs Example Using Maven
54.5.1.4 To Run the jobs Example and Submit Jobs With Low Priority
54.5.1.5 To Run the jobs Example and Submit Jobs With High Priority
Part XI Case Studies
55 Duke's Bookstore Case Study Example
55.1 Design and Architecture of Duke's Bookstore
55.2 The Duke's Bookstore Interface
55.2.1 The Book Java Persistence API Entity
55.2.2 Enterprise Beans Used in Duke's Bookstore
55.2.3 Facelets Pages and Managed Beans Used in Duke's Bookstore
55.2.4 Custom Components and Other Custom Objects Used in Duke's Bookstore
55.2.5 Properties Files Used in Duke's Bookstore
55.2.6 Deployment Descriptors Used in Duke's Bookstore
55.3 Running the Duke's Bookstore Case Study Application
55.3.1 To Build and Deploy Duke's Bookstore Using NetBeans IDE
55.3.2 To Build and Deploy Duke's Bookstore Using Maven
55.3.3 To Run Duke's Bookstore
Index
Symbols
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X