About This Tutorial

Who Should Use This Tutorial

Prerequisites

How to Read This Tutorial

About the Examples

Further Information

How to Print This Tutorial

Typographical Conventions

Feedback

Chapter 1:   Overview

Java EE Application Model

Distributed Multitiered Applications

Security

Java EE Components

Java EE Clients

Web Components

Business Components

Enterprise Information System Tier

Java EE Containers

Container Services

Container Types

Web Services Support

XML

SOAP Transport Protocol

WSDL Standard Format

UDDI and ebXML Standard Formats

Java EE Application Assembly and Deployment

Packaging Applications

Development Roles

Java EE Product Provider

Tool Provider

Application Component Provider

Application Assembler

Application Deployer and Administrator

Java EE 5 APIs

Enterprise JavaBeans Technology

Java Servlet Technology

JavaServer Pages Technology

JavaServer Pages Standard Tag Library

JavaServer Faces

Java Message Service API

Java Transaction API

JavaMail API

JavaBeans Activation Framework

Java API for XML Processing

Java API for XML Web Services (JAX-WS)

Java Architecture for XML Binding (JAXB)

SOAP with Attachments API for Java

Java API for XML Registries

J2EE Connector Architecture

Java Database Connectivity API

Java Persistence API

Java Naming and Directory Interface

Java Authentication and Authorization Service

Simplified Systems Integration

Sun Java System Application Server Platform Edition 9

Tools

Starting and Stopping the Application Server

Starting the Admin Console

Starting and Stopping the Java DB Database Server

Debugging Java EE Applications

Part One: The Web Tier    

Chapter 2:   Getting Started with Web Applications

Web Application Life Cycle

Web Modules

Packaging Web Modules

Deploying a WAR File

Testing Deployed Web Modules

Listing Deployed Web Modules

Updating Web Modules

Undeploying Web Modules

Configuring Web Applications

Mapping URLs to Web Components

Declaring Welcome Files

Setting Initialization Parameters

Mapping Errors to Error Screens

Declaring Resource References

Duke's Bookstore Examples

Accessing Databases from Web Applications

Populating the Example Database

Creating a Data Source in the Application Server

Further Information

Chapter 3:   Java Servlet Technology

What Is a Servlet?

The Example Servlets

Troubleshooting

Servlet Life Cycle

Handling Servlet Life-Cycle Events

Handling Errors

Sharing Information

Using Scope Objects

Controlling Concurrent Access to Shared Resources

Accessing Databases

Initializing a Servlet

Writing Service Methods

Getting Information from Requests

Constructing Responses

Filtering Requests and Responses

Programming Filters

Programming Customized Requests and Responses

Specifying Filter Mappings

Invoking Other Web Resources

Including Other Resources in the Response

Transferring Control to Another Web Component

Accessing the Web Context

Maintaining Client State

Accessing a Session

Associating Objects with a Session

Session Management

Session Tracking

Finalizing a Servlet

Tracking Service Requests

Notifying Methods to Shut Down

Creating Polite Long-Running Methods

Further Information

Chapter 4:   JavaServer Pages Technology

What Is a JSP Page?

Example

The Example JSP Pages

The Life Cycle of a JSP Page

Translation and Compilation

Execution

Creating Static Content

Response and Page Encoding

Creating Dynamic Content

Using Objects within JSP Pages

Unified Expression Language

Immediate and Deferred Evaluation Syntax

Value and Method Expressions

Defining a Tag Attribute Type

Deactivating Expression Evaluation

Literal Expressions

Resolving Expressions

Implicit Objects

Operators

Reserved Words

Examples

Functions

JavaBeans Components

JavaBeans Component Design Conventions

Creating and Using a JavaBeans Component

Setting JavaBeans Component Properties

Retrieving JavaBeans Component Properties

Using Custom Tags

Declaring Tag Libraries

Including the Tag Library Implementation

Reusing Content in JSP Pages

Transferring Control to Another Web Component

jsp:param Element

Including an Applet

Setting Properties for Groups of JSP Pages

Further Information

Chapter 5:   JavaServer Pages Documents

The Example JSP Document

Creating a JSP Document

Declaring Tag Libraries

Including Directives in a JSP Document

