Java Platform, Enterprise Edition

The Java EE Tutorial

Release 7

E39031-01

September 2014

Java Platform, Enterprise Edition The Java EE Tutorial, Release 7

E39031-01

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Primary Author:  Eric Jendrock, Ricardo Cervera-Navarro, Ian Evans, Kim Haase, William Markito

Contributing Author:

Contributor:

This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.

The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.

If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable:

U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government.

This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.

Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.

This software or hardware and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services.

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 Java EE 7 APIs

- 1.7.1 Enterprise JavaBeans Technology

- 1.7.2 Java Servlet Technology

- 1.7.3 JavaServer Faces Technology

- 1.7.4 JavaServer Pages Technology

- 1.7.5 JavaServer Pages Standard Tag Library

- 1.7.6 Java Persistence API

- 1.7.7 Java Transaction API

- 1.7.8 Java API for RESTful Web Services

- 1.7.9 Managed Beans

- 1.7.10 Contexts and Dependency Injection for Java EE

- 1.7.11 Dependency Injection for Java

- 1.7.12 Bean Validation

- 1.7.13 Java Message Service API

- 1.7.14 Java EE Connector Architecture

- 1.7.15 JavaMail API

- 1.7.16 Java Authorization Contract for Containers

- 1.7.17 Java Authentication Service Provider Interface for Containers

- 1.7.18 Java API for WebSocket

- 1.7.19 Java API for JSON Processing

- 1.7.20 Concurrency Utilities for Java EE

- 1.7.21 Batch Applications for the Java Platform

- 1.8 Java EE 7 APIs in the Java Platform, Standard Edition 7

- 1.8.1 Java Database Connectivity API

- 1.8.2 Java Naming and Directory Interface API

- 1.8.3 JavaBeans Activation Framework

- 1.8.4 Java API for XML Processing

- 1.8.5 Java Architecture for XML Binding

- 1.8.6 Java API for XML Web Services

- 1.8.7 SOAP with Attachments API for Java

- 1.8.8 Java Authentication and Authorization Service

- 1.8.9 Common Annotations for the Java Platform

- 1.9 GlassFish Server Tools

2 Using the Tutorial Examples

- 2.1 Required Software

- 2.1.1 Java Platform, Standard Edition

- 2.1.2 Java EE 7 Software Development Kit

- 2.1.2.1 SDK Installation Tips

- 2.1.3 Java EE 7 Tutorial Component

- 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 Using NetBeans IDE

- 2.1.5 Apache Maven

- 2.2 Starting and Stopping GlassFish Server

- 2.2.1 To Start GlassFish Server Using NetBeans IDE

- 2.2.2 To Stop GlassFish Server Using NetBeans IDE

- 2.2.3 To Start GlassFish Server Using the Command Line

- 2.2.4 To Stop GlassFish Server Using the Command Line

- 2.3 Starting the Administration Console

- 2.3.1 To Start the Administration Console Using 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 Using 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 NetBeans IDE

- 2.8.2 To Update the Tutorial Using the Command Line

- 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 The 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 Maven

- 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 Partial Processing and Partial Rendering

- 7.8 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: The guessnumber-jsf Example 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

- 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

- 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

- 9.3.1.2 Referencing Object Properties or Collection Elements

- 9.3.1.3 Referencing Literals

- 9.3.1.4 Parameterized Method Calls

- 9.3.1.5 Where Value Expressions Can Be Used

- 9.3.2 Method Expressions

- 9.3.3 Lambda Expressions

- 9.4 Operations on Collection Objects

- 9.5 Operators

- 9.6 Reserved Words

- 9.7 Examples of EL Expressions

- 9.8 Further Information about the Expression Language

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

- 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 Validator Tags

- 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

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 Ajax Request Lifecycle

- 13.9 Grouping of Components

- 13.10 Loading JavaScript as a Resource

- 13.10.1 Using JavaScript API in a Facelets Application

- 13.10.2 Using the @ResourceDependency Annotation in a Bean Class

- 13.11 The ajaxguessnumber Example Application

- 13.11.1 The ajaxguessnumber Source Files

- 13.11.1.1 The ajaxgreeting.xhtml Facelets Page

- 13.11.1.2 The UserNumberBean Backing Bean

- 13.11.1.3 The DukesNumberBean CDI Managed Bean

- 13.11.2 Running the ajaxguessnumber Example

- 13.11.2.1 To Build, Package, and Deploy the ajaxguessnumber Example Using NetBeans IDE

- 13.11.2.2 To Build, Package, and Deploy the ajaxguessnumber Example Using Maven

- 13.11.2.3 To Run the ajaxguessnumber Example

- 13.12 Further Information about Ajax in JavaServer Faces Technology

14 Composite Components: Advanced Topics and an Example

- 14.1 Attributes of a Composite Component

- 14.2 Invoking a Managed Bean

- 14.3 Validating Composite Component Values

- 14.4 The compositecomponentexample 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 compositecomponentexample Example

- 14.4.4.1 To Build, Package, and Deploy the compositecomponentexample Example Using NetBeans IDE

- 14.4.4.2 To Build, Package, and Deploy the compositecomponentexample Example Using Maven

- 14.4.4.3 To Run the compositecomponentexample 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.2 Application Configuration Resource File

- 16.2.1 Configuring Eager Application-Scoped Managed Beans

- 16.2.2 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

- 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

- 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.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 Nonblocking I/O

- 17.13.1 Reading a Large HTTP POST Request Using Nonblocking 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 Deploy 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 the Java EE Platform

- 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 Specifying an Endpoint Configurator Class

- 18.11 The dukeetf2 Example Application

- 18.11.1 Architecture of the dukeetf2 Sample Application

- 18.11.1.1 The Endpoint

- 18.11.1.2 The Enterprise Bean

- 18.11.1.3 The HTML Page

- 18.11.2 Running the dukeetf2 Example Application

- 18.11.2.1 To Run the dukeetf2 Example Application Using NetBeans IDE

- 18.11.2.2 To Run the dukeetf2 Example Application Using Maven

- 18.12 The websocketbot Example Application

- 18.12.1 Architecture of the websocketbot Example Application

- 18.12.1.1 The CDI Bean

- 18.12.1.2 The WebSocket Endpoint

- 18.12.1.3 The Application Messages

- 18.12.1.4 The Encoder Classes

- 18.12.1.5 The Message Decoder

- 18.12.1.6 The HTML Page

- 18.12.2 Running the websocketbot Example Application

- 18.12.2.1 To Run the websocketbot Example Application Using NetBeans IDE

- 18.12.2.2 To Run the websocketbot Example Application Using Maven

- 18.12.2.3 To Test the websocketbot Example Application

- 18.13 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 the Java EE Platform

- 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 Bean Validation

21 Introduction to Bean Validation

- 21.1 Using Bean Validation Constraints

- 21.2 Validating Null and Empty Strings

- 21.3 Validating Constructors and Methods

- 21.3.1 Cross-Parameter Constraints

- 21.3.2 Identifying Parameter Constraint Violations

- 21.3.3 Adding Constraints to Method Return Values

- 21.4 Further Information about Bean Validation

22 Bean Validation: Advanced Topics

- 22.1 Creating Custom Constraints

- 22.1.1 Using the Built-In Constraints to Make a New Constraint

- 22.1.2 Removing Ambiguity in Constraint Targets

- 22.2 Customizing Validator Messages

- 22.2.1 The ValidationMessages Resource Bundle

- 22.2.1.1 Localizing Validation Messages

- 22.3 Grouping Constraints

- 22.3.1 Customizing Group Validation Order

- 22.4 Using Method Constraints in Type Hierarchies

- 22.4.1 Rules for Using Method Constraints in Type Hierarchies

Part V Contexts and Dependency Injection for Java EE

23 Introduction to Contexts and Dependency Injection for Java EE

- 23.1 Getting Started

- 23.2 Overview of CDI

- 23.3 About Beans

- 23.4 About CDI Managed Beans

- 23.5 Beans as Injectable Objects

- 23.6 Using Qualifiers

- 23.7 Injecting Beans

- 23.8 Using Scopes

- 23.9 Giving Beans EL Names

- 23.10 Adding Setter and Getter Methods

- 23.11 Using a Managed Bean in a Facelets Page

- 23.12 Injecting Objects by Using Producer Methods

- 23.13 Configuring a CDI Application

- 23.14 Using the @PostConstruct and @PreDestroy Annotations with CDI Managed Bean Classes

- 23.14.1 To Initialize a Managed Bean Using the @PostConstruct Annotation

- 23.14.2 To Prepare for the Destruction of a Managed Bean Using the @PreDestroy Annotation

- 23.15 Further Information about CDI

24 Running the Basic Contexts and Dependency Injection Examples

- 24.1 The simplegreeting CDI Example

- 24.1.1 The simplegreeting Source Files

- 24.1.2 The Facelets Template and Page

- 24.1.3 Running the simplegreeting Example

- 24.1.3.1 To Build, Package, and Run the simplegreeting Example Using NetBeans IDE

- 24.1.3.2 To Build, Package, and Deploy the simplegreeting Example Using Maven

- 24.1.3.3 To Run the simplegreeting Example

- 24.2 The guessnumber-cdi CDI Example

- 24.2.1 The guessnumber-cdi Source Files

- 24.2.1.1 The @MaxNumber and @Random Qualifier Interfaces

- 24.2.1.2 The Generator Managed Bean

- 24.2.1.3 The UserNumberBean Managed Bean

- 24.2.2 The Facelets Page

- 24.2.3 Running the guessnumber-cdi Example

- 24.2.3.1 To Build, Package, and Deploy the guessnumber-cdi Example Using NetBeans IDE

- 24.2.3.2 To Build, Package, and Deploy the guessnumber-cdi Example Using Maven

- 24.2.3.3 To Run the guessnumber Example

25 Contexts and Dependency Injection for Java EE: Advanced Topics

- 25.1 Packaging CDI Applications

- 25.2 Using Alternatives in CDI Applications

- 25.2.1 Using Specialization

- 25.3 Using Producer Methods, Producer Fields, and Disposer Methods in CDI Applications

- 25.3.1 Using Producer Methods

- 25.3.2 Using Producer Fields to Generate Resources

- 25.3.3 Using a Disposer Method

- 25.4 Using Predefined Beans in CDI Applications

- 25.5 Using Events in CDI Applications

- 25.5.1 Defining Events

- 25.5.2 Using Observer Methods to Handle Events

- 25.5.3 Firing Events

- 25.6 Using Interceptors in CDI Applications

- 25.7 Using Decorators in CDI Applications

- 25.8 Using Stereotypes in CDI Applications

26 Running the Advanced Contexts and Dependency Injection Examples

- 26.1 The encoder Example: Using Alternatives

- 26.1.1 The Coder Interface and Implementations

- 26.1.2 The encoder Facelets Page and Managed Bean

- 26.1.3 Running the encoder Example

- 26.1.3.1 To Build, Package, and Deploy the encoder Example Using NetBeans IDE

- 26.1.3.2 To Run the encoder Example Using NetBeans IDE

- 26.1.3.3 To Build, Package, and Deploy the encoder Example Using Maven

- 26.1.3.4 To Run the encoder Example Using Maven

- 26.2 The producermethods Example: Using a Producer Method to Choose a Bean Implementation

- 26.2.1 Components of the producermethods Example

- 26.2.2 Running the producermethods Example

- 26.2.2.1 To Build, Package, and Deploy the producermethods Example Using NetBeans IDE

- 26.2.2.2 To Build, Package, and Deploy the producermethods Example Using Maven

- 26.2.2.3 To Run the producermethods Example

- 26.3 The producerfields Example: Using Producer Fields to Generate Resources

- 26.3.1 The Producer Field for the producerfields Example