Creating Static and Dynamic Content

Using the jsp:root Element

Using the jsp:output Element

Identifying the JSP Document to the Container

Chapter 6:   JavaServer Pages Standard Tag Library

The Example JSP Pages

Using JSTL

Tag Collaboration

Core Tag Library

Variable Support Tags

Flow Control Tags

URL Tags

Miscellaneous Tags

XML Tag Library

Core Tags

Flow Control Tags

Transformation Tags

Internationalization Tag Library

Setting the Locale

Messaging Tags

Formatting Tags

SQL Tag Library

query Tag Result Interface

Functions

Further Information

Chapter 7:   Custom Tags in JSP Pages

What Is a Custom Tag?

The Example JSP Pages

Types of Tags

Tags with Attributes

Tags with Bodies

Tags That Define Variables

Communication between Tags

Encapsulating Reusable Content Using Tag Files

Tag File Location

Tag File Directives

Evaluating Fragments Passed to Tag Files

Examples

Tag Library Descriptors

Top-Level Tag Library Descriptor Elements

Declaring Tag Files

Declaring Tag Handlers

Declaring Tag Attributes for Tag Handlers

Declaring Tag Variables for Tag Handlers

Programming Simple Tag Handlers

Including Tag Handlers in Web Applications

How Is a Simple Tag Handler Invoked?

Tag Handlers for Basic Tags

Tag Handlers for Tags with Attributes

Tag Handlers for Tags with Bodies

Tag Handlers for Tags That Define Variables

Cooperating Tags

Examples

Chapter 8:   Scripting in JSP Pages

The Example JSP Pages

Using Scripting

Disabling Scripting

Declarations

Initializing and Finalizing a JSP Page

Scriptlets

Expressions

Programming Tags That Accept Scripting Elements

TLD Elements

Tag Handlers

Tags with Bodies

Cooperating Tags

Tags That Define Variables

Chapter 9:   JavaServer Faces Technology

JavaServer Faces Technology Benefits

What is a JavaServer Faces Application?

A Simple JavaServer Faces Application

Steps in the Development Process

Mapping the FacesServlet Instance

Creating the Pages

Defining Page Navigation

Configuring Error Messages

Developing the Beans

Adding Managed Bean Declarations

User Interface Component Model

User Interface Component Classes

Component Rendering Model

Conversion Model

Event and Listener Model

Validation Model

Navigation Model

Backing Beans

The Life Cycle of a JavaServer Faces Page

Further Information

Chapter 10:   Using JavaServer Faces Technology in JSP Pages

The Example JavaServer Faces Application

Setting Up a Page

Using the Core Tags

Adding UI Components to a Page Using the HTML Component Tags

UI Component Tag Attributes

Adding a Form Component

Using Text Components

Using Command Components for Performing Actions and Navigation

Using Data-Bound Table Components

Adding Graphics and Images With the graphicImage Tag

Laying Out Components with the UIPanel Component

Rendering Components for Selecting One Value

Rendering Components for Selecting Multiple Values

The UISelectItem, UISelectItems, and UISelectItemGroup Components

Displaying Error Messages with the message and messages Tags

Using Localized Data

Loading a Resource Bundle

Referencing Localized Static Data

Referencing Error Messages

Using the Standard Converters

Converting a Component's Value

Using DateTimeConverter

Using NumberConverter

Registering Listeners on Components

Registering a Value-Change Listener on a Component

Registering an Action Listener on a Component

Using the Standard Validators

Validating a Component's Value

Using the LongRangeValidator

Binding Component Values and Instances to External Data Sources

Binding a Component Value to a Property

Binding a Component Value to an Implicit Object

Binding a Component Instance to a Bean Property

Binding Converters, Listeners, and Validators to Backing Bean Properties

Referencing a Backing Bean Method

Referencing a Method That Performs Navigation

Referencing a Method That Handles an Action Event

Referencing a Method That Performs Validation

Referencing a Method That Handles a Value-change Event

Using Custom Objects

Using a Custom Converter

Using a Custom Validator

Using a Custom Component

Chapter 11:   Developing with JavaServer Faces Technology

Writing Bean Properties

Writing Properties Bound to Component Values