- 26.3.2 The producerfields Entity and Session Bean

- 26.3.3 The producerfields Facelets Pages and Managed Bean

- 26.3.4 Running the producerfields Example

- 26.3.4.1 To Build, Package, and Deploy the producerfields Example Using NetBeans IDE

- 26.3.4.2 To Build, Package, and Deploy the producerfields Example Using Maven

- 26.3.4.3 To Run the producerfields Example

- 26.4 The billpayment Example: Using Events and Interceptors

- 26.4.1 The PaymentEvent Event Class

- 26.4.2 The PaymentHandler Event Listener

- 26.4.3 The billpayment Facelets Pages and Managed Bean

- 26.4.4 The LoggedInterceptor Interceptor Class

- 26.4.5 Running the billpayment Example

- 26.4.5.1 To Build, Package, and Deploy the billpayment Example Using NetBeans IDE

- 26.4.5.2 To Build, Package, and Deploy the billpayment Example Using Maven

- 26.4.5.3 To Run the billpayment Example

- 26.5 The decorators Example: Decorating a Bean

- 26.5.1 Components of the decorators Example

- 26.5.2 Running the decorators Example

- 26.5.2.1 To Build, Package, and Deploy the decorators Example Using NetBeans IDE

- 26.5.2.2 To Build, Package, and Deploy the decorators Example Using Maven

- 26.5.2.3 To Run the decorators Example

Part VI Web Services

27 Introduction to Web Services

- 27.1 What Are Web Services?

- 27.2 Types of Web Services

- 27.2.1 "Big" Web Services

- 27.2.2 RESTful Web Services

- 27.3 Deciding Which Type of Web Service to Use

28 Building Web Services with JAX-WS

- 28.1 Creating a Simple Web Service and Clients with JAX-WS

- 28.1.1 Requirements of a JAX-WS Endpoint

- 28.1.2 Coding the Service Endpoint Implementation Class

- 28.1.3 Building, Packaging, and Deploying the Service

- 28.1.3.1 To Build, Package, and Deploy the Service Using NetBeans IDE

- 28.1.3.2 To Build, Package, and Deploy the Service Using Maven

- 28.1.4 Testing the Methods of a Web Service Endpoint

- 28.1.4.1 To Test the Service without a Client

- 28.1.5 A Simple JAX-WS Application Client

- 28.1.5.1 Coding the Application Client

- 28.1.5.2 Running the Application Client

- 28.1.6 A Simple JAX-WS Web Client

- 28.1.6.1 Coding the Servlet

- 28.1.6.2 Running the Web Client

- 28.2 Types Supported by JAX-WS

- 28.2.1 Schema-to-Java Mapping

- 28.2.2 Java-to-Schema Mapping

- 28.3 Web Services Interoperability and JAX-WS

- 28.4 Further Information about JAX-WS

29 Building RESTful Web Services with JAX-RS

- 29.1 What Are RESTful Web Services?

- 29.2 Creating a RESTful Root Resource Class

- 29.2.1 Developing RESTful Web Services with JAX-RS

- 29.2.2 Overview of a JAX-RS Application

- 29.2.3 The @Path Annotation and URI Path Templates

- 29.2.4 Responding to HTTP Methods and Requests

- 29.2.4.1 The Request Method Designator Annotations

- 29.2.4.2 Using Entity Providers to Map HTTP Response and Request Entity Bodies

- 29.2.5 Using @Consumes and @Produces to Customize Requests and Responses

- 29.2.5.1 The @Produces Annotation

- 29.2.5.2 The @Consumes Annotation

- 29.2.6 Extracting Request Parameters

- 29.2.7 Configuring JAX-RS Applications

- 29.2.7.1 Configuring a JAX-RS Application Using a Subclass of Application

- 29.2.7.2 Configuring the Base URI in web.xml

- 29.3 Example Applications for JAX-RS

- 29.3.1 Creating a Simple RESTful Web Service

- 29.3.1.1 To Create a RESTful Web Service Using NetBeans IDE

- 29.3.2 The rsvp Example Application

- 29.3.2.1 Components of the rsvp Example Application

- 29.3.2.2 Running the rsvp Example Application

- 29.3.3 Real-World Examples

- 29.4 Further Information about JAX-RS

30 Accessing REST Resources with the JAX-RS Client API

- 30.1 Overview of the Client API

- 30.1.1 Creating a Basic Client Request Using the Client API

- 30.1.1.1 Obtaining the Client Instance

- 30.1.1.2 Setting the Client Target

- 30.1.1.3 Setting Path Parameters in Targets

- 30.1.1.4 Invoking the Request

- 30.2 Using the Client API in the JAX-RS Example Applications

- 30.2.1 The Client API in the rsvp Example Application

- 30.2.2 The Client API in the customer Example Application

- 30.3 Advanced Features of the Client API

- 30.3.1 Configuring the Client Request

- 30.3.1.1 Setting Message Headers in the Client Request

- 30.3.1.2 Setting Cookies in the Client Request

- 30.3.1.3 Adding Filters to the Client

- 30.3.2 Asynchronous Invocations in the Client API

- 30.3.2.1 Using Custom Callbacks in Asynchronous Invocations

31 JAX-RS: Advanced Topics and an Example

- 31.1 Annotations for Field and Bean Properties of Resource Classes

- 31.1.1 Extracting Path Parameters

- 31.1.2 Extracting Query Parameters

- 31.1.3 Extracting Form Data

- 31.1.4 Extracting the Java Type of a Request or Response

- 31.2 Validating Resource Data with Bean Validation

- 31.2.1 Using Constraint Annotations on Resource Methods

- 31.2.2 Validating Entity Data

- 31.2.3 Validation Exception Handling and Response Codes

- 31.3 Subresources and Runtime Resource Resolution

- 31.3.1 Subresource Methods

- 31.3.2 Subresource Locators

- 31.4 Integrating JAX-RS with EJB Technology and CDI

- 31.5 Conditional HTTP Requests

- 31.6 Runtime Content Negotiation

- 31.7 Using JAX-RS with JAXB

- 31.7.1 Using Java Objects to Model Your Data

- 31.7.2 Starting from an Existing XML Schema Definition

- 31.7.3 Using JSON with JAX-RS and JAXB

- 31.8 The customer Example Application

- 31.8.1 Overview of the customer Example Application

- 31.8.2 The Customer and Address Entity Classes

- 31.8.3 The CustomerService Class

- 31.8.4 Using the JAX-RS Client in the CustomerBean Classes

- 31.8.5 Running the customer Example

- 31.8.5.1 To Build, Package, and Deploy the customer Example Using NetBeans IDE

- 31.8.5.2 To Build, Package, and Deploy the customer Example Using Maven

Part VII Enterprise Beans

32 Enterprise Beans

- 32.1 What Is an Enterprise Bean?

- 32.1.1 Benefits of Enterprise Beans

- 32.1.2 When to Use Enterprise Beans

- 32.1.3 Types of Enterprise Beans

- 32.2 What Is a Session Bean?

- 32.2.1 Types of Session Beans

- 32.2.1.1 Stateful Session Beans

- 32.2.1.2 Stateless Session Beans

- 32.2.1.3 Singleton Session Beans

- 32.2.2 When to Use Session Beans

- 32.3 What Is a Message-Driven Bean?

- 32.3.1 What Makes Message-Driven Beans Different from Session Beans?

- 32.3.2 When to Use Message-Driven Beans

- 32.4 Accessing Enterprise Beans

- 32.4.1 Using Enterprise Beans in Clients

- 32.4.1.1 Portable JNDI Syntax

- 32.4.2 Deciding on Remote or Local Access

- 32.4.3 Local Clients

- 32.4.3.1 Accessing Local Enterprise Beans Using the No-Interface View

- 32.4.3.2 Accessing Local Enterprise Beans That Implement Business Interfaces

- 32.4.4 Remote Clients

- 32.4.5 Web Service Clients

- 32.4.6 Method Parameters and Access

- 32.4.6.1 Isolation

- 32.4.6.2 Granularity of Accessed Data

- 32.5 The Contents of an Enterprise Bean

- 32.6 Naming Conventions for Enterprise Beans

- 32.7 The Lifecycles of Enterprise Beans

- 32.7.1 The Lifecycle of a Stateful Session Bean

- 32.7.2 The Lifecycle of a Stateless Session Bean

- 32.7.3 The Lifecycle of a Singleton Session Bean

- 32.7.4 The Lifecycle of a Message-Driven Bean

- 32.8 Further Information about Enterprise Beans

33 Getting Started with Enterprise Beans

- 33.1 Creating the Enterprise Bean

- 33.1.1 Coding the Enterprise Bean Class

- 33.1.2 Creating the converter Web Client

- 33.1.3 Running the converter Example

- 33.1.3.1 To Run the converter Example Using NetBeans IDE

- 33.1.3.2 To Run the converter Example Using Maven

- 33.2 Modifying the Java EE Application

- 33.2.1 To Modify a Class File

34 Running the Enterprise Bean Examples

- 34.1 The cart Example

- 34.1.1 The Business Interface

- 34.1.2 Session Bean Class

- 34.1.2.1 Lifecycle Callback Methods

- 34.1.2.2 Business Methods

- 34.1.3 The @Remove Method

- 34.1.4 Helper Classes

- 34.1.5 Running the cart Example

- 34.1.5.1 To Run the cart Example Using NetBeans IDE

- 34.1.5.2 To Run the cart Example Using Maven

- 34.2 A Singleton Session Bean Example: counter

- 34.2.1 Creating a Singleton Session Bean

- 34.2.1.1 Initializing Singleton Session Beans

- 34.2.1.2 Managing Concurrent Access in a Singleton Session Bean

- 34.2.1.3 Handling Errors in a Singleton Session Bean

- 34.2.2 The Architecture of the counter Example

- 34.2.3 Running the counter Example

- 34.2.3.1 To Run the counter Example Using NetBeans IDE

- 34.2.3.2 To Run the counter Example Using Maven

- 34.3 A Web Service Example: helloservice

- 34.3.1 The Web Service Endpoint Implementation Class

- 34.3.2 Stateless Session Bean Implementation Class

- 34.3.3 Running the helloservice Example

- 34.3.3.1 To Build, Package, and Deploy the helloservice Example Using NetBeans IDE

- 34.3.3.2 To Build, Package, and Deploy the helloservice Example Using Maven

- 34.3.3.3 To Test the Service without a Client

- 34.4 Using the Timer Service

- 34.4.1 Creating Calendar-Based Timer Expressions

- 34.4.1.1 Specifying Multiple Values in Calendar Expressions

- 34.4.2 Programmatic Timers

- 34.4.2.1 The @Timeout Method

- 34.4.2.2 Creating Programmatic Timers

- 34.4.3 Automatic Timers

- 34.4.4 Canceling and Saving Timers

- 34.4.5 Getting Timer Information

- 34.4.6 Transactions and Timers

- 34.4.7 The timersession Example

- 34.4.8 Running the timersession Example

- 34.4.8.1 To Run the timersession Example Using NetBeans IDE

- 34.4.8.2 To Build, Package, and Deploy the timersession Example Using Maven

- 34.4.8.3 To Run the Web Client

- 34.5 Handling Exceptions

35 Using the Embedded Enterprise Bean Container

- 35.1 Overview of the Embedded Enterprise Bean Container

- 35.2 Developing Embeddable Enterprise Bean Applications

- 35.2.1 Running Embedded Applications

- 35.2.2 Creating the Enterprise Bean Container

- 35.2.2.1 Explicitly Specifying Enterprise Bean Modules to Be Initialized

- 35.2.3 Looking Up Session Bean References

- 35.2.4 Shutting Down the Enterprise Bean Container

- 35.3 The standalone Example Application

- 35.3.1 To Run the standalone Example Application Using NetBeans IDE

- 35.3.2 To Run the standalone Example Application Using Maven

36 Using Asynchronous Method Invocation in Session Beans

- 36.1 Asynchronous Method Invocation

- 36.1.1 Creating an Asynchronous Business Method

- 36.1.2 Calling Asynchronous Methods from Enterprise Bean Clients

- 36.1.2.1 Retrieving the Final Result from an Asynchronous Method Invocation

- 36.1.2.2 Cancelling an Asynchronous Method Invocation

- 36.1.2.3 Checking the Status of an Asynchronous Method Invocation

- 36.2 The async Example Application

- 36.2.1 Architecture of the async-war Module

- 36.2.2 Running the async Example

- 36.2.2.1 To Run the async Example Application Using NetBeans IDE

- 36.2.2.2 To Run the async Example Application Using Maven

Part VIII Persistence

37 Introduction to the Java Persistence API

- 37.1 Entities

- 37.1.1 Requirements for Entity Classes

- 37.1.2 Persistent Fields and Properties in Entity Classes

- 37.1.2.1 Persistent Fields

- 37.1.2.2 Persistent Properties

- 37.1.2.3 Using Collections in Entity Fields and Properties

- 37.1.2.4 Validating Persistent Fields and Properties

- 37.1.3 Primary Keys in Entities

- 37.1.4 Multiplicity in Entity Relationships

- 37.1.5 Direction in Entity Relationships

- 37.1.5.1 Bidirectional Relationships

- 37.1.5.2 Unidirectional Relationships

- 37.1.5.3 Queries and Relationship Direction

- 37.1.5.4 Cascade Operations and Relationships

- 37.1.5.5 Orphan Removal in Relationships

- 37.1.6 Embeddable Classes in Entities

- 37.2 Entity Inheritance

- 37.2.1 Abstract Entities

- 37.2.2 Mapped Superclasses

- 37.2.3 Non-Entity Superclasses

- 37.2.4 Entity Inheritance Mapping Strategies

- 37.2.4.1 The Single Table per Class Hierarchy Strategy

- 37.2.4.2 The Table per Concrete Class Strategy

- 37.2.4.3 The Joined Subclass Strategy

- 37.3 Managing Entities

- 37.3.1 The EntityManager Interface

- 37.3.1.1 Container-Managed Entity Managers

- 37.3.1.2 Application-Managed Entity Managers

- 37.3.1.3 Finding Entities Using the EntityManager

- 37.3.1.4 Managing an Entity Instance's Lifecycle

- 37.3.1.5 Persisting Entity Instances

- 37.3.1.6 Removing Entity Instances

- 37.3.1.7 Synchronizing Entity Data to the Database

- 37.3.2 Persistence Units

- 37.4 Querying Entities

- 37.5 Database Schema Creation

- 37.5.1 Configuring an Application to Create or Drop Database Tables

- 37.5.2 Loading Data Using SQL Scripts

- 37.6 Further Information about Persistence

38 Running the Persistence Examples

- 38.1 The order Application

- 38.1.1 Entity Relationships in the order Application

- 38.1.1.1 Self-Referential Relationships

- 38.1.1.2 One-to-One Relationships

- 38.1.1.3 One-to-Many Relationship Mapped to Overlapping Primary and Foreign Keys

- 38.1.1.4 Unidirectional Relationships

- 38.1.2 Primary Keys in the order Application

- 38.1.2.1 Generated Primary Keys

- 38.1.2.2 Compound Primary Keys

- 38.1.3 Entity Mapped to More Than One Database Table

- 38.1.4 Cascade Operations in the order Application

- 38.1.5 BLOB and CLOB Database Types in the order Application

- 38.1.6 Temporal Types in the order Application

- 38.1.7 Managing the order Application's Entities

- 38.1.7.1 Creating Entities

- 38.1.7.2 Finding Entities

- 38.1.7.3 Setting Entity Relationships

- 38.1.7.4 Using Queries

- 38.1.7.5 Removing Entities

- 38.1.8 Running the order Example

- 38.1.8.1 To Run the order Example Using NetBeans IDE

- 38.1.8.2 To Run the order Example Using Maven

- 38.2 The roster Application

- 38.2.1 Relationships in the roster Application

- 38.2.1.1 The Many-To-Many Relationship in roster

- 38.2.2 Entity Inheritance in the roster Application

- 38.2.3 Criteria Queries in the roster Application

- 38.2.3.1 Metamodel Classes in the roster Application

- 38.2.3.2 Obtaining a CriteriaBuilder Instance in RequestBean

- 38.2.3.3 Creating Criteria Queries in RequestBean's Business Methods

- 38.2.4 Automatic Table Generation in the roster Application

- 38.2.5 Running the roster Example

- 38.2.5.1 To Run the roster Example Using NetBeans IDE

- 38.2.5.2 To Run the roster Example Using Maven

- 38.3 The address-book Application

- 38.3.1 Bean Validation Constraints in address-book

- 38.3.2 Specifying Error Messages for Constraints in address-book

- 38.3.3 Validating Contact Input from a JavaServer Faces Application

- 38.3.4 Running the address-book Example

- 38.3.4.1 To Run the address-book Example Using NetBeans IDE

- 38.3.4.2 To Run the address-book Example Using Maven

39 The Java Persistence Query Language

- 39.1 Query Language Terminology

- 39.2 Creating Queries Using the Java Persistence Query Language

- 39.2.1 Named Parameters in Queries

- 39.2.2 Positional Parameters in Queries

- 39.3 Simplified Query Language Syntax

- 39.3.1 Select Statements

- 39.3.2 Update and Delete Statements

- 39.4 Example Queries

- 39.4.1 Simple Queries

- 39.4.1.1 A Basic Select Query

- 39.4.1.2 Eliminating Duplicate Values

- 39.4.1.3 Using Named Parameters

- 39.4.2 Queries That Navigate to Related Entities

- 39.4.2.1 A Simple Query with Relationships

- 39.4.2.2 Navigating to Single-Valued Relationship Fields

- 39.4.2.3 Traversing Relationships with an Input Parameter

- 39.4.2.4 Traversing Multiple Relationships

- 39.4.2.5 Navigating According to Related Fields

- 39.4.3 Queries with Other Conditional Expressions

- 39.4.3.1 The LIKE Expression

- 39.4.3.2 The IS NULL Expression

- 39.4.3.3 The IS EMPTY Expression

- 39.4.3.4 The BETWEEN Expression

- 39.4.3.5 Comparison Operators

- 39.4.4 Bulk Updates and Deletes

- 39.4.4.1 Update Queries

- 39.4.4.2 Delete Queries

- 39.5 Full Query Language Syntax

- 39.5.1 BNF Symbols

- 39.5.2 BNF Grammar of the Java Persistence Query Language

- 39.5.3 FROM Clause

- 39.5.3.1 Identifiers

- 39.5.3.2 Identification Variables

- 39.5.3.3 Range Variable Declarations

- 39.5.3.4 Collection Member Declarations

- 39.5.3.5 Joins

- 39.5.4 Path Expressions

- 39.5.4.1 Examples of Path Expressions

- 39.5.4.2 Expression Types

- 39.5.4.3 Navigation

- 39.5.5 WHERE Clause

- 39.5.5.1 Literals

- 39.5.5.2 Input Parameters

- 39.5.5.3 Conditional Expressions

- 39.5.5.4 Operators and Their Precedence

- 39.5.5.5 BETWEEN Expressions

- 39.5.5.6 IN Expressions

- 39.5.5.7 LIKE Expressions

- 39.5.5.8 NULL Comparison Expressions

- 39.5.5.9 Empty Collection Comparison Expressions

- 39.5.5.10 Collection Member Expressions

- 39.5.5.11 Subqueries

- 39.5.5.12 Functional Expressions

- 39.5.5.13 Case Expressions

- 39.5.5.14 NULL Values

- 39.5.5.15 Equality Semantics

- 39.5.6 SELECT Clause

- 39.5.6.1 Return Types

- 39.5.6.2 The DISTINCT Keyword

- 39.5.6.3 Constructor Expressions

- 39.5.7 ORDER BY Clause

- 39.5.8 GROUP BY and HAVING Clauses

40 Using the Criteria API to Create Queries

- 40.1 Overview of the Criteria and Metamodel APIs

- 40.2 Using the Metamodel API to Model Entity Classes

- 40.2.1 Using Metamodel Classes

- 40.3 Using the Criteria API and Metamodel API to Create Basic Typesafe Queries

- 40.3.1 Creating a Criteria Query

- 40.3.2 Query Roots

- 40.3.3 Querying Relationships Using Joins

- 40.3.4 Path Navigation in Criteria Queries

- 40.3.5 Restricting Criteria Query Results

- 40.3.5.1 The Expression Interface Methods

- 40.3.5.2 Expression Methods in the CriteriaBuilder Interface

- 40.3.6 Managing Criteria Query Results

- 40.3.6.1 Ordering Results

- 40.3.6.2 Grouping Results

- 40.3.7 Executing Queries

- 40.3.7.1 Single-Valued Query Results

- 40.3.7.2 Collection-Valued Query Results

41 Creating and Using String-Based Criteria Queries

- 41.1 Overview of String-Based Criteria API Queries

- 41.2 Creating String-Based Queries

- 41.3 Executing String-Based Queries

42 Controlling Concurrent Access to Entity Data with Locking

- 42.1 Overview of Entity Locking and Concurrency

- 42.1.1 Using Optimistic Locking

- 42.2 Lock Modes

- 42.2.1 Setting the Lock Mode

- 42.2.2 Using Pessimistic Locking

- 42.2.2.1 Pessimistic Locking Timeouts

43 Creating Fetch Plans with Entity Graphs

- 43.1 Entity Graph Basics

- 43.1.1 The Default Entity Graph

- 43.1.2 Using Entity Graphs in Persistence Operations

- 43.1.2.1 Fetch Graphs

- 43.1.2.2 Load Graphs

- 43.2 Using Named Entity Graphs

- 43.2.1 Applying Named Entity Graph Annotations to Entity Classes

- 43.2.2 Obtaining EntityGraph Instances from Named Entity Graphs

- 43.3 Using Entity Graphs in Query Operations

44 Using a Second-Level Cache with Java Persistence API Applications

- 44.1 Overview of the Second-Level Cache

- 44.1.1 Controlling whether Entities May Be Cached

- 44.2 Specifying the Cache Mode Settings to Improve Performance

- 44.2.1 Setting the Cache Retrieval and Store Modes

- 44.2.1.1 Cache Retrieval Mode

- 44.2.1.2 Cache Store Mode

- 44.2.1.3 Setting the Cache Retrieval or Store Mode

- 44.2.2 Controlling the Second-Level Cache Programmatically

- 44.2.2.1 Checking whether an Entity's Data Is Cached

- 44.2.2.2 Removing an Entity from the Cache

- 44.2.2.3 Removing All Data from the Cache

Part IX Messaging

45 Java Message Service Concepts

- 45.1 Overview of the JMS API

- 45.1.1 What Is Messaging?

- 45.1.2 What Is the JMS API?

- 45.1.3 When Can You Use the JMS API?

- 45.1.4 How Does the JMS API Work with the Java EE Platform?

- 45.2 Basic JMS API Concepts

- 45.2.1 JMS API Architecture

- 45.2.2 Messaging Styles

- 45.2.2.1 Point-to-Point Messaging Style

- 45.2.2.2 Publish/Subscribe Messaging Style

- 45.2.3 Message Consumption

- 45.3 The JMS API Programming Model

- 45.3.1 JMS Administered Objects

- 45.3.1.1 JMS Connection Factories

- 45.3.1.2 JMS Destinations

- 45.3.2 Connections

- 45.3.3 Sessions