Writing Properties Bound to Component Instances

Writing Properties Bound to Converters, Listeners, or Validators

Performing Localization

Creating a Resource Bundle

Localizing Dynamic Data

Localizing Messages

Creating a Custom Converter

Implementing an Event Listener

Implementing Value-Change Listeners

Implementing Action Listeners

Creating a Custom Validator

Implementing the Validator Interface

Creating a Custom Tag

Writing Backing Bean Methods

Writing a Method to Handle Navigation

Writing a Method to Handle an Action Event

Writing a Method to Perform Validation

Writing a Method to Handle a Value-Change Event

Chapter 12:   Creating Custom UI Components

Determining Whether You Need a Custom Component or Renderer

When to Use a Custom Component

When to Use a Custom Renderer

Component, Renderer, and Tag Combinations

Understanding the Image Map Example

Why Use JavaServer Faces Technology to Implement an Image Map?

Understanding the Rendered HTML

Understanding the JSP Page

Configuring Model Data

Summary of the Application Classes

Steps for Creating a Custom Component

Creating Custom Component Classes

Specifying the Component Family

Performing Encoding

Performing Decoding

Enabling Component Properties to Accept Expressions

Saving and Restoring State

Delegating Rendering to a Renderer

Creating the Renderer Class

Identifying the Renderer Type

Handling Events for Custom Components

Creating the Component Tag Handler

Retrieving the Component Type

Setting Component Property Values

Providing the Renderer Type

Releasing Resources

Defining the Custom Component Tag in a Tag Library Descriptor

Chapter 13:   Configuring JavaServer Faces Applications

Application Configuration Resource File

Configuring Beans

Using the managed-bean Element

Initializing Properties using the managed-property Element

Initializing Maps and Lists

Registering Custom Error Messages

Registering Custom Localized Static Text

Registering a Custom Validator

Registering a Custom Converter

Configuring Navigation Rules

Registering a Custom Renderer with a Render Kit

Registering a Custom Component

Basic Requirements of a JavaServer Faces Application

Configuring an Application with a Deployment Descriptor

Including the Required JAR Files

Including the Classes, Pages, and Other Resources

Chapter 14:   Internationalizing and Localizing Web Applications

Java Platform Localization Classes

Providing Localized Messages and Labels

Establishing the Locale

Setting the Resource Bundle

Retrieving Localized Messages

Date and Number Formatting

Character Sets and Encodings

Character Sets

Character Encoding

Further Information

Part Two: Web Services    

Chapter 15:   Building Web Services with JAX-WS

Setting the Port

Creating a Simple Web Service and Client with JAX-WS

Requirements of a JAX-WS Endpoint

Coding the Service Endpoint Implementation Class

Building and Packaging the Service

Deploying the Service

A Simple JAX-WS Client

Types Supported by JAX-WS

Web Services Interoperability and JAX-WS

Further Information

Chapter 16:   Binding between XML Schema and Java Classes

JAXB Architecture

Architectural Overview

The JAXB Binding Process

More About Unmarshalling

More About Marshalling

More About Validation

Representing XML Content

Java Representation of XML Schema

Binding XML Schemas

Simple Type Definitions

Default Data Type Bindings

Customizing JAXB Bindings

Schema-to-Java

Java-to-Schema

Examples

General Usage Instructions

Description

Using the Examples

Configuring and Running the Samples

JAXB Compiler Options

JAXB Schema Generator Options

About the Schema-to-Java Bindings

Schema-Derived JAXB Classes

Basic Examples

Modify Marshal Example

Unmarshal Validate Example

Customizing JAXB Bindings

Why Customize?

Customization Overview

Customize Inline Example

Datatype Converter Example

External Customize Example

Java-toSchema Examples

j2s-create-marshal Example

j2s-xmlAccessorOrder Example

j2s-xmlAdapter-field Example

j2s-xmlAttribute-field Example

j2s-xmlRootElement Example

j2s-xmlSchemaType-class Example

j2s-xmlType Example

Chapter 17:   Streaming API for XML

Why StAX?

Streaming Versus DOM

Pull Parsing Versus Push Parsing

StAX Use Cases

Comparing StAX to Other JAXP APIs