- 45.3.4 JMSContext Objects

- 45.3.5 JMS Message Producers

- 45.3.6 JMS Message Consumers

- 45.3.6.1 JMS Message Listeners

- 45.3.6.2 JMS Message Selectors

- 45.3.6.3 Consuming Messages from Topics

- 45.3.6.4 Creating Durable Subscriptions

- 45.3.6.5 Creating Shared Subscriptions

- 45.3.7 JMS Messages

- 45.3.7.1 Message Headers

- 45.3.7.2 Message Properties

- 45.3.7.3 Message Bodies

- 45.3.8 JMS Queue Browsers

- 45.3.9 JMS Exception Handling

- 45.4 Using Advanced JMS Features

- 45.4.1 Controlling Message Acknowledgment

- 45.4.2 Specifying Options for Sending Messages

- 45.4.2.1 Specifying Message Persistence

- 45.4.2.2 Setting Message Priority Levels

- 45.4.2.3 Allowing Messages to Expire

- 45.4.2.4 Specifying a Delivery Delay

- 45.4.2.5 Using JMSProducer Method Chaining

- 45.4.3 Creating Temporary Destinations

- 45.4.4 Using JMS Local Transactions

- 45.4.5 Sending Messages Asynchronously

- 45.5 Using the JMS API in Java EE Applications

- 45.5.1 Creating Resources for Java EE Applications

- 45.5.2 Using Resource Injection in Enterprise Bean or Web Components

- 45.5.2.1 Injecting a ConnectionFactory, Queue, or Topic

- 45.5.2.2 Injecting a JMSContext Object

- 45.5.3 Using Java EE Components to Produce and to Synchronously Receive Messages

- 45.5.3.1 Managing JMS Resources in Web and EJB Components

- 45.5.3.2 Managing Transactions in Session Beans

- 45.5.4 Using Message-Driven Beans to Receive Messages Asynchronously

- 45.5.5 Managing JTA Transactions

- 45.6 Further Information about JMS

46 Java Message Service Examples

- 46.1 Overview of the JMS Examples

- 46.2 Writing Simple JMS Applications

- 46.2.1 Starting the JMS Provider

- 46.2.2 Creating JMS Administered Objects

- 46.2.2.1 To Create Resources for the Simple Examples

- 46.2.3 Building All the Simple Examples

- 46.2.3.1 To Build All the Simple Examples Using NetBeans IDE

- 46.2.3.2 To Build All the Simple Examples Using Maven

- 46.2.4 Sending Messages

- 46.2.4.1 The Producer.java Client

- 46.2.4.2 To Run the Producer Client

- 46.2.5 Receiving Messages Synchronously

- 46.2.5.1 The SynchConsumer.java Client

- 46.2.5.2 To Run the SynchConsumer and Producer Clients

- 46.2.6 Using a Message Listener for Asynchronous Message Delivery

- 46.2.6.1 Writing the AsynchConsumer.java and TextListener.java Clients

- 46.2.6.2 To Run the AsynchConsumer and Producer Clients

- 46.2.7 Browsing Messages on a Queue

- 46.2.7.1 The MessageBrowser.java Client

- 46.2.7.2 To Run the QueueBrowser Client

- 46.2.8 Running Multiple Consumers on the Same Destination

- 46.2.9 Acknowledging Messages

- 46.2.9.1 To Run the ClientAckConsumer Client

- 46.3 Writing More Advanced JMS Applications

- 46.3.1 Using Durable Subscriptions

- 46.3.1.1 To Create Resources for the Durable Subscription Example

- 46.3.1.2 To Run the Durable Subscription Example

- 46.3.1.3 To Run the unsubscriber Example

- 46.3.2 Using Local Transactions

- 46.3.2.1 To Create Resources for the transactedexample Example

- 46.3.2.2 To Run the transactedexample Clients

- 46.4 Writing High Performance and Scalable JMS Applications

- 46.4.1 Using Shared Nondurable Subscriptions

- 46.4.1.1 Writing the Clients for the Shared Consumer Example

- 46.4.1.2 To Run the SharedConsumer and Producer Clients

- 46.4.2 Using Shared Durable Subscriptions

- 46.4.2.1 To Run the SharedDurableConsumer and Producer Clients

- 46.5 Sending and Receiving Messages Using a Simple Web Application

- 46.5.1 The websimplemessage Facelets Pages

- 46.5.2 The websimplemessage Managed Beans

- 46.5.3 Running the websimplemessage Example

- 46.5.3.1 Creating Resources for the websimplemessage Example

- 46.5.3.2 To Package and Deploy websimplemessage Using NetBeans IDE

- 46.5.3.3 To Package and Deploy websimplemessage Using Maven

- 46.5.3.4 To Run the websimplemessage Example

- 46.6 Receiving Messages Asynchronously Using a Message-Driven Bean

- 46.6.1 Overview of the simplemessage Example

- 46.6.2 The simplemessage Application Client

- 46.6.3 The simplemessage Message-Driven Bean Class

- 46.6.3.1 The onMessage Method

- 46.6.4 Running the simplemessage Example

- 46.6.4.1 Creating Resources for the simplemessage Example

- 46.6.4.2 To Run the simplemessage Example Using NetBeans IDE

- 46.6.4.3 To Run the simplemessage Example Using Maven

- 46.7 Sending Messages from a Session Bean to an MDB

- 46.7.1 Writing the Application Components for the clientsessionmdb Example

- 46.7.1.1 Coding the Application Client: MyAppClient.java

- 46.7.1.2 Coding the Publisher Session Bean

- 46.7.1.3 Coding the Message-Driven Bean: MessageBean.java

- 46.7.2 Running the clientsessionmdb Example

- 46.7.2.1 To Run clientsessionmdb Using NetBeans IDE

- 46.7.2.2 To Run clientsessionmdb Using Maven

- 46.8 Using an Entity to Join Messages from Two MDBs

- 46.8.1 Overview of the clientmdbentity Example Application

- 46.8.2 Writing the Application Components for the clientmdbentity Example

- 46.8.2.1 Coding the Application Client: HumanResourceClient.java

- 46.8.2.2 Coding the Message-Driven Beans for the clientmdbentity Example

- 46.8.2.3 Coding the Entity Class for the clientmdbentity Example

- 46.8.3 Running the clientmdbentity Example

- 46.8.3.1 To Run clientmdbentity Using NetBeans IDE

- 46.8.3.2 To Run clientmdbentity Using Maven

- 46.8.3.3 Viewing the Application Output

- 46.9 Using NetBeans IDE to Create JMS Resources

- 46.9.1 To Create JMS Resources Using NetBeans IDE

- 46.9.2 To Delete JMS Resources Using NetBeans IDE

Part X Security

47 Introduction to Security in the Java EE Platform

- 47.1 Overview of Java EE Security

- 47.1.1 A Simple Application Security Walkthrough

- 47.1.1.1 Step 1: Initial Request

- 47.1.1.2 Step 2: Initial Authentication

- 47.1.1.3 Step 3: URL Authorization

- 47.1.1.4 Step 4: Fulfilling the Original Request

- 47.1.1.5 Step 5: Invoking Enterprise Bean Business Methods

- 47.1.2 Features of a Security Mechanism

- 47.1.3 Characteristics of Application Security

- 47.2 Security Mechanisms

- 47.2.1 Java SE Security Mechanisms

- 47.2.2 Java EE Security Mechanisms

- 47.2.2.1 Application-Layer Security

- 47.2.2.2 Transport-Layer Security

- 47.2.2.3 Message-Layer Security

- 47.3 Securing Containers

- 47.3.1 Using Annotations to Specify Security Information

- 47.3.2 Using Deployment Descriptors for Declarative Security

- 47.3.3 Using Programmatic Security

- 47.4 Securing GlassFish Server

- 47.5 Working with Realms, Users, Groups, and Roles

- 47.5.1 What Are Realms, Users, Groups, and Roles?

- 47.5.1.1 What Is a Realm?

- 47.5.1.2 What Is a User?

- 47.5.1.3 What Is a Group?

- 47.5.1.4 What Is a Role?

- 47.5.1.5 Some Other Terminology

- 47.5.2 Managing Users and Groups in GlassFish Server

- 47.5.2.1 To Add Users to GlassFish Server

- 47.5.3 Setting Up Security Roles

- 47.5.4 Mapping Roles to Users and Groups

- 47.6 Establishing a Secure Connection Using SSL

- 47.6.1 Verifying and Configuring SSL Support

- 47.7 Further Information about Security

48 Getting Started Securing Web Applications

- 48.1 Overview of Web Application Security

- 48.2 Securing Web Applications

- 48.2.1 Specifying Security Constraints

- 48.2.1.1 Specifying a Web Resource Collection

- 48.2.1.2 Specifying an Authorization Constraint

- 48.2.1.3 Specifying a Secure Connection

- 48.2.1.4 Specifying Security Constraints for Resources

- 48.2.2 Specifying Authentication Mechanisms

- 48.2.2.1 HTTP Basic Authentication

- 48.2.2.2 Form-Based Authentication

- 48.2.2.3 Digest Authentication

- 48.2.3 Specifying an Authentication Mechanism in the Deployment Descriptor

- 48.2.4 Declaring Security Roles

- 48.3 Using Programmatic Security with Web Applications

- 48.3.1 Authenticating Users Programmatically

- 48.3.2 Checking Caller Identity Programmatically

- 48.3.3 Example Code for Programmatic Security

- 48.3.4 Declaring and Linking Role References

- 48.4 Examples: Securing Web Applications

- 48.4.1 To Set Up Your System for Running the Security Examples

- 48.4.2 The hello2-basicauth Example: Basic Authentication with a Servlet

- 48.4.2.1 Specifying Security for Basic Authentication Using Annotations

- 48.4.2.2 To Build, Package, and Deploy the hello2-basicauth Example Using NetBeans IDE

- 48.4.2.3 To Build, Package, and Deploy the hello2-basicauth Example Using Maven

- 48.4.2.4 To Run the hello2-basicauth Example

- 48.4.3 The hello1-formauth Example: Form-Based Authentication with a JavaServer Faces Application

- 48.4.3.1 Creating the Login Form and the Error Page

- 48.4.3.2 Specifying Security for the Form-Based Authentication Example

- 48.4.3.3 To Build, Package, and Deploy the hello1-formauth Example Using NetBeans IDE

- 48.4.3.4 To Build, Package, and Deploy the hello1-formauth Example Using Maven and the asadmin Command

- 48.4.3.5 To Run the hello1-formauth Example

49 Getting Started Securing Enterprise Applications

- 49.1 Basic Security Tasks for Enterprise Applications

- 49.2 Securing Enterprise Beans

- 49.2.1 Securing an Enterprise Bean Using Declarative Security

- 49.2.1.1 Specifying Authorized Users by Declaring Security Roles

- 49.2.1.2 Specifying an Authentication Mechanism and Secure Connection

- 49.2.2 Securing an Enterprise Bean Programmatically

- 49.2.2.1 Accessing an Enterprise Bean Caller's Security Context

- 49.2.3 Propagating a Security Identity (Run-As)

- 49.2.3.1 Configuring a Component's Propagated Security Identity

- 49.2.3.2 Trust between Containers

- 49.2.4 Deploying Secure Enterprise Beans

- 49.3 Examples: Securing Enterprise Beans

- 49.3.1 The cart-secure Example: Securing an Enterprise Bean with Declarative Security

- 49.3.1.1 Annotating the Bean

- 49.3.1.2 To Run the cart-secure Example Using NetBeans IDE

- 49.3.1.3 To Run the cart-secure Example Using Maven

- 49.3.2 The converter-secure Example: Securing an Enterprise Bean with Programmatic Security

- 49.3.2.1 Modifying ConverterBean