StAX API

Cursor API

Iterator API

Choosing Between Cursor and Iterator APIs

Using StAX

StAX Factory Classes

Resources, Namespaces, and Errors

Reading XML Streams

Writing XML Streams

Sun's Streaming Parser Implementation

Reporting CDATA Events

SJSXP Factories Implementation

Sample Code

Sample Code Organization

Configuring Your Environment for Running the Samples

Running the Samples

Sample XML Document

cursor Sample - CursorParse.java

cursor2event Sample - CursorApproachEventObject.java

event Sample - EventParse.java

filter Sample - MyStreamFilter.java

readnwrite Sample - EventProducerConsumer.java

writer Sample - CursorWriter.java

Further Information

Chapter 18:   SOAP with Attachments API for Java

Overview of SAAJ

Messages

Connections

Tutorial

Creating and Sending a Simple Message

Adding Content to the Header

Adding Content to the SOAPPart Object

Adding a Document to the SOAP Body

Manipulating Message Content Using SAAJ or DOM APIs

Adding Attachments

Adding Attributes

Using SOAP Faults

Code Examples

Request.java

MyUddiPing.java

HeaderExample.java

DOMExample.java and DOMSrcExample.java

Attachments.java

SOAPFaultTest.java

Further Information

Chapter 19:   Java API for XML Registries

Overview of JAXR

What Is a Registry?

What Is JAXR?

JAXR Architecture

Implementing a JAXR Client

Establishing a Connection

Querying a Registry

Managing Registry Data

Using Taxonomies in JAXR Clients

Running the Client Examples

Before You Compile the Examples

Compiling the Examples

Running the Examples

Using JAXR Clients in Java EE Applications

Coding the Application Client: MyAppClient.java

Coding the PubQuery Session Bean

Editing the Properties File

Starting the Application Server

Creating JAXR Resources

Compiling the Source Files and Packaging the Application

Deploying the Application

Running the Application Client

Further Information

Part Three: Enterprise Beans    

Chapter 20:   Enterprise Beans

What Is an Enterprise Bean?

Benefits of Enterprise Beans

When to Use Enterprise Beans

Types of Enterprise Beans

What Is a Session Bean?

State Management Modes

When to Use Session Beans

What Is a Message-Driven Bean?

What Makes Message-Driven Beans Different from Session Beans?

When to Use Message-Driven Beans

Defining Client Access with Interfaces

Remote Clients

Local Clients

Deciding on Remote or Local Access

Web Service Clients

Method Parameters and Access

The Contents of an Enterprise Bean

Naming Conventions for Enterprise Beans

The Life Cycles of Enterprise Beans

The Life Cycle of a Stateful Session Bean

The Life Cycle of a Stateless Session Bean

The Life Cycle of a Message-Driven Bean

Further Information

Chapter 21:   Getting Started with Enterprise Beans

Creating the Enterprise Bean

Coding the Enterprise Bean

Compiling and Packaging converter

Creating the Application Client

Coding the Application Client

Compiling the Application Client

Creating the Web Client

Coding the Web Client

Compiling the Web Client

Deploying the Java EE Application

Running the Application Client

Running the Web Client

Modifying the Java EE Application

Modifying a Class File

Chapter 22:   Session Bean Examples

The cart Example

Session Bean Class

The Remove Method

Helper Classes

Building and Packaging the CartBean Example

Undeploying cart

A Web Service Example: HelloServiceBean

The Web Service Endpoint Implementation Class

Stateless Session Bean Implementation Class

Building and Packaging helloservice

Deploying helloservice

Using the Timer Service

The Timeout Method

Creating Timers

Canceling and Saving Timers

Getting Timer Information

Transactions and Timers

The timersession Example

Building and Packaging timersession

Deploying timersession

Handling Exceptions

Chapter 23:   A Message-Driven Bean Example

Example Application Overview

The Application Client

The Message-Driven Bean Class

The onMessage Method

Packaging, Deploying, and Running SimpleMessage

Creating the Administered Objects

Creating and Packaging the Application

Deploying the Application

Running the Client

Removing the Administered Objects

Creating Deployment Descriptors for Message-Driven Beans

Part Four: Persistence    