- 49.3.2.2 Modifying ConverterServlet

- 49.3.2.3 To Run the converter-secure Example Using NetBeans IDE

- 49.3.2.4 To Run the converter-secure Example Using Maven

- 49.3.2.5 To Run the converter-secure Example

50 Java EE Security: Advanced Topics

- 50.1 Working with Digital Certificates

- 50.1.1 Creating a Server Certificate

- 50.1.1.1 To Use keytool to Create a Server Certificate

- 50.1.2 Adding Users to the Certificate Realm

- 50.1.3 Using a Different Server Certificate with GlassFish Server

- 50.1.3.1 To Specify a Different Server Certificate

- 50.2 Authentication Mechanisms

- 50.2.1 Client Authentication

- 50.2.2 Mutual Authentication

- 50.2.2.1 Enabling Mutual Authentication over SSL

- 50.2.2.2 Creating a Client Certificate for Mutual Authentication

- 50.3 Using the JDBC Realm for User Authentication

- 50.3.1 To Configure a JDBC Authentication Realm

- 50.4 Securing HTTP Resources

- 50.5 Securing Application Clients

- 50.5.1 Using Login Modules

- 50.5.2 Using Programmatic Login

- 50.6 Securing Enterprise Information Systems Applications

- 50.6.1 Container-Managed Sign-On

- 50.6.2 Component-Managed Sign-On

- 50.6.3 Configuring Resource Adapter Security

- 50.6.4 Mapping an Application Principal to EIS Principals

- 50.7 Configuring Security Using Deployment Descriptors

- 50.7.1 Specifying Security for Basic Authentication in the Deployment Descriptor

- 50.7.2 Specifying Non-Default Principal-to-Role Mapping in the Deployment Descriptor

- 50.8 Further Information about Advanced Security Topics

Part XI Java EE Supporting Technologies

51 Transactions

- 51.1 Transactions in Java EE Applications

- 51.2 What Is a Transaction?

- 51.3 Container-Managed Transactions

- 51.3.1 Transaction Attributes

- 51.3.1.1 Required Attribute

- 51.3.1.2 RequiresNew Attribute

- 51.3.1.3 Mandatory Attribute

- 51.3.1.4 NotSupported Attribute

- 51.3.1.5 Supports Attribute

- 51.3.1.6 Never Attribute

- 51.3.1.7 Summary of Transaction Attributes

- 51.3.1.8 Setting Transaction Attributes

- 51.3.2 Rolling Back a Container-Managed Transaction

- 51.3.3 Synchronizing a Session Bean's Instance Variables

- 51.3.4 Methods Not Allowed in Container-Managed Transactions

- 51.4 Bean-Managed Transactions

- 51.4.1 JTA Transactions

- 51.4.2 Returning without Committing

- 51.4.3 Methods Not Allowed in Bean-Managed Transactions

- 51.5 Transaction Timeouts

- 51.5.1 To Set a Transaction Timeout

- 51.6 Updating Multiple Databases

- 51.7 Transactions in Web Components

- 51.8 Further Information about Transactions

52 Resource Adapters and Contracts

- 52.1 What Is a Resource Adapter?

- 52.1.1 Management Contracts

- 52.1.1.1 Lifecycle Management

- 52.1.1.2 Work Management Contract

- 52.1.2 Generic Work Context Contract

- 52.1.3 Outbound and Inbound Contracts

- 52.2 Metadata Annotations

- 52.3 Common Client Interface

- 52.4 Using Resource Adapters with Contexts and Dependency Injection for Java EE (CDI)

- 52.5 Further Information about Resource Adapters

53 The Resource Adapter Examples

- 53.1 The trading Example

- 53.1.1 Using the Outbound Resource Adapter

- 53.1.2 Implementing the Outbound Resource Adapter

- 53.1.3 Running the trading Example

- 53.1.3.1 To Run the trading Example Using NetBeans IDE

- 53.1.3.2 To Run the trading Example Using Maven

- 53.2 The traffic Example

- 53.2.1 Using the Inbound Resource Adapter

- 53.2.2 Implementing the Inbound Resource Adapter

- 53.2.3 Running the traffic Example

- 53.2.3.1 To Run the traffic Example Using NetBeans IDE

- 53.2.3.2 To Run the traffic Example Using Maven

54 Using Java EE Interceptors

- 54.1 Overview of Interceptors

- 54.1.1 Interceptor Classes

- 54.1.2 Interceptor Lifecycle

- 54.1.3 Interceptors and CDI

- 54.2 Using Interceptors

- 54.2.1 Intercepting Method Invocations

- 54.2.1.1 Using Multiple Method Interceptors

- 54.2.1.2 Accessing Target Method Parameters from an Interceptor Class

- 54.2.2 Intercepting Lifecycle Callback Events

- 54.2.2.1 Using AroundConstruct Interceptor Methods

- 54.2.2.2 Using Multiple Lifecycle Callback Interceptors

- 54.2.3 Intercepting Timeout Events

- 54.2.3.1 Using Multiple Timeout Interceptors

- 54.2.4 Binding Interceptors to Components

- 54.2.4.1 Declaring the Interceptor Bindings on an Interceptor Class

- 54.2.4.2 Binding a Component to an Interceptor

- 54.2.5 Ordering Interceptors

- 54.3 The interceptor Example Application

- 54.3.1 Running the interceptor Example

- 54.3.1.1 To Run the interceptor Example Using NetBeans IDE

- 54.3.1.2 To Run the interceptor Example Using Maven

55 Batch Processing

- 55.1 Introduction to Batch Processing

- 55.1.1 Steps in Batch Jobs

- 55.1.2 Parallel Processing

- 55.1.3 Status and Decision Elements

- 55.1.4 Batch Framework Functionality

- 55.2 Batch Processing in Java EE

- 55.2.1 The Batch Processing Framework

- 55.2.2 Creating Batch Applications

- 55.2.3 Elements of a Batch Job

- 55.2.4 Properties and Parameters

- 55.2.5 Job Instances and Job Executions

- 55.2.6 Batch and Exit Status

- 55.3 Simple Use Case

- 55.3.1 Chunk Step

- 55.3.2 Task Step

- 55.4 Using the Job Specification Language

- 55.4.1 The job Element

- 55.4.2 The step Element

- 55.4.2.1 The chunk Element

- 55.4.2.2 The batchlet Element

- 55.4.2.3 The partition Element

- 55.4.3 The flow Element

- 55.4.4 The split Element

- 55.4.5 The decision Element

- 55.5 Creating Batch Artifacts

- 55.5.1 Batch Artifact Interfaces

- 55.5.2 Dependency Injection in Batch Artifacts

- 55.5.3 Using the Context Objects from the Batch Runtime

- 55.6 Submitting Jobs to the Batch Runtime

- 55.6.1 Starting a Job

- 55.6.2 Checking the Status of a Job

- 55.6.3 Invoking the Batch Runtime in Your Application

- 55.7 Packaging Batch Applications

- 55.8 The webserverlog Example Application

- 55.8.1 Architecture of the webserverlog Example Application

- 55.8.1.1 The Job Definition File

- 55.8.1.2 The LogLine and LogFilteredLine Items

- 55.8.1.3 The Chunk Step Batch Artifacts

- 55.8.1.4 The Listener Batch Artifacts

- 55.8.1.5 The Task Step Batch Artifact

- 55.8.1.6 The JavaServer Faces Pages

- 55.8.1.7 The Managed Bean

- 55.8.2 Running the webserverlog Example Application

- 55.8.2.1 To Run the webserverlog Example Application Using NetBeans IDE

- 55.8.2.2 To Run the webserverlog Example Application Using Maven

- 55.9 The phonebilling Example Application

- 55.9.1 Architecture of the phonebilling Example Application

- 55.9.1.1 The Job Definition File

- 55.9.1.2 The CallRecord and PhoneBill Entities

- 55.9.1.3 The Call Records Chunk Step

- 55.9.1.4 The Phone Billing Chunk Step

- 55.9.1.5 The JavaServer Faces Pages

- 55.9.1.6 The Managed Bean

- 55.9.2 Running the phonebilling Example Application

- 55.9.2.1 To Run the phonebilling Example Application Using NetBeans IDE

- 55.9.2.2 To Run the phonebilling Example Application Using Maven

- 55.10 Further Information about Batch Processing

56 Concurrency Utilities for Java EE

- 56.1 Concurrency Basics

- 56.1.1 Threads and Processes

- 56.2 Main Components of the Concurrency Utilities

- 56.3 Concurrency and Transactions

- 56.4 Concurrency and Security

- 56.5 The jobs Concurrency Example

- 56.5.1 Running the jobs Example

- 56.5.1.1 To Configure GlassFish Server for the Basic Concurrency Example

- 56.5.1.2 To Build, Package, and Deploy the jobs Example Using NetBeans IDE

- 56.5.1.3 To Build, Package, and Deploy the jobs Example Using Maven

- 56.5.1.4 To Run the jobs Example and Submit Jobs with Low Priority

- 56.5.1.5 To Run the jobs Example and Submit Jobs with High Priority

- 56.6 The taskcreator Concurrency Example

- 56.6.1 Running the taskcreator Example

- 56.6.1.1 To Build, Package, and Deploy the taskcreator Example Using NetBeans IDE

- 56.6.1.2 To Build, Package, and Deploy the taskcreator Example Using Maven

- 56.6.1.3 To Run the taskcreator Example

- 56.7 Further Information about the Concurrency Utilities

Part XII Case Studies

57 Duke's Bookstore Case Study Example

- 57.1 Design and Architecture of Duke's Bookstore

- 57.2 The Duke's Bookstore Interface

- 57.2.1 The Book Java Persistence API Entity

- 57.2.2 Enterprise Beans Used in Duke's Bookstore

- 57.2.3 Facelets Pages and Managed Beans Used in Duke's Bookstore

- 57.2.4 Custom Components and Other Custom Objects Used in Duke's Bookstore

- 57.2.5 Properties Files Used in Duke's Bookstore

- 57.2.6 Deployment Descriptors Used in Duke's Bookstore

- 57.3 Running the Duke's Bookstore Case Study Application

- 57.3.1 To Build and Deploy Duke's Bookstore Using NetBeans IDE

- 57.3.2 To Build and Deploy Duke's Bookstore Using Maven

- 57.3.3 To Run Duke's Bookstore

58 Duke's Tutoring Case Study Example

- 58.1 Design and Architecture of Duke's Tutoring

- 58.2 Main Interface

- 58.2.1 Java Persistence API Entities Used in the Main Interface

- 58.2.2 Enterprise Beans Used in the Main Interface

- 58.2.3 WebSocket Endpoint Used in the Main Interface

- 58.2.4 Facelets Files Used in the Main Interface

- 58.2.5 Helper Classes Used in the Main Interface

- 58.2.6 Properties Files

- 58.2.7 Deployment Descriptors Used in Duke's Tutoring

- 58.3 Administration Interface

- 58.3.1 Enterprise Beans Used in the Administration Interface

- 58.3.2 Facelets Files Used in the Administration Interface

- 58.3.3 CDI Managed Beans Used in the Administration Interface

- 58.3.4 Helper Classes Used in the Administration Interface

- 58.4 Running the Duke's Tutoring Case Study Application

- 58.4.1 Running Duke's Tutoring

- 58.4.1.1 To Build and Deploy Duke's Tutoring Using NetBeans IDE

- 58.4.1.2 To Build and Deploy Duke's Tutoring Using Maven

- 58.4.1.3 Using Duke's Tutoring

59 Duke's Forest Case Study Example

- 59.1 Design and Architecture of Duke's Forest

- 59.1.1 The events Project

- 59.1.2 The entities Project

- 59.1.3 The dukes-payment Project

- 59.1.4 The dukes-resources Project

- 59.1.5 The Duke's Store Project

- 59.1.5.1 Enterprise Beans Used in Duke's Store

- 59.1.5.2 Facelets Files Used in the Main Interface of Duke's Store

- 59.1.5.3 Facelets Files Used in the Administration Interface of Duke's Store

- 59.1.5.4 Managed Beans Used in Duke's Store

- 59.1.5.5 Helper Classes Used in Duke's Store

- 59.1.5.6 Qualifiers Used in Duke's Store

- 59.1.5.7 Event Handlers Used in Duke's Store

- 59.1.5.8 Deployment Descriptors Used in Duke's Store

- 59.1.6 The Duke's Shipment Project

- 59.1.6.1 Enterprise Beans Used in Duke's Shipment

- 59.1.6.2 Facelets Files Used in Duke's Shipment

- 59.1.6.3 Managed Beans Used in Duke's Shipment

- 59.1.6.4 Helper Class Used in Duke's Shipment

- 59.1.6.5 Qualifier Used in Duke's Shipment

- 59.1.6.6 Deployment Descriptors Used in Duke's Shipment

- 59.2 Building and Deploying the Duke's Forest Case Study Application

- 59.2.1 To Build and Deploy the Duke's Forest Application Using NetBeans IDE

- 59.2.2 To Build and Deploy the Duke's Forest Application Using Maven

- 59.3 Running the Duke's Forest Application

- 59.3.1 To Register as a Duke's Store Customer

- 59.3.2 To Purchase Products

- 59.3.3 To Approve Shipment of a Product

- 59.3.4 To Create a New Product

Index

Preface

This tutorial is a guide to developing enterprise applications for the Java Platform, Enterprise Edition 7 (Java EE 7), using GlassFish Server Open Source Edition.

GlassFish Server Open Source Edition is the leading open-source and open-community platform for building and deploying next-generation applications and services. GlassFish Server Open Source Edition, developed by the GlassFish project open-source community at https://glassfish.java.net/, is the first compatible implementation of the Java EE 7 platform specification. This lightweight, flexible, and open-source application server enables organizations not only to leverage the new capabilities introduced within the Java EE 7 specification, but also to add to their existing capabilities through a faster and more streamlined development and deployment cycle. GlassFish Server Open Source Edition is hereafter referred to as GlassFish Server.

The following topics are addressed here:

- Audience

- Documentation Accessibility

- Before You Read This Book

- Related Documentation

- Conventions

- Default Paths and File Names

Audience

This tutorial is intended for programmers interested in developing and deploying Java EE 7 applications. It covers the technologies comprising the Java EE platform and describes how to develop Java EE components and deploy them on the Java EE Software Development Kit (SDK).

Documentation Accessibility

For information about Oracle's commitment to accessibility, visit the Oracle Accessibility Program website at http://www.oracle.com/pls/topic/lookup?ctx=acc&id=docacc.

Access to Oracle Support

Oracle customers have access to electronic support through My Oracle Support. For information, visit http://www.oracle.com/pls/topic/lookup?ctx=acc&id=info or visit http://www.oracle.com/pls/topic/lookup?ctx=acc&id=trs if you are hearing impaired.

Before You Read This Book