Chapter 24:   Introduction to the Java Persistence API

Entities

Requirements for Entity Classes

Persistent Fields and Properties in Entity Classes

Primary Keys in Entities

Multiplicity in Entity Relationships

Direction in Entity Relationships

Managing Entities

The Persistence Context

The EntityManager

Persistence Units

Chapter 25:   Persistence in the Web Tier

Accessing Databases from Web Applications

Populating the Example Database

Creating a Data Source in the Application Server

Defining the Persistence Unit

Creating an Entity Class

Obtaining Access to an Entity Manager

Accessing Data From the Database

Updating Data in the Database

Chapter 26:   Persistence in the EJB Tier

Overview of the order Application

Entity Relationships in order

Primary Keys in order

Entity Mapped to More Than One Database Table

Cascade Operations in order

BLOB and CLOB Database Types in order

Temporal Types in order

Managing order's Entities

Building and Running order

Creating the Database Tables

Building and Packaging the Application

Deploying the Application

Running the Application

Undeploying order

The roster Application

Relationships in the roster Application

Automatic Table Generation in roster

Building and Running roster

Building and Packaging the roster Application

Deploying the Application

Running the Application

Undeploying order

Chapter 27:   The Java Persistence Query Language

Terminology

Simplified Syntax

Select Statements

Update and Delete Statements

Example Queries

Simple Queries

Queries That Navigate to Related Entities

Queries with Other Conditional Expressions

Bulk Updates and Deletes

Full Syntax

BNF Symbols

BNF Grammar of the Java Persistence Query Language

FROM Clause

Path Expressions

WHERE Clause

SELECT Clause

ORDER BY Clause

The GROUP BY Clause

Part Five: Services    

Chapter 28:   Introduction to Security in Java EE

Overview

A Simple Example

Security Functions

Characteristics of Application Security

Security Implementation Mechanisms

Java SE Security Implementation Mechanisms

Java EE Security Implementation Mechanisms

Securing Containers

Using Deployment Descriptors for Declarative Security

Using Annotations

Using Programmatic Security

Securing the Application Server

Working with Realms, Users, Groups, and Roles

What is a Realm, User, Group, and Role?

Managing Users and Groups on the Application Server

Setting Up Security Roles

Mapping Roles to Users and Groups

Establishing a Secure Connection Using SSL

Installing and Configuring SSL Support

Specifying a Secure Connection in Your Application Deployment Descriptor

Verifying SSL Support

Working with Digital Certificates

Enabling Mutual Authentication over SSL

Further Information

Chapter 29:   Securing Java EE Applications

Securing Enterprise Beans

Accessing an Enterprise Bean Caller's Security Context

Declaring Security Role Names Referenced from Enterprise Bean Code

Defining a Security View of Enterprise Beans

Using Enterprise Bean Security Annotations

Using Enterprise Bean Security Deployment Descriptor Elements

Configuring IOR Security

Deploying Secure Enterprise Beans

Enterprise Bean Example Applications

Example: Securing an Enterprise Bean

Example: Using isCallerInRole and getCallerPrincipal

Discussion: Securing the Duke's Bank Example

Securing Application Clients

Using Login Modules

Using Programmatic Login

Securing EIS Applications

Container-Managed Sign-On

Component-Managed Sign-On

Configuring Resource Adapter Security

Mapping an Application Principal to EIS Principals

Example Applications in the Application Server

Further Information

Chapter 30:   Securing Web Applications

Overview

Working with Security Roles

Declaring Security Roles

Mapping Security Roles to Application Server Groups

Checking Caller Identity Programmatically

Declaring and Linking Role References

Defining Security Requirements for Web Applications

Declaring Security Requirements Using Annotations

Declaring Security Requirements in a Deployment Descriptor

Specifying a Secure Connection

Specifying an Authentication Mechanism

Examples: Securing Web Applications

Example: Using Form-Based Authentication with a JSP page

Example: Basic Authentication with a Servlet

Example: Basic Authentication with JAX-WS

Further Information

Chapter 31:   Securing Web Services

Securing Web Service Endpoints

Overview of Message Security

Advantages of Message Security

Message Security Mechanisms

Web Services Security Initiatives and Organizations

W3C Specifications

OASIS Specifications

JCP Specifications

WS-I Specifications

Using Message Security with Java EE

Using the Application Server Message Security Implementation

Using the Java WSDP XWSS Security Implementation

Further Information

Chapter 32:   The Java Message Service API

Overview

What Is Messaging?

What Is the JMS API?

When Can You Use the JMS API?

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

Basic JMS API Concepts

JMS API Architecture

Messaging Domains

Message Consumption

The JMS API Programming Model

Administered Objects

Connections

Sessions

Message Producers

Message Consumers

Messages

Queue Browsers

Exception Handling

Writing Simple JMS Client Applications

A Simple Example of Synchronous Message Receives

A Simple Example of Asynchronous Message Consumption

A Simple Example of Browsing Messages in a Queue

Running JMS Client Programs on Multiple Systems

Creating Robust JMS Applications

Using Basic Reliability Mechanisms

Using Advanced Reliability Mechanisms

Using the JMS API in a Java EE Application

Using @Resource Annotations in Java EE Components

Using Session Beans to Produce and to Synchronously Receive Messages

Using Message-Driven Beans

Managing Distributed Transactions

Using the JMS API with Application Clients and Web Components

Further Information

Chapter 33:   Java EE Examples Using the JMS API

A Java EE Application That Uses the JMS API with a Session Bean

Writing the Application Components

Creating and Packaging the Application

Deploying the Application

Running the Application Client

A Java EE Application That Uses the JMS API with an Entity

Overview of the Human Resources Application

Writing the Application Components

Creating and Packaging the Application

Deploying the Application

Running the Application Client

An Application Example That Consumes Messages from a Remote Java EE Server

Overview of the Modules

Writing the Components

Creating and Packaging the Modules

Deploying the EJB Module and Copying the Client

Running the Application Client

An Application Example That Deploys a Message-Driven Bean on Two Java EE Servers

Overview of the Modules

Writing the Module Components

Creating and Packaging the Modules

Deploying the Modules

Running the Application Client

Chapter 34:   Transactions

What Is a Transaction?

Container-Managed Transactions

Transaction Attributes

Rolling Back a Container-Managed Transaction

Synchronizing a Session Bean's Instance Variables

Methods Not Allowed in Container-Managed Transactions

Bean-Managed Transactions

JTA Transactions

Returning without Committing

Methods Not Allowed in Bean-Managed Transactions

Transaction Timeouts

Updating Multiple Databases

Transactions in Web Components

Chapter 35:   Resource Connections

Resources and JNDI Naming

DataSource Objects and Connection Pools

Resource Injection

Field-Based Injection

Method-Based Injection

Class-Based Injection

The confirmer Example Application

Running the confirmer Example Application

Further Information

Chapter 36:   Connector Architecture

About Resource Adapters

Resource Adapter Contracts

Management Contracts

Outbound Contracts

Inbound Contracts

Common Client Interface

Further Information

Part Six: Case Studies    

Chapter 37:   The Coffee Break Application

Common Code

JAX-WS Coffee Supplier Service

Service Implementation

SAAJ Coffee Supplier Service

SAAJ Client

SAAJ Service

Coffee Break Server

JSP Pages

JavaBeans Components

RetailPriceListServlet

Resource Configuration

Building, Packaging, Deploying, and Running the Application

Setting the Port

Building the Common Classes

Building, Packaging, and Deploying the JAX-WS Service

Building, Packaging, and Deploying the SAAJ Service

Building, Packaging, and Deploying the Coffee Break Server

Running the Coffee Break Client

Removing the Coffee Break Application

Chapter 38:   The Duke's Bank Application

Enterprise Beans

Session Beans

Java Persistence Entities

Helper Classes

Database Tables

Protecting the Enterprise Beans

Application Client

The Classes and Their Relationships

BankAdmin Class

Web Client

Design Strategies

Client Components

Request Processing

Protecting the Web Client Resources

Building, Packaging, Deploying, and Running the Application

Setting Up the Servers

Building the Duke's Bank Application

Running the Clients

Running the Application Client

Running the Web Client

Appendix A:   Java Encoding Schemes

Further Information

About the Authors

Current Writers

Index