Before proceeding with this tutorial, you should have a good knowledge of the Java programming language. A good way to get to that point is to work through the Java Tutorials (http://docs.oracle.com/javase/tutorial/index.html).

Related Documentation

The GlassFish Server documentation set describes deployment planning and system installation. To obtain documentation for GlassFish Server Open Source Edition, go to https://glassfish.java.net/docs/.

The Java EE 7 API specification can be viewed at http://docs.oracle.com/javaee/7/api/ and is also provided in the Java EE 7 SDK.

Additionally, the Java EE Specifications at http://www.oracle.com/technetwork/java/javaee/tech/index.html might be useful.

For information about creating enterprise applications in the NetBeans Integrated Development Environment (IDE), see https://netbeans.org/kb/.

For information about the Java DB database for use with GlassFish Server, see http://www.oracle.com/technetwork/java/javadb/overview/index.html.

The GlassFish Samples project is a collection of sample applications that demonstrate a broad range of Java EE technologies. The GlassFish Samples are bundled with the Java EE Software Development Kit (SDK) and are also available from the GlassFish Samples project page at https://glassfish-samples.java.net/.

Conventions

The following table describes the typographic conventions that are used in this book.

Convention

Meaning

Example

Boldface

Boldface type indicates graphical user interface elements associated with an action or terms defined in text.

From the File menu, choose Open Project.
A cache is a copy that is stored locally.

Monospace

Monospace type indicates the names of files and directories, commands within a paragraph, URLs, code in examples, text that appears on the screen, or text that you enter.

Edit your .login file.
Use ls -a to list all files.

machine_name% you have mail.

Italic

Italic type indicates book titles, emphasis, or placeholder variables for which you supply particular values.

Read Chapter 6 in the User's Guide.
Do not save the file.

The command to remove a file is rm filename.

Default Paths and File Names

The following table describes the default paths and file names that are used in this book.

Placeholder

Description

Default Value

as-install

Represents the base installation directory for GlassFish Server or the SDK of which GlassFish Server is a part.

Installations on the Solaris operating system, Linux operating system, and Mac operating system:
user's-home-directory/glassfish4/glassfish

Windows, all installations:

SystemDrive:\glassfish4\glassfish

as-install-parent

Represents the parent of the base installation directory for GlassFish Server.

Installations on the Solaris operating system, Linux operating system, and Mac operating system:
user's-home-directory/glassfish4

Windows, all installations:

SystemDrive:\glassfish4

tut-install

Represents the base installation directory for the Java EE Tutorial after you install GlassFish Server or the SDK and run the Update Tool.

as-install-parent/docs/javaee-tutorial

domain-dir

Represents the directory in which a domain's configuration is stored.

as-install/domains/domain1

Part I

Introduction

Part I introduces the platform, the tutorial, and the examples. This part contains the following chapters:

- Chapter 1, "Overview"

- Chapter 2, "Using the Tutorial Examples"

1 Overview

This chapter introduces you to Java EE enterprise application development. Here you will review development basics, learn about the Java EE architecture and APIs, become acquainted with important terms and concepts, and find out how to approach Java EE application programming, assembly, and deployment.

Developers today increasingly recognize the need for distributed, transactional, and portable applications that leverage the speed, security, and reliability of server-side technology. Enterprise applications provide the business logic for an enterprise. They are centrally managed and often interact with other enterprise software. In the world of information technology, enterprise applications must be designed, built, and produced for less money, with greater speed, and with fewer resources.

With the Java Platform, Enterprise Edition (Java EE), development of Java enterprise applications has never been easier or faster. The aim of the Java EE platform is to provide developers with a powerful set of APIs while shortening development time, reducing application complexity, and improving application performance.

The Java EE platform is developed through the Java Community Process (JCP), which is responsible for all Java technologies. Expert groups composed of interested parties have created Java Specification Requests (JSRs) to define the various Java EE technologies. The work of the Java Community under the JCP program helps to ensure Java technology's standards of stability and cross-platform compatibility.

The Java EE platform uses a simplified programming model. XML deployment descriptors are optional. Instead, a developer can simply enter the information as an annotation directly into a Java source file, and the Java EE server will configure the component at deployment and runtime. These annotations are generally used to embed in a program data that would otherwise be furnished in a deployment descriptor. With annotations, you put the specification information in your code next to the program element affected.

In the Java EE platform, dependency injection can be applied to all resources a component needs, effectively hiding the creation and lookup of resources from application code. Dependency injection can be used in Enterprise JavaBeans (EJB) containers, web containers, and application clients. Dependency injection allows the Java EE container to automatically insert references to other required components or resources, using annotations.

This tutorial uses examples to describe the features available in the Java EE platform for developing enterprise applications. Whether you are a new or experienced enterprise developer, you should find the examples and accompanying text a valuable and accessible knowledge base for creating your own solutions.

The following topics are addressed here:

- Java EE 7 Platform Highlights

- Java EE Application Model

- Distributed Multitiered Applications

- Java EE Containers

- Web Services Support

- Java EE Application Assembly and Deployment

- Java EE 7 APIs

- Java EE 7 APIs in the Java Platform, Standard Edition 7

- GlassFish Server Tools

1.1 Java EE 7 Platform Highlights

The most important goal of the Java EE 7 platform is to simplify development by providing a common foundation for the various kinds of components in the Java EE platform. Developers benefit from productivity improvements with more annotations and less XML configuration, more Plain Old Java Objects (POJOs), and simplified packaging. The Java EE 7 platform includes the following new features:

- New technologies, including the following:

- Batch Applications for the Java Platform

- Concurrency Utilities for Java EE

- Java API for JSON Processing (JSON-P)

- Java API for WebSocket

- New features for EJB components (see Enterprise JavaBeans Technology for details)

- New features for servlets (see Java Servlet Technology for details)

- New features for JavaServer Faces components (see JavaServer Faces Technology for details)

- New features for the Java Message Service (JMS) (see Java Message Service API for details)

1.2 Java EE Application Model

The Java EE application model begins with the Java programming language and the Java virtual machine. The proven portability, security, and developer productivity they provide form the basis of the application model. Java EE is designed to support applications that implement enterprise services for customers, employees, suppliers, partners, and others who make demands on or contributions to the enterprise. Such applications are inherently complex, potentially accessing data from a variety of sources and distributing applications to a variety of clients.

To better control and manage these applications, the business functions to support these various users are conducted in the middle tier. The middle tier represents an environment that is closely controlled by an enterprise's information technology department. The middle tier is typically run on dedicated server hardware and has access to the full services of the enterprise.

The Java EE application model defines an architecture for implementing services as multitier applications that deliver the scalability, accessibility, and manageability needed by enterprise-level applications. This model partitions the work needed to implement a multitier service into the following parts:

- The business and presentation logic to be implemented by the developer

- The standard system services provided by the Java EE platform

The developer can rely on the platform to provide solutions for the hard systems-level problems of developing a multitier service.

1.3 Distributed Multitiered Applications

The Java EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function, and the application components that make up a Java EE application are installed on various machines depending on the tier in the multitiered Java EE environment to which the application component belongs.

Figure 1-1 shows two multitiered Java EE applications divided into the tiers described in the following list. The Java EE application parts shown in Figure 1-1 are presented in Java EE Components.

- Client-tier components run on the client machine.

- Web-tier components run on the Java EE server.

- Business-tier components run on the Java EE server.

- Enterprise information system (EIS)-tier software runs on the EIS server.

Although a Java EE application can consist of all tiers shown in Figure 1-1, Java EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three locations: client machines, the Java EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client-and-server model by placing a multithreaded application server between the client application and back-end storage.

Figure 1-1 Multitiered Applications

1.3.1 Security

Although other enterprise application models require platform-specific security measures in each application, the Java EE security environment enables security constraints to be defined at deployment time. The Java EE platform makes applications portable to a wide variety of security implementations by shielding application developers from the complexity of implementing security features.

The Java EE platform provides standard declarative access control rules that are defined by the developer and interpreted when the application is deployed on the server. Java EE also provides standard login mechanisms so that application developers do not have to implement these mechanisms in their applications. The same application works in a variety of security environments without changing the source code.

1.3.2 Java EE Components

Java EE applications are made up of components. A Java EE component is a self-contained functional software unit that is assembled into a Java EE application with its related classes and files and that communicates with other components.

The Java EE specification defines the following Java EE components:

- Application clients and applets are components that run on the client.

- Java Servlet, JavaServer Faces, and JavaServer Pages (JSP) technology components are web components that run on the server.

- EJB components (enterprise beans) are business components that run on the server.

Java EE components are written in the Java programming language and are compiled in the same way as any program in the language. The differences between Java EE components and "standard" Java classes are that Java EE components are assembled into a Java EE application, they are verified to be well formed and in compliance with the Java EE specification, and they are deployed to production, where they are run and managed by the Java EE server.

1.3.3 Java EE Clients

A Java EE client is usually either a web client or an application client.

1.3.3.1 Web Clients

A web client consists of two parts:

- Dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by web components running in the web tier

- A web browser, which renders the pages received from the server

A web client is sometimes called a thin client. Thin clients usually do not query databases, execute complex business rules, or connect to legacy applications. When you use a thin client, such heavyweight operations are off-loaded to enterprise beans executing on the Java EE server, where they can leverage the security, speed, services, and reliability of Java EE server-side technologies.

1.3.3.2 Application Clients

An application client runs on a client machine and provides a way for users to handle tasks that require a richer user interface than can be provided by a markup language. An application client typically has a graphical user interface (GUI) created from the Swing API or the Abstract Window Toolkit (AWT) API, but a command-line interface is certainly possible.

Application clients directly access enterprise beans running in the business tier. However, if application requirements warrant it, an application client can open an HTTP connection to establish communication with a servlet running in the web tier. Application clients written in languages other than Java can interact with Java EE servers, enabling the Java EE platform to interoperate with legacy systems, clients, and non-Java languages.

1.3.3.3 Applets

A web page received from the web tier can include an embedded applet. Written in the Java programming language, an applet is a small client application that executes in the Java virtual machine installed in the web browser. However, client systems will likely need the Java Plug-in and possibly a security policy file for the applet to successfully execute in the web browser.

Web components are the preferred API for creating a web client program because no plug-ins or security policy files are needed on the client systems. Also, web components enable cleaner and more modular application design because they provide a way to separate applications programming from web page design. Personnel involved in web page design thus do not need to understand Java programming language syntax to do their jobs.

1.3.3.4 The JavaBeans Component Architecture

The server and client tiers might also include components based on the JavaBeans component architecture (JavaBeans components) to manage the data flow between the following:

- An application client or applet and components running on the Java EE server

- Server components and a database

JavaBeans components are not considered Java EE components by the Java EE specification.

JavaBeans components have properties and have get and set methods for accessing those properties. JavaBeans components used in this way are typically simple in design and implementation but should conform to the naming and design conventions outlined in the JavaBeans component architecture.

1.3.3.5 Java EE Server Communications

Figure 1-2 shows the various elements that can make up the client tier. The client communicates with the business tier running on the Java EE server either directly or, as in the case of a client running in a browser, by going through web pages or servlets running in the web tier.

Figure 1-2 Server Communication

1.3.4 Web Components

Java EE web components are either servlets or web pages created using JavaServer Faces technology and/or JSP technology (JSP pages). Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content. JavaServer Faces technology builds on servlets and JSP technology and provides a user interface component framework for web applications.

Static HTML pages and applets are bundled with web components during application assembly but are not considered web components by the Java EE specification. Server-side utility classes can also be bundled with web components and, like HTML pages, are not considered web components.

As shown in Figure 1-3, the web tier, like the client tier, might include a JavaBeans component to manage the user input and send that input to enterprise beans running in the business tier for processing.

Figure 1-3 Web Tier and Java EE Applications

1.3.5 Business Components

Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in either the business tier or the web tier. Figure 1-4 shows how an enterprise bean receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.

Figure 1-4 Business and EIS Tiers

1.3.6 Enterprise Information System Tier

The enterprise information system tier handles EIS software and includes enterprise infrastructure systems, such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems. For example, Java EE application components might need access to enterprise information systems for database connectivity.

1.4 Java EE Containers

Normally, thin-client multitiered applications are hard to write because they involve many lines of intricate code to handle transaction and state management, multithreading, resource pooling, and other complex low-level details. The component-based and platform-independent Java EE architecture makes applications easy to write because business logic is organized into reusable components. In addition, the Java EE server provides underlying services in the form of a container for every component type. Because you do not have to develop these services yourself, you are free to concentrate on solving the business problem at hand.

1.4.1 Container Services

Containers are the interface between a component and the low-level, platform-specific functionality that supports the component. Before it can be executed, a web, enterprise bean, or application client component must be assembled into a Java EE module and deployed into its container.

The assembly process involves specifying container settings for each component in the Java EE application and for the Java EE application itself. Container settings customize the underlying support provided by the Java EE server, including such services as security, transaction management, Java Naming and Directory Interface (JNDI) API lookups, and remote connectivity. Here are some of the highlights.

- The Java EE security model lets you configure a web component or enterprise bean so that system resources are accessed only by authorized users.

- The Java EE transaction model lets you specify relationships among methods that make up a single transaction so that all methods in one transaction are treated as a single unit.

- JNDI lookup services provide a unified interface to multiple naming and directory services in the enterprise so that application components can access these services.

- The Java EE remote connectivity model manages low-level communications between clients and enterprise beans. After an enterprise bean is created, a client invokes methods on it as if it were in the same virtual machine.

Because the Java EE architecture provides configurable services, components within the same application can behave differently based on where they are deployed. For example, an enterprise bean can have security settings that allow it a certain level of access to database data in one production environment and another level of database access in another production environment.

The container also manages nonconfigurable services, such as enterprise bean and servlet lifecycles, database connection resource pooling, data persistence, and access to the Java EE platform APIs (see Java EE 7 APIs).

1.4.2 Container Types

The deployment process installs Java EE application components in the Java EE containers, as illustrated in Figure 1-5.

Figure 1-5 Java EE Server and Containers

The server and containers are as follows:

- Java EE server: The runtime portion of a Java EE product. A Java EE server provides EJB and web containers.

- EJB container: Manages the execution of enterprise beans for Java EE applications. Enterprise beans and their container run on the Java EE server.

- Web container: Manages the execution of web pages, servlets, and some EJB components for Java EE applications. Web components and their container run on the Java EE server.

- Application client container: Manages the execution of application client components. Application clients and their container run on the client.

- Applet container: Manages the execution of applets. Consists of a web browser and a Java Plug-in running on the client together.

1.5 Web Services Support

Web services are web-based enterprise applications that use open, XML-based standards and transport protocols to exchange data with calling clients. The Java EE platform provides the XML APIs and tools you need to quickly design, develop, test, and deploy web services and clients that fully interoperate with other web services and clients running on Java-based or non-Java-based platforms.

To write web services and clients with the Java EE XML APIs, all you need to do is pass parameter data to the method calls and process the data returned; for document-oriented web services, you send documents containing the service data back and forth. No low-level programming is needed because the XML API implementations do the work of translating the application data to and from an XML-based data stream that is sent over the standardized XML-based transport protocols. These XML-based standards and protocols are introduced in the following sections.

The translation of data to a standardized XML-based data stream is what makes web services and clients written with the Java EE XML APIs fully interoperable. This does not necessarily mean that the data being transported includes XML tags, because the transported data can itself be plain text, XML data, or any kind of binary data, such as audio, video, maps, program files, computer-aided design (CAD) documents, and the like. The next section introduces XML and explains how parties doing business can use XML tags and schemas to exchange data in a meaningful way.

1.5.1 XML

Extensible Markup Language (XML) is a cross-platform, extensible, text-based standard for representing data. Parties that exchange XML data can create their own tags to describe the data, set up schemas to specify which tags can be used in a particular kind of XML document, and use XML style sheets to manage the display and handling of the data.

For example, a web service can use XML and a schema to produce price lists, and companies that receive the price lists and schema can have their own style sheets to handle the data in a way that best suits their needs. Here are examples.

- One company might put XML pricing information through a program to translate the XML into HTML so that it can post the price lists to its intranet.

- A partner company might put the XML pricing information through a tool to create a marketing presentation.

- Another company might read the XML pricing information into an application for processing.

1.5.2 SOAP Transport Protocol

Client requests and web service responses are transmitted as Simple Object Access Protocol (SOAP) messages over HTTP to enable a completely interoperable exchange between clients and web services, all running on different platforms and at various locations on the Internet. HTTP is a familiar request-and-response standard for sending messages over the Internet, and SOAP is an XML-based protocol that follows the HTTP request-and-response model.

The SOAP portion of a transported message does the following:

- Defines an XML-based envelope to describe what is in the message and explain how to process the message

- Includes XML-based encoding rules to express instances of application-defined data types within the message

- Defines an XML-based convention for representing the request to the remote service and the resulting response

1.5.3 WSDL Standard Format

The Web Services Description Language (WSDL) is a standardized XML format for describing network services. The description includes the name of the service, the location of the service, and ways to communicate with the service. WSDL service descriptions can be published on the Web. GlassFish Server provides a tool for generating the WSDL specification of a web service that uses remote procedure calls to communicate with clients.

1.6 Java EE Application Assembly and Deployment

A Java EE application is packaged into one or more standard units for deployment to any Java EE platform-compliant system. Each unit contains

- A functional component or components, such as an enterprise bean, web page, servlet, or applet

- An optional deployment descriptor that describes its content

Once a Java EE unit has been produced, it is ready to be deployed. Deployment typically involves using a platform's deployment tool to specify location-specific information, such as a list of local users who can access it and the name of the local database. Once deployed on a local platform, the application is ready to run.

1.7 Java EE 7 APIs

Figure 1-6 shows the relationships among the Java EE containers.

Figure 1-6 Java EE Containers

Figure 1-7 shows the availability of the Java EE 7 APIs in the web container.

Figure 1-7 Java EE APIs in the Web Container

Figure 1-8 shows the availability of the Java EE 7 APIs in the EJB container.

Figure 1-8 Java EE APIs in the EJB Container

Figure 1-9 shows the availability of the Java EE 7 APIs in the application client container.

Figure 1-9 Java EE APIs in the Application Client Container

The following sections give a brief summary of the technologies required by the Java EE platform and the APIs used in Java EE applications.

1.7.1 Enterprise JavaBeans Technology

An Enterprise JavaBeans (EJB) component, or enterprise bean, is a body of code that has fields and methods to implement modules of business logic. You can think of an enterprise bean as a building block that can be used alone or with other enterprise beans to execute business logic on the Java EE server.

Enterprise beans are either session beans or message-driven beans.

- A session bean represents a transient conversation with a client. When the client finishes executing, the session bean and its data are gone.

- A message-driven bean combines features of a session bean and a message listener, allowing a business component to receive messages asynchronously. Commonly, these are Java Message Service (JMS) messages.

In the Java EE 7 platform, new enterprise bean features include the following:

- Asynchronous local session beans in EJB Lite

- Nonpersistent timers in EJB Lite

The Java EE 7 platform requires Enterprise JavaBeans 3.2 and Interceptors 1.2. The Interceptors specification is part of the EJB specification.

1.7.2 Java Servlet Technology

Java Servlet technology lets you define HTTP-specific servlet classes. A servlet class extends the capabilities of servers that host applications accessed by way of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers.

In the Java EE 7 platform, new Java Servlet technology features include the following:

- Nonblocking I/O

- HTTP protocol upgrade

The Java EE 7 platform requires Servlet 3.1.

1.7.3 JavaServer Faces Technology

JavaServer Faces technology is a user interface framework for building web applications. The main components of JavaServer Faces technology are as follows:

- A GUI component framework.

- A flexible model for rendering components in different kinds of HTML or different markup languages and technologies. A Renderer object generates the markup to render the component and converts the data stored in a model object to types that can be represented in a view.

- A standard RenderKit for generating HTML 4.01 markup.

The following features support the GUI components:

- Input validation

- Event handling

- Data conversion between model objects and components

- Managed model object creation

- Page navigation configuration

- Expression Language (EL)

All this functionality is available using standard Java APIs and XML-based configuration files.

In the Java EE 7 platform, new features of JavaServer Faces technology include the following:

- HTML5-friendly markup

- Faces Flows

- Resource library contracts

The Java EE 7 platform requires JavaServer Faces 2.2 and Expression Language 3.0.

1.7.4 JavaServer Pages Technology

JavaServer Pages (JSP) technology lets you put snippets of servlet code directly into a text-based document. A JSP page is a text-based document that contains two types of text:

- Static data, which can be expressed in any text-based format, such as HTML or XML

- JSP elements, which determine how the page constructs dynamic content

For information about JSP technology, see the The Java EE 5 Tutorial at http://docs.oracle.com/javaee/5/tutorial/doc/.

The Java EE 7 platform requires JavaServer Pages 2.3 for compatibility with earlier releases but recommends the use of Facelets as the display technology in new applications.

1.7.5 JavaServer Pages Standard Tag Library

The JavaServer Pages Standard Tag Library (JSTL) encapsulates core functionality common to many JSP applications. Instead of mixing tags from numerous vendors in your JSP applications, you use a single, standard set of tags. This standardization allows you to deploy your applications on any JSP container that supports JSTL and makes it more likely that the implementation of the tags is optimized.

JSTL has iterator and conditional tags for handling flow control, tags for manipulating XML documents, internationalization tags, tags for accessing databases using SQL, and tags for commonly used functions.

The Java EE 7 platform requires JSTL 1.2.

1.7.6 Java Persistence API

The Java Persistence API (JPA) is a Java standards–based solution for persistence. Persistence uses an object/relational mapping approach to bridge the gap between an object-oriented model and a relational database. The Java Persistence API can also be used in Java SE applications outside of the Java EE environment. Java Persistence consists of the following areas:

- The Java Persistence API

- The query language

- Object/relational mapping metadata

The Java EE 7 platform requires Java Persistence API 2.1.

1.7.7 Java Transaction API

The Java Transaction API (JTA) provides a standard interface for demarcating transactions. The Java EE architecture provides a default auto commit to handle transaction commits and rollbacks. An auto commit means that any other applications that are viewing data will see the updated data after each database read or write operation. However, if your application performs two separate database access operations that depend on each other, you will want to use the JTA API to demarcate where the entire transaction, including both operations, begins, rolls back, and commits.

The Java EE 7 platform requires Java Transaction API 1.2.

1.7.8 Java API for RESTful Web Services

The Java API for RESTful Web Services (JAX-RS) defines APIs for the development of web services built according to the Representational State Transfer (REST) architectural style. A JAX-RS application is a web application that consists of classes packaged as a servlet in a WAR file along with required libraries.

The Java EE 7 platform requires JAX-RS 2.0.

1.7.9 Managed Beans

Managed Beans, lightweight container-managed objects (POJOs) with minimal requirements, support a small set of basic services, such as resource injection, lifecycle callbacks, and interceptors. Managed Beans represent a generalization of the managed beans specified by JavaServer Faces technology and can be used anywhere in a Java EE application, not just in web modules.

The Managed Beans specification is part of the Java EE 7 platform specification (JSR 342). The Java EE 7 platform requires Managed Beans 1.0.

1.7.10 Contexts and Dependency Injection for Java EE

Contexts and Dependency Injection for Java EE (CDI) defines a set of contextual services, provided by Java EE containers, that make it easy for developers to use enterprise beans along with JavaServer Faces technology in web applications. Designed for use with stateful objects, CDI also has many broader uses, allowing developers a great deal of flexibility to integrate different kinds of components in a loosely coupled but typesafe way.

The Java EE 7 platform requires CDI 1.1.

1.7.11 Dependency Injection for Java

Dependency Injection for Java defines a standard set of annotations (and one interface) for use on injectable classes.

In the Java EE platform, CDI provides support for Dependency Injection. Specifically, you can use injection points only in a CDI-enabled application.

The Java EE 7 platform requires Dependency Injection for Java 1.0.

1.7.12 Bean Validation

The Bean Validation specification defines a metadata model and API for validating data in JavaBeans components. Instead of distributing validation of data over several layers, such as the browser and the server side, you can define the validation constraints in one place and share them across the different layers.

The Java EE 7 platform requires Bean Validation 1.1.

1.7.13 Java Message Service API

The Java Message Service (JMS) API is a messaging standard that allows Java EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.

In the platform, new features of JMS include the following.

- A new, simplified API offers a simpler alternative to the previous API. This API includes a JMSContext object that combines the functions of a Connection and a Session.

- All objects with a close method implement the java.lang.Autocloseable interface so that they can be used in a Java SE 7 try-with-resources statement.

The Java EE 7 platform requires JMS 2.0.

1.7.14 Java EE Connector Architecture

The Java EE Connector Architecture is used by tools vendors and system integrators to create resource adapters that support access to enterprise information systems that can be plugged in to any Java EE product. A resource adapter is a software component that allows Java EE application components to access and interact with the underlying resource manager of the EIS. Because a resource adapter is specific to its resource manager, a different resource adapter typically exists for each type of database or enterprise information system.

The Java EE Connector Architecture also provides a performance-oriented, secure, scalable, and message-based transactional integration of Java EE platform–based web services with existing EISs that can be either synchronous or asynchronous. Existing applications and EISs integrated through the Java EE Connector Architecture into the Java EE platform can be exposed as XML-based web services by using JAX-WS and Java EE component models. Thus JAX-WS and the Java EE Connector Architecture are complementary technologies for enterprise application integration (EAI) and end-to-end business integration.

The Java EE 7 platform requires Java EE Connector Architecture 1.7.

1.7.15 JavaMail API

Java EE applications use the JavaMail API to send email notifications. The JavaMail API has two parts:

- An application-level interface used by the application components to send mail

- A service provider interface

The Java EE platform includes the JavaMail API with a service provider that allows application components to send Internet mail.

The Java EE 7 platform requires JavaMail 1.5.

1.7.16 Java Authorization Contract for Containers

The Java Authorization Contract for Containers (JACC) specification defines a contract between a Java EE application server and an authorization policy provider. All Java EE containers support this contract.

The JACC specification defines java.security.Permission classes that satisfy the Java EE authorization model. The specification defines the binding of container-access decisions to operations on instances of these permission classes. It defines the semantics of policy providers that use the new permission classes to address the authorization requirements of the Java EE platform, including the definition and use of roles.

The Java EE 7 platform requires JACC 1.5.

1.7.17 Java Authentication Service Provider Interface for Containers

The Java Authentication Service Provider Interface for Containers (JASPIC) specification defines a service provider interface (SPI) by which authentication providers that implement message authentication mechanisms may be integrated in client or server message-processing containers or runtimes. Authentication providers integrated through this interface operate on network messages provided to them by their calling containers. The authentication providers transform outgoing messages so that the source of each message can be authenticated by the receiving container, and the recipient of the message can be authenticated by the message sender. Authentication providers authenticate each incoming message and return to their calling containers the identity established as a result of the message authentication.

The Java EE 7 platform requires JASPIC 1.1.

1.7.18 Java API for WebSocket

WebSocket is an application protocol that provides full-duplex communications between two peers over TCP. The Java API for WebSocket enables Java EE applications to create endpoints using annotations that specify the configuration parameters of the endpoint and designate its lifecycle callback methods.

The WebSocket API is new to the Java EE 7 platform. The Java EE 7 platform requires Java API for WebSocket 1.0.

1.7.19 Java API for JSON Processing

JSON is a text-based data exchange format derived from JavaScript that is used in web services and other connected applications. The Java API for JSON Processing (JSON-P) enables Java EE applications to parse, transform, and query JSON data using the object model or the streaming model.

JSON-P is new to the Java EE 7 platform. The Java EE 7 platform requires JSON-P 1.0.

1.7.20 Concurrency Utilities for Java EE

Concurrency Utilities for Java EE is a standard API for providing asynchronous capabilities to Java EE application components through the following types of objects: managed executor service, managed scheduled executor service, managed thread factory, and context service.

Concurrency Utilities for Java EE is new to the Java EE 7 platform. The Java EE 7 platform requires Concurrency Utilities for Java EE 1.0.

1.7.21 Batch Applications for the Java Platform

Batch jobs are tasks that can be executed without user interaction. The Batch Applications for the Java Platform specification is a batch framework that provides support for creating and running batch jobs in Java applications. The batch framework consists of a batch runtime, a job specification language based on XML, a Java API to interact with the batch runtime, and a Java API to implement batch artifacts.

Batch Applications for the Java Platform is new to the Java EE 7 platform. The Java EE 7 platform requires Batch Applications for the Java Platform 1.0.

1.8 Java EE 7 APIs in the Java Platform, Standard Edition 7

Several APIs that are required by the Java EE 7 platform are included in the Java Platform, Standard Edition 7 (Java SE 7) and are thus available to Java EE applications.

1.8.1 Java Database Connectivity API

The Java Database Connectivity (JDBC) API lets you invoke SQL commands from Java programming language methods. You use the JDBC API in an enterprise bean when you have a session bean access the database. You can also use the JDBC API from a servlet or a JSP page to access the database directly without going through an enterprise bean.

The JDBC API has two parts:

- An application-level interface used by the application components to access a database

- A service provider interface to attach a JDBC driver to the Java EE platform

The Java SE 7 platform requires JDBC 4.1.

1.8.2 Java Naming and Directory Interface API

The Java Naming and Directory Interface (JNDI) API provides naming and directory functionality, enabling applications to access multiple naming and directory services, such as LDAP, DNS, and NIS. The JNDI API provides applications with methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes. Using JNDI, a Java EE application can store and retrieve any type of named Java object, allowing Java EE applications to coexist with many legacy applications and systems.

Java EE naming services provide application clients, enterprise beans, and web components with access to a JNDI naming environment. A naming environment allows a component to be customized without the need to access or change the component's source code. A container implements the component's environment and provides it to the component as a JNDI naming context.

The naming environment provides four logical namespaces: java:comp, java:module, java:app, and java:global for objects available to components, modules, or applications or shared by all deployed applications. A Java EE component can access named system-provided and user-defined objects. The names of some system-provided objects, such as a default JDBC DataSource object, a default JMS connection factory, and a JTA UserTransaction object, are stored in the java:comp namespace. The Java EE platform allows a component to name user-defined objects, such as enterprise beans, environment entries, JDBC DataSource objects, and messaging destinations.

A Java EE component can also locate its environment naming context by using JNDI interfaces. A component can create a javax.naming.InitialContext object and look up the environment naming context in InitialContext under the name java:comp/env. A component's naming environment is stored directly in the environment naming context or in any of its direct or indirect subcontexts.

1.8.3 JavaBeans Activation Framework

The JavaBeans Activation Framework (JAF) is used by the JavaMail API. JAF provides standard services to determine the type of an arbitrary piece of data, encapsulate access to it, discover the operations available on it, and create the appropriate JavaBeans component to perform those operations.

1.8.4 Java API for XML Processing

The Java API for XML Processing (JAXP), part of the Java SE platform, supports the processing of XML documents using Document Object Model (DOM), Simple API for XML (SAX), and Extensible Stylesheet Language Transformations (XSLT). JAXP enables applications to parse and transform XML documents independently of a particular XML-processing implementation.

JAXP also provides namespace support, which lets you work with schemas that might otherwise have naming conflicts. Designed to be flexible, JAXP lets you use any XML-compliant parser or XSL processor from within your application and supports the Worldwide Web Consortium (W3C) schema. You can find information on the W3C schema at jollibeefood.rest/>

1.8.3 .5a>JavaBeans Activation Framewo Archit nauru uont>The JavaBeans Activation Framewo Archit nauru uont><>< ana repres="1em">

>The JavaBeans Activation Framng (EEn7processin requires,SE B 2.2/div>

1.8.4 Java APIProcessingThe Java AP"+1">