The Java EE 6 Tutorial
Oracle Corporation
The Java EE 6 Tutorial
Free
Description
Contents
Reviews
Language
English
ISBN
Unknown
The Java EE 6 Tutorial
Preface
Before You Read This Book
Related Documentation
Typographic Conventions
Default Paths and File Names
Third-Party Web Site References
Introduction
Overview
Java EE 6 Platform Highlights
Java EE Application Model
Distributed Multitiered Applications
Security
Java EE Components
Java EE Clients
Web Clients
Application Clients
Applets
The JavaBeans Component Architecture
Java EE Server Communications
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
Java EE Application Assembly and Deployment
Packaging Applications
Development Roles
Java EE Product Provider
Tool Provider
Application Component Provider
Enterprise Bean Developer
Web Component Developer
Application Client Developer
Application Assembler
Application Deployer and Administrator
Java EE 6 APIs
Enterprise JavaBeans Technology
Java Servlet Technology
JavaServer Faces Technology
JavaServer Pages Technology
JavaServer Pages Standard Tag Library
Java Persistence API
Java Transaction API
Java API for RESTful Web Services
Managed Beans
Contexts and Dependency Injection for the Java EE Platform (JSR 299)
Dependency Injection for Java (JSR 330)
Bean Validation
Java Message Service API
Java EE Connector Architecture
JavaMail API
Java Authorization Contract for Containers
Java Authentication Service Provider Interface for Containers
Java EE 6 APIs in the Java Platform, Standard Edition 6 and 7
Java Database Connectivity API
Java Naming and Directory Interface API
JavaBeans Activation Framework
Java API for XML Processing
Java Architecture for XML Binding
SOAP with Attachments API for Java
Java API for XML Web Services
Java Authentication and Authorization Service
GlassFish Server Tools
Using the Tutorial Examples
Required Software
Java Platform, Standard Edition
Java EE 6 Software Development Kit
SDK Installation Tips
Java EE 6 Tutorial Component
To Obtain the Tutorial Component Using the Update Tool
NetBeans IDE
To Install NetBeans IDE without GlassFish Server
To Add GlassFish Server as a Server in NetBeans IDE
Apache Ant
To Obtain Apache Ant
Starting and Stopping the GlassFish Server
To Start the GlassFish Server Using NetBeans IDE
Starting the Administration Console
To Start the Administration Console Using NetBeans IDE
Starting and Stopping the Java DB Server
To Start the Database Server Using NetBeans IDE
Building the Examples
Tutorial Example Directory Structure
Getting the Latest Updates to the Tutorial
To Update the Tutorial through the Update Center
Debugging Java EE Applications
Using the Server Log
To Use the Administration Console Log Viewer
Using a Debugger
To Debug an Application Using a Debugger
The Web Tier
Getting Started with Web Applications
Web Applications
Web Application Lifecycle
Web Modules: The hello1 Example
Examining the hello1 Web Module
To View the hello1 Web Module Using NetBeans IDE
Introduction to Scopes
Packaging a Web Module
To Set the Context Root
To Build and Package the hello1 Web Module Using NetBeans IDE
To Build and Package the hello1 Web Module Using Ant
Deploying a Web Module
To Deploy the hello1 Web Module Using NetBeans IDE
To Deploy the hello1 Web Module Using Ant
Running a Deployed Web Module
To Run a Deployed Web Module
Listing Deployed Web Modules
To List Deployed Web Modules Using the Administration Console
To List Deployed Web Modules Using the asadmin Command
Updating a Web Module
To Update a Deployed Web Module
Dynamic Reloading
To Disable or Modify Dynamic Reloading
Undeploying Web Modules
To Undeploy the hello1 Web Module Using NetBeans IDE
To Undeploy the hello1 Web Module Using Ant
Configuring Web Applications: The hello2 Example
Mapping URLs to Web Components
Examining the hello2 Web Module
To View the hello2 Web Module Using NetBeans IDE
Running the hello2 Example
To Run the hello2 Example Using NetBeans IDE
To Run the hello2 Example Using Ant
Declaring Welcome Files
Setting Context Parameters
To Add a Context Parameter Using NetBeans IDE
To Create a web.xml File Using NetBeans IDE
Mapping Errors to Error Screens
To Set Up Error Mapping Using NetBeans IDE
Declaring Resource References
Declaring a Reference to a Resource
Declaring a Reference to a Web Service
Further Information about Web Applications
JavaServer Faces Technology
What Is a JavaServer Faces Application?
JavaServer Faces Technology Benefits
Creating a Simple JavaServer Faces Application
Developing the Managed Bean
Creating the Web Page
Mapping the FacesServlet Instance
The Lifecycle of the hello Application
Running the hello Application
To Run the hello Application in NetBeans IDE
To Run the hello Example Using Ant
Further Information about JavaServer Faces Technology
Introduction to Facelets
What Is Facelets?
Developing a Simple Facelets Application
Creating a Facelets Application
Developing a Managed Bean
Creating Facelets Views
Configuring the Application
Running the guessnumber Facelets Example
To Build, Package, and Deploy the guessnumber Example Using NetBeans IDE
To Build, Package, and Deploy the guessnumber Example Using Ant
To Run the guessnumber Example
Using Facelets Templates
Composite Components
Web Resources
Expression Language
Overview of the EL
Immediate and Deferred Evaluation Syntax
Immediate Evaluation
Deferred Evaluation
Value and Method Expressions
Value Expressions
Referencing Objects Using Value Expressions
Referring to Object Properties Using Value Expressions
Where Value Expressions Can Be Used
Method Expressions
Parameterized Method Calls
Defining a Tag Attribute Type
Literal Expressions
Operators
Reserved Words
Examples of EL Expressions
Using JavaServer Faces Technology in Web Pages
Setting Up a Page
Adding Components to a Page Using HTML Tags
Common Component Tag Attributes
The id Attribute
The immediate Attribute
The rendered Attribute
The style and styleClass Attributes
The value and binding Attributes
Adding HTML Head and Body Tags
Adding a Form Component
Using Text Components
Rendering a Text Field with the h:inputText Tag
Rendering a Password Field with the h:inputSecret Tag
Rendering a Label with the h:outputLabel Tag
Rendering a Hyperlink with the h:outputLink Tag
Displaying a Formatted Message with the h:outputFormat Tag
Using Command Component Tags for Performing Actions and Navigation
Rendering a Button with the h:commandButton Tag
Rendering a Hyperlink with the h:commandLink Tag
Adding Graphics and Images with the h:graphicImage Tag
Laying Out Components with the h:panelGrid and h:panelGroup Tags
Displaying Components for Selecting One Value
Displaying a Check Box Using the h:selectBooleanCheckbox Tag
Displaying a Menu Using the h:selectOneMenu Tag
Displaying Components for Selecting Multiple Values
Using the f:selectItem and f:selectItems Tags
Using the f:selectItems Tag
Using the f:selectItem Tag
Displaying the Results from Selection Components
Using Data-Bound Table Components
Displaying Error Messages with the h:message and h:messages Tags
Creating Bookmarkable URLs with the h:button and h:link Tags
Using View Parameters to Configure Bookmarkable URLs
The bookmarks Example Application
Building, Packaging, Deploying, and Running the bookmarks Example
To Build, Package, and Deploy the bookmarks Example Using NetBeans IDE
To Build, Package, and Deploy the bookmarks Example Using Ant
To Run the bookmarks Example
Resource Relocation Using h:outputScript and h:outputStylesheet Tags
Using Core Tags
Using Converters, Listeners, and Validators
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 LongRangeValidator
Referencing a Managed 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
Developing with JavaServer Faces Technology
Managed Beans in JavaServer Faces Technology
Creating a Managed Bean
Using the EL to Reference Managed Beans
Writing Bean Properties
Writing Properties Bound to Component Values
UIInput and UIOutput Properties
UIData Properties
UISelectBoolean Properties
UISelectMany Properties
UISelectOne Properties
UISelectItem Properties
UISelectItems Properties
Writing Properties Bound to Component Instances
Writing Properties Bound to Converters, Listeners, or Validators
Writing Managed 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
Using Bean Validation
Validating Null and Empty Strings
JavaServer Faces Technology: Advanced Concepts
The Lifecycle of a JavaServer Faces Application
Overview of the JavaServer Faces Lifecycle
Restore View Phase
Apply Request Values Phase
Process Validations Phase
Update Model Values Phase
Invoke Application Phase
Render Response Phase
Partial Processing and Partial Rendering
The Lifecycle of a Facelets Application
User Interface Component Model
User Interface Component Classes
Component Rendering Model
Conversion Model
Event and Listener Model
Validation Model
Navigation Model
Using Ajax with JavaServer Faces Technology
Overview of Ajax
Using Ajax Functionality with JavaServer Faces Technology
Using Ajax with Facelets
Using the f:ajax Tag
Sending an Ajax Request
Using the event Attribute
Using the execute Attribute
Using the immediate Attribute
Using the listener Attribute
Monitoring Events on the Client
Handling Errors
Receiving an Ajax Response
Ajax Request Lifecycle
Grouping of Components
Loading JavaScript as a Resource
Using JavaScript API in a Facelets Application
Using the @ResourceDependency Annotation in a Bean Class
The ajaxguessnumber Example Application
The ajaxguessnumber Source Files
The ajaxgreeting.xhtml Facelets Page
The ui.js JavaScript File
The UserNumberBean Managed Bean
Running the ajaxguessnumber Example
To Build, Package, and Deploy the ajaxguessnumber Example Using NetBeans IDE
To Build, Package, and Deploy the ajaxguessnumber Example Using Ant
To Run the ajaxguessnumber Example
Further Information about Ajax in JavaServer Faces Technology
Composite Components: Advanced Topics and Example
Attributes of a Composite Component
Invoking a Managed Bean
Validating Composite Component Values
The compositecomponentlogin Example Application
The Composite Component File
The Using Page
The Managed Bean
Running the compositecomponentlogin Example
To Build, Package, and Deploy the compositecomponentlogin Example Using NetBeans IDE
To Build, Package, and Deploy the compositecomponentlogin Example Using Ant
To Run the compositecomponentlogin Example
Creating Custom UI Components and Other Custom Objects
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 Facelets Page
Configuring Model Data
Summary of the Image Map 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
Implementing an Event Listener
Implementing Value-Change Listeners
Implementing Action Listeners
Handling Events for Custom Components
Defining the Custom Component Tag in a Tag Library Descriptor
Using a Custom Component
Creating and Using a Custom Converter
Creating a Custom Converter
Using a Custom Converter
Creating and Using a Custom Validator
Implementing the Validator Interface
Specifying a Custom Tag
Using a Custom Validator
Binding Component Values and Instances to Managed Bean Properties
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 Managed Bean Properties
Configuring JavaServer Faces Applications
Using Annotations to Configure Managed Beans
Using Managed Bean Scopes
Eager Application-Scoped Beans
Application Configuration Resource File
Ordering of Application Configuration Resource Files
Configuring Managed Beans
Using the managed-bean Element
Initializing Properties Using the managed-property Element
Referencing a Java Enum Type
Referencing a Context Initialization Parameter
Initializing Map Properties
Initializing Array and List Properties
Initializing Managed Bean Properties
Initializing Maps and Lists
Registering Application Messages
Using FacesMessage to Create a Message
Referencing Error Messages
Using Default Validators
Registering a Custom Validator
Registering a Custom Converter
Configuring Navigation Rules
To Configure a Navigation Rule
Implicit 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 Web Deployment Descriptor
Identifying the Servlet for Lifecycle Processing
To Specify a Path to an Application Configuration Resource File
To Specify Where State Is Saved
Configuring Project Stage
Including the Classes, Pages, and Other Resources
Java Servlet Technology
What Is a Servlet?
Servlet Lifecycle
Handling Servlet Lifecycle Events
Defining the Listener Class
Handling Servlet Errors
Sharing Information
Using Scope Objects
Controlling Concurrent Access to Shared Resources
Creating and 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
To Specify Filter Mappings Using NetBeans IDE
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
To Set the Timeout Period Using NetBeans IDE
Session Tracking
Finalizing a Servlet
Tracking Service Requests
Notifying Methods to Shut Down
Creating Polite Long-Running Methods
The mood Example Application
Components of the mood Example Application
Running the mood Example
To Run the mood Example Using NetBeans IDE
To Run the mood Example Using Ant
Further Information about Java Servlet Technology
Uploading Files with Java Servlet Technology
The @MultipartConfig Annotation
The getParts and getPart Methods
The fileupload Example Application
Architecture of the fileupload Example Application
Running the fileupload Example
To Build, Package, and Deploy the fileupload Example Using NetBeans IDE
To Build, Package, and Deploy the fileupload Example Using Ant
To Run the fileupload Example
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
Web Services
Introduction to Web Services
What Are Web Services?
Types of Web Services
“Big” Web Services
RESTful Web Services
Deciding Which Type of Web Service to Use
Building Web Services with JAX-WS
Creating a Simple Web Service and Clients with JAX-WS
Requirements of a JAX-WS Endpoint
Coding the Service Endpoint Implementation Class
Building, Packaging, and Deploying the Service
To Build, Package, and Deploy the Service Using NetBeans IDE
To Build, Package, and Deploy the Service Using Ant
Testing the Methods of a Web Service Endpoint
To Test the Service without a Client
A Simple JAX-WS Application Client
Coding the Application Client
Running the Application Client
To Run the Application Client Using NetBeans IDE
To Run the Application Client Using Ant
A Simple JAX-WS Web Client
Coding the Servlet
Running the Web Client
To Run the Web Client Using NetBeans IDE
To Run the Web Client Using Ant
Types Supported by JAX-WS
Schema-to-Java Mapping
Java-to-Schema Mapping
Web Services Interoperability and JAX-WS
Further Information about JAX-WS
Building RESTful Web Services with JAX-RS
What Are RESTful Web Services?
Creating a RESTful Root Resource Class
Developing RESTful Web Services with JAX-RS
Overview of a JAX-RS Application
The @Path Annotation and URI Path Templates
Responding to HTTP Methods and Requests
The Request Method Designator Annotations
Using Entity Providers to Map HTTP Response and Request Entity Bodies
Using @Consumes and @Produces to Customize Requests and Responses
The @Produces Annotation
The @Consumes Annotation
Extracting Request Parameters
Example Applications for JAX-RS
A RESTful Web Service
To Create a RESTful Web Service Using NetBeans IDE
The rsvp Example Application
Components of the rsvp Example Application
Running the rsvp Example Application
To Run the rsvp Example Application in NetBeans IDE
To Run the rsvp Example Application Using Ant
Real-World Examples
Further Information about JAX-RS
JAX-RS: Advanced Topics and Example
Annotations for Field and Bean Properties of Resource Classes
Extracting Path Parameters
Extracting Query Parameters
Extracting Form Data
Extracting the Java Type of a Request or Response
Subresources and Runtime Resource Resolution
Subresource Methods
Subresource Locators
Integrating JAX-RS with EJB Technology and CDI
Conditional HTTP Requests
Runtime Content Negotiation
Using JAX-RS With JAXB
Using Java Objects to Model Your Data
Starting from an Existing XML Schema Definition
Using JSON with JAX-RS and JAXB
The customer Example Application
Overview of the customer Example Application
The Customer and Address Entity Classes
The CustomerService Class
The CustomerClientXML and CustomerClientJSON Classes
Modifying the Example to Generate Entity Classes from an Existing Schema
To Modify the customer Example to Generate Java Entity Classes from an Existing XML Schema Definition
Running the customer Example
To Build, Package, and Deploy the customer Example Using NetBeans IDE
To Build, Package, and Deploy the customer Example Using Ant
To Run the customer Example Using the Jersey Client
To Run the customer Example Using the Web Services Tester
Using Curl to Run the customer Example Application
Enterprise Beans
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?
Types of Session Beans
Stateful Session Beans
Stateless Session Beans
Singleton Session Beans
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
Accessing Enterprise Beans
Using Enterprise Beans in Clients
Portable JNDI Syntax
Deciding on Remote or Local Access
Local Clients
Accessing Local Enterprise Beans Using the No-Interface View
Accessing Local Enterprise Beans That Implement Business Interfaces
Remote Clients
Web Service Clients
Method Parameters and Access
Isolation
Granularity of Accessed Data
The Contents of an Enterprise Bean
Packaging Enterprise Beans in EJB JAR Modules
Packaging Enterprise Beans in WAR Modules
Naming Conventions for Enterprise Beans
The Lifecycles of Enterprise Beans
The Lifecycle of a Stateful Session Bean
The Lifecycle of a Stateless Session Bean
The Lifecycle of a Singleton Session Bean
The Lifecycle of a Message-Driven Bean
Further Information about Enterprise Beans
Getting Started with Enterprise Beans
Creating the Enterprise Bean
Coding the Enterprise Bean Class
Creating the converter Web Client
Running the converter Example
To Build, Package, and Deploy the converter Example in NetBeans IDE
To Build, Package, and Deploy the converter Example Using Ant
To Run the converter Example
Modifying the Java EE Application
To Modify a Class File
Running the Enterprise Bean Examples
The cart Example
The Business Interface
Session Bean Class
Lifecycle Callback Methods
Business Methods
The @Remove Method
Helper Classes
Running the cart Example
To Run the cart Example Using NetBeans IDE
To Run the cart Example Using Ant
The all Task
A Singleton Session Bean Example: counter
Creating a Singleton Session Bean
Initializing Singleton Session Beans
Managing Concurrent Access in a Singleton Session Bean
Container-Managed Concurrency
Bean-Managed Concurrency
Handling Errors in a Singleton Session Bean
The Architecture of the counter Example
Running the counter Example
To Run the counter Example Using NetBeans IDE
To Run the counter Example Using Ant
A Web Service Example: helloservice
The Web Service Endpoint Implementation Class
Stateless Session Bean Implementation Class
Running the helloservice Example
To Build, Package, and Deploy the helloservice Example Using NetBeans IDE
To Build, Package, and Deploy the helloservice Example Using Ant
To Test the Service without a Client
Using the Timer Service
Creating Calendar-Based Timer Expressions
Specifying Multiple Values in Calendar Expressions
Using Wildcards in Calendar Expressions
Specifying a List of Values
Specifying a Range of Values
Specifying Intervals
Programmatic Timers
The @Timeout Method
Creating Programmatic Timers
Automatic Timers
Canceling and Saving Timers
Getting Timer Information
Transactions and Timers
The timersession Example
Running the timersession Example
To Run the timersession Example Using NetBeans IDE
To Build, Package, and Deploy the timersession Example Using Ant
To Run the Web Client
Handling Exceptions
A Message-Driven Bean Example
Overview of the simplemessage Example
The simplemessage Application Client
The Message-Driven Bean Class
The onMessage Method
Running the simplemessage Example
Administered Objects for the simplemessage Example
To Run the simplemessage Application Using NetBeans IDE
To Run the simplemessage Application Using Ant
Removing the Administered Objects for the simplemessage Example
Using the Embedded Enterprise Bean Container
Overview of the Embedded Enterprise Bean Container
Developing Embeddable Enterprise Bean Applications
Running Embedded Applications
Creating the Enterprise Bean Container
Explicitly Specifying Enterprise Bean Modules to be Initialized
Looking Up Session Bean References
Shutting Down the Enterprise Bean Container
The standalone Example Application
To Run the standalone Example Application
Using Asynchronous Method Invocation in Session Beans
Asynchronous Method Invocation
Creating an Asynchronous Business Method
Calling Asynchronous Methods from Enterprise Bean Clients
Retrieving the Final Result from an Asynchronous Method Invocation
Cancelling an Asynchronous Method Invocation
Checking the Status of an Asynchronous Method Invocation
The async Example Application
Architecture of the async Example Application
Running the async Example
To Configure the Keystore and Truststore in GlassFish Server
To Run the async Example Using NetBeans IDE
To Run the async Example Using Ant
Contexts and Dependency Injection for the Java EE Platform
Introduction to Contexts and Dependency Injection for the Java EE Platform
Overview of CDI
About Beans
About CDI Managed Beans
Beans as Injectable Objects
Using Qualifiers
Injecting Beans
Using Scopes
Overriding the Scope of a Bean at the Point of Injection
Giving Beans EL Names
Adding Setter and Getter Methods
Using a Managed Bean in a Facelets Page
Injecting Objects by Using Producer Methods
Configuring a CDI Application
Using the @PostConstruct and @PreDestroy Annotations With CDI Managed Bean Classes
To Initialize a Managed Bean Using the @PostConstruct Annotation
To Prepare for the Destruction of a Managed Bean Using the @PreDestroy Annotation
Further Information about CDI
Running the Basic Contexts and Dependency Injection Examples
The simplegreeting CDI Example
The simplegreeting Source Files
The Facelets Template and Page
Configuration Files
Running the simplegreeting Example
To Build, Package, and Deploy the simplegreeting Example Using NetBeans IDE
To Build, Package, and Deploy the simplegreeting Example Using Ant
To Run the simplegreeting Example
The guessnumber CDI Example
The guessnumber Source Files
The @MaxNumber and @Random Qualifier Interfaces
The Generator Managed Bean
The UserNumberBean Managed Bean
The Facelets Page
Running the guessnumber Example
To Build, Package, and Deploy the guessnumber Example Using NetBeans IDE
To Build, Package, and Deploy the guessnumber Example Using Ant
To Run the guessnumber Example
Contexts and Dependency Injection for the Java EE Platform: Advanced Topics
Using Alternatives in CDI Applications
Using Specialization
Using Producer Methods, Producer Fields, and Disposer Methods in CDI Applications
Using Producer Methods
Using Producer Fields to Generate Resources
Using a Disposer Method
Using Predefined Beans in CDI Applications
Using Events in CDI Applications
Defining Events
Using Observer Methods to Handle Events
Firing Events
Using Interceptors in CDI Applications
Using Decorators in CDI Applications
Using Stereotypes in CDI Applications
Running the Advanced Contexts and Dependency Injection Examples
The encoder Example: Using Alternatives
The Coder Interface and Implementations
The encoder Facelets Page and Managed Bean
Running the encoder Example
To Build, Package, and Deploy the encoder Example Using NetBeans IDE
To Run the encoder Example Using NetBeans IDE
To Build, Package, and Deploy the encoder Example Using Ant
To Run the encoder Example Using Ant
The producermethods Example: Using a Producer Method To Choose a Bean Implementation
Components of the producermethods Example
Running the producermethods Example
To Build, Package, and Deploy the producermethods Example Using NetBeans IDE
To Build, Package, and Deploy the producermethods Example Using Ant
To Run the producermethods Example
The producerfields Example: Using Producer Fields to Generate Resources
The Producer Field for the producerfields Example
The producerfields Entity and Session Bean
The producerfields Facelets Pages and Managed Bean
Running the producerfields Example
To Build, Package, and Deploy the producerfields Example Using NetBeans IDE
To Build, Package, and Deploy the producerfields Example Using Ant
To Run the producerfields Example
The billpayment Example: Using Events and Interceptors
The PaymentEvent Event Class
The PaymentHandler Event Listener
The billpayment Facelets Pages and Managed Bean
The LoggedInterceptor Interceptor Class
Running the billpayment Example
To Build, Package, and Deploy the billpayment Example Using NetBeans IDE
To Build, Package, and Deploy the billpayment Example Using Ant
To Run the billpayment Example
The decorators Example: Decorating a Bean
Components of the decorators Example
Running the decorators Example
To Build, Package, and Deploy the decorators Example Using NetBeans IDE
To Build, Package, and Deploy the decorators Example Using Ant
To Run the decorators Example
Persistence
Introduction to the Java Persistence API
Entities
Requirements for Entity Classes
Persistent Fields and Properties in Entity Classes
Persistent Fields
Persistent Properties
Using Collections in Entity Fields and Properties
Validating Persistent Fields and Properties
Primary Keys in Entities
Multiplicity in Entity Relationships
Direction in Entity Relationships
Bidirectional Relationships
Unidirectional Relationships
Queries and Relationship Direction
Cascade Operations and Relationships
Orphan Removal in Relationships
Embeddable Classes in Entities
Entity Inheritance
Abstract Entities
Mapped Superclasses
Non-Entity Superclasses
Entity Inheritance Mapping Strategies
The Single Table per Class Hierarchy Strategy
The Table per Concrete Class Strategy
The Joined Subclass Strategy
Managing Entities
The EntityManager Interface
Container-Managed Entity Managers
Application-Managed Entity Managers
Finding Entities Using the EntityManager
Managing an Entity Instance’s Lifecycle
Persisting Entity Instances
Removing Entity Instances
Synchronizing Entity Data to the Database
Persistence Units
Querying Entities
Further Information about Persistence
Running the Persistence Examples
The order Application
Entity Relationships in the order Application
Self-Referential Relationships
One-to-One Relationships
One-to-Many Relationship Mapped to Overlapping Primary and Foreign Keys
Unidirectional Relationships
Primary Keys in the order Application
Generated Primary Keys
Compound Primary Keys
Entity Mapped to More Than One Database Table
Cascade Operations in the order Application
BLOB and CLOB Database Types in the order Application
Temporal Types in the order Application
Managing the order Application’s Entities
Creating Entities
Finding Entities
Setting Entity Relationships
Using Queries
Removing Entities
Running the order Example
To Run the order Example Using NetBeans IDE
To Run the order Example Using Ant
The all Task
The roster Application
Relationships in the roster Application
The Many-To-Many Relationship in roster
Entity Inheritance in the roster Application
Criteria Queries in the roster Application
Metamodel Classes in the roster Application
Obtaining a CriteriaBuilder Instance in RequestBean
Creating Criteria Queries in RequestBean’s Business Methods
Automatic Table Generation in the roster Application
Running the roster Example
To Run the roster Example Using NetBeans IDE
To Run the roster Example Using Ant
The all Task
The address-book Application
Bean Validation Constraints in address-book
Specifying Error Messages for Constraints in address-book
Validating Contact Input from a JavaServer Faces Application
Running the address-book Example
To Run the address-book Example Using NetBeans IDE
To Run the address-book Example Using Ant
The Java Persistence Query Language
Query Language Terminology
Creating Queries Using the Java Persistence Query Language
Named Parameters in Queries
Positional Parameters in Queries
Simplified Query Language Syntax
Select Statements
Update and Delete Statements
Example Queries
Simple Queries
A Basic Select Query
Eliminating Duplicate Values
Using Named Parameters
Queries That Navigate to Related Entities
A Simple Query with Relationships
Navigating to Single-Valued Relationship Fields
Traversing Relationships with an Input Parameter
Traversing Multiple Relationships
Navigating According to Related Fields
Queries with Other Conditional Expressions
The LIKE Expression
The IS NULL Expression
The IS EMPTY Expression
The BETWEEN Expression
Comparison Operators
Bulk Updates and Deletes
Update Queries
Delete Queries
Full Query Language Syntax
BNF Symbols
BNF Grammar of the Java Persistence Query Language
FROM Clause
Identifiers
Identification Variables
Range Variable Declarations
Collection Member Declarations
Joins
Path Expressions
Examples of Path Expressions
Expression Types
Navigation
WHERE Clause
Literals
Input Parameters
Conditional Expressions
Operators and Their Precedence
BETWEEN Expressions
IN Expressions
LIKE Expressions
NULL Comparison Expressions
Empty Collection Comparison Expressions
Collection Member Expressions
Subqueries
Functional Expressions
Case Expressions
NULL Values
Equality Semantics
SELECT Clause
Return Types
The DISTINCT Keyword
Constructor Expressions
ORDER BY Clause
GROUP BY and HAVING Clauses
Using the Criteria API to Create Queries
Overview of the Criteria and Metamodel APIs
Using the Metamodel API to Model Entity Classes
Using Metamodel Classes
Using the Criteria API and Metamodel API to Create Basic Typesafe Queries
Creating a Criteria Query
Query Roots
Querying Relationships Using Joins
Path Navigation in Criteria Queries
Restricting Criteria Query Results
The Expression Interface Methods
Expression Methods in the CriteriaBuilder Interface
Managing Criteria Query Results
Ordering Results
Grouping Results
Executing Queries
Single-Valued Query Results
Collection-Valued Query Results
Creating and Using String-Based Criteria Queries
Overview of String-Based Criteria API Queries
Creating String-Based Queries
Executing String-Based Queries
Controlling Concurrent Access to Entity Data with Locking
Overview of Entity Locking and Concurrency
Using Optimistic Locking
Lock Modes
Setting the Lock Mode
Using Pessimistic Locking
Pessimistic Locking Timeouts
Using a Second-Level Cache with Java Persistence API Applications
Overview of the Second-Level Cache
Controlling Whether Entities May Be Cached
Specifying the Cache Mode Settings to Improve Performance
Setting the Cache Retrieval and Store Modes
Cache Retrieval Mode
Cache Store Mode
Setting the Cache Retrieval or Store Mode
Controlling the Second-Level Cache Programmatically
Checking Whether an Entity’s Data Is Cached
Removing an Entity from the Cache
Removing All Data from the Cache
Security
Introduction to Security in the Java EE Platform
Overview of Java EE Security
A Simple Application Security Walkthrough
Step 1: Initial Request
Step 2: Initial Authentication
Step 3: URL Authorization
Step 4: Fulfilling the Original Request
Step 5: Invoking Enterprise Bean Business Methods
Features of a Security Mechanism
Characteristics of Application Security
Security Mechanisms
Java SE Security Mechanisms
Java EE Security Mechanisms
Application-Layer Security
Transport-Layer Security
Message-Layer Security
Securing Containers
Using Annotations to Specify Security Information
Using Deployment Descriptors for Declarative Security
Using Programmatic Security
Securing the GlassFish Server
Working with Realms, Users, Groups, and Roles
What Are Realms, Users, Groups, and Roles?
What Is a Realm?
What Is a User?
What Is a Group?
What Is a Role?
Some Other Terminology
Managing Users and Groups on the GlassFish Server
To Add Users to the GlassFish Server
Setting Up Security Roles
Mapping Roles to Users and Groups
Establishing a Secure Connection Using SSL
Verifying and Configuring SSL Support
Further Information about Security
Getting Started Securing Web Applications
Overview of Web Application Security
Securing Web Applications
Specifying Security Constraints
Specifying a Web Resource Collection
Specifying an Authorization Constraint
Specifying a Secure Connection
Specifying Security Constraints for Resources
Specifying Authentication Mechanisms
HTTP Basic Authentication
Form-Based Authentication
Digest Authentication
Specifying an Authentication Mechanism in the Deployment Descriptor
Declaring Security Roles
Using Programmatic Security with Web Applications
Authenticating Users Programmatically
Checking Caller Identity Programmatically
Example Code for Programmatic Security
Declaring and Linking Role References
Examples: Securing Web Applications
To Set Up Your System for Running the Security Examples
The hello2_basicauth Example: Basic Authentication with a Servlet
Specifying Security for Basic Authentication Using Annotations
To Build, Package, and Deploy the hello2_basicauth Example Using NetBeans IDE
To Build, Package, and Deploy the hello2_basicauth Example Using Ant
To Run the hello2_basicauth Example
The hello1_formauth Example: Form-Based Authentication with a JavaServer Faces Application
Creating the Login Form and the Error Page
Specifying Security for the Form-Based Authentication Example
To Build, Package, and Deploy the hello1_formauth Example Using NetBeans IDE
To Build, Package, and Deploy the hello1_formauth Example Using Ant
To Run the hello1_formauth Example
Getting Started Securing Enterprise Applications
Securing Enterprise Beans
Securing an Enterprise Bean Using Declarative Security
Specifying Authorized Users by Declaring Security Roles
Specifying an Authentication Mechanism and Secure Connection
Securing an Enterprise Bean Programmatically
Accessing an Enterprise Bean Caller’s Security Context
Propagating a Security Identity (Run-As)
Configuring a Component’s Propagated Security Identity
Trust between Containers
Deploying Secure Enterprise Beans
Examples: Securing Enterprise Beans
The cart-secure Example: Securing an Enterprise Bean with Declarative Security
Annotating the Bean
To Run the cart-secure Example Using NetBeans IDE
To Run the cart-secure Example Using Ant
The converter-secure Example: Securing an Enterprise Bean with Programmatic Security
Modifying ConverterBean
Modifying ConverterServlet
To Build, Package, and Deploy the converter-secure Example Using NetBeans IDE
To Build, Package, and Deploy the converter-secure Example Using Ant
To Run the converter-secure Example
Java EE Security: Advanced Topics
Working with Digital Certificates
Creating a Server Certificate
To Use keytool to Create a Server Certificate
Adding Users to the Certificate Realm
Using a Different Server Certificate with the GlassFish Server
To Specify a Different Server Certificate
Authentication Mechanisms
Client Authentication
Mutual Authentication
Enabling Mutual Authentication over SSL
Creating a Client Certificate for Mutual Authentication
To Create a Client Certificate and Keystore
Using Form-Based Login in JavaServer Faces Web Applications
Using j_security_check in JavaServer Faces Forms
Using a Managed Bean for Authentication in JavaServer Faces Applications
Using the JDBC Realm for User Authentication
To Configure a JDBC Authentication Realm
Securing HTTP Resources
Securing Application Clients
Using Login Modules
Using Programmatic Login
Securing Enterprise Information Systems Applications
Container-Managed Sign-On
Component-Managed Sign-On
Configuring Resource Adapter Security
To Map an Application Principal to EIS Principals
Configuring Security Using Deployment Descriptors
Specifying Security for Basic Authentication in the Deployment Descriptor
Specifying Non-Default Principal-to-Role Mapping in the Deployment Descriptor
Further Information about Security
Java EE Supporting Technologies
Introduction to Java EE Supporting Technologies
Transactions in Java EE Applications
Resources in Java EE Applications
The Java EE Connector Architecture and Resource Adapters
Java Database Connectivity Software
Java Message Service
Transactions
What Is a Transaction?
Container-Managed Transactions
Transaction Attributes
Required Attribute
RequiresNew Attribute
Mandatory Attribute
NotSupported Attribute
Supports Attribute
Never Attribute
Summary of Transaction Attributes
Setting 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
To Set a Transaction Timeout
Updating Multiple Databases
Transactions in Web Components
Further Information about Transactions
Resources and Resource Adapters
Resources and JNDI Naming
DataSource Objects and Connection Pools
Resource Injection
Field-Based Injection
Method-Based Injection
Class-Based Injection
Resource Adapters and Contracts
Management Contracts
Lifecycle Management
Work Management Contract
Generic Work Context Contract
Outbound and Inbound Contracts
Metadata Annotations
Common Client Interface
Using Resource Adapters With Contexts and Dependency Injection for the Java EE Platform (CDI)
Further Information about Resources
The Resource Adapter Example
The Resource Adapter
The Message-Driven Bean
The Web Application
Running the mailconnector Example
Before You Deploy the mailconnector Example
To Build, Package, and Deploy the mailconnector Example Using NetBeans IDE
To Build, Package, and Deploy the mailconnector Example Using Ant
To Run the mailconnector Example
Java Message Service Concepts
Overview of the JMS API
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
Point-to-Point Messaging Domain
Publish/Subscribe Messaging Domain
Programming with the Common Interfaces
Message Consumption
The JMS API Programming Model
JMS Administered Objects
JMS Connection Factories
JMS Destinations
JMS Connections
JMS Sessions
JMS Message Producers
JMS Message Consumers
JMS Message Listeners
JMS Message Selectors
JMS Messages
Message Headers
Message Properties
Message Bodies
JMS Queue Browsers
JMS Exception Handling
Creating Robust JMS Applications
Using Basic Reliability Mechanisms
Controlling Message Acknowledgment
Specifying Message Persistence
Setting Message Priority Levels
Allowing Messages to Expire
Creating Temporary Destinations
Using Advanced Reliability Mechanisms
Creating Durable Subscriptions
Using JMS API Local Transactions
Using the JMS API in Java EE Applications
Using @Resource Annotations in Enterprise Bean or Web Components
Using Session Beans to Produce and to Synchronously Receive Messages
Managing JMS Resources in Session Beans
Managing Transactions in Session Beans
Using Message-Driven Beans to Receive Messages Asynchronously
Managing Distributed Transactions
Using the JMS API with Application Clients and Web Components
Further Information about JMS
Java Message Service Examples
Writing Simple JMS Applications
A Simple Example of Synchronous Message Receives
Writing the Clients for the Synchronous Receive Example
Starting the JMS Provider
JMS Administered Objects for the Synchronous Receive Example
To Create JMS Resources Using NetBeans IDE
To Delete JMS Resources Using NetBeans IDE
Running the Clients for the Synchronous Receive Example
To Build and Package the Clients for the Synchronous Receive Example Using NetBeans IDE
To Deploy and Run the Clients for the Synchronous Receive Example Using NetBeans IDE
To Build and Package the Clients for the Synchronous Receive Example Using Ant
To Deploy and Run the Clients for the Synchronous Receive Example Using Ant and the appclient Command
A Simple Example of Asynchronous Message Consumption
Writing the Clients for the Asynchronous Receive Example
To Build and Package the AsynchConsumer Client Using NetBeans IDE
To Deploy and Run the Clients for the Asynchronous Receive Example Using NetBeans IDE
To Build and Package the AsynchConsumer Client Using Ant
To Deploy and Run the Clients for the Asynchronous Receive Example Using Ant and the appclient Command
A Simple Example of Browsing Messages in a Queue
Writing the Client for the QueueBrowser Example
To Run the MessageBrowser Client Using NetBeans IDE
To Run the MessageBrowser Client Using Ant and the appclient Command
Running JMS Clients on Multiple Systems
To Create Administered Objects for Multiple Systems
Changing the Default Host Name
To Change the Default Host Name Using the Administration Console
To Change the Default Host Name Using the asadmin Command
To Run the Clients Using NetBeans IDE
To Run the Clients Using Ant and the appclient Command
Undeploying and Cleaning the Simple JMS Examples
Writing Robust JMS Applications
A Message Acknowledgment Example
To Run ackequivexample Using NetBeans IDE
To Run ackequivexample Using Ant
A Durable Subscription Example
To Run durablesubscriberexample Using NetBeans IDE
To Run durablesubscriberexample Using Ant
A Local Transaction Example
To Run transactedexample Using NetBeans IDE
To Run transactedexample Using Ant and the appclient Command
An Application That Uses the JMS API with a Session Bean
Writing the Application Components for the clientsessionmdb Example
Coding the Application Client: MyAppClient.java
Coding the Publisher Session Bean
Coding the Message-Driven Bean: MessageBean.java
Creating Resources for the clientsessionmdb Example
Running the clientsessionmdb Example
To Run the clientsessionmdb Example Using NetBeans IDE
To Run the clientsessionmdb Example Using Ant
An Application That Uses the JMS API with an Entity
Overview of the clientmdbentity Example Application
Writing the Application Components for the clientmdbentity Example
Coding the Application Client: HumanResourceClient.java
Coding the Message-Driven Beans for the clientmdbentity Example
Coding the Entity Class for the clientmdbentity Example
Creating Resources for the clientmdbentity Example
Running the clientmdbentity Example
To Run the clientmdbentity Example Using NetBeans IDE
To Run the clientmdbentity Example Using Ant
An Application Example That Consumes Messages from a Remote Server
Overview of the consumeremote Example Modules
Writing the Module Components for the consumeremote Example
Creating Resources for the consumeremote Example
Using Two Application Servers for the consumeremote Example
Running the consumeremote Example
To Run the consumeremote Example Using NetBeans IDE
To Run the consumeremote Example Using Ant
An Application Example That Deploys a Message-Driven Bean on Two Servers
Overview of the sendremote Example Modules
Writing the Module Components for the sendremote Example
Coding the Application Client: MultiAppServerClient.java
Coding the Message-Driven Bean: ReplyMsgBean.java
Creating Resources for the sendremote Example
To Enable Deployment on the Remote System
To Use Two Application Servers for the sendremote Example
Running the sendremote Example
To Run the sendremote Example Using NetBeans IDE
To Run the sendremote Example Using Ant
To Disable Deployment on the Remote System
Bean Validation: Advanced Topics
Creating Custom Constraints
Using the Built-In Constraints to Make a New Constraint
Customizing Validator Messages
The ValidationMessages Resource Bundle
Localizing Validation Messages
Grouping Constraints
Customizing Group Validation Order
Using Java EE Interceptors
Overview of Interceptors
Interceptor Classes
Interceptor Lifecycle
Interceptors and CDI
Using Interceptors
Intercepting Method Invocations
Using Multiple Method Interceptors
Accessing Target Method Parameters From an Interceptor Class
Intercepting Lifecycle Callback Events
Using Multiple Lifecycle Callback Interceptors
Intercepting Timeout Events
Using Multiple Timeout Interceptors
The interceptor Example Application
Running the interceptor Example
To Run the interceptor Example Using NetBeans IDE
To Run the interceptor Example Using Ant
Case Studies
Duke’s Bookstore Case Study Example
Design and Architecture of Duke’s Bookstore
The Duke’s Bookstore Interface
The Book Java Persistence API Entity
Enterprise Beans Used in Duke’s Bookstore
Facelets Pages and Managed Beans Used in Duke’s Bookstore
Custom Components and Other Custom Objects Used in Duke’s Bookstore
Properties Files Used in Duke’s Bookstore
Deployment Descriptors Used in Duke’s Bookstore
Running the Duke’s Bookstore Case Study Application
To Build and Deploy Duke’s Bookstore Using NetBeans IDE
To Build and Deploy Duke’s Bookstore Using Ant
To Run Duke’s Bookstore
Duke’s Tutoring Case Study Example
Design and Architecture of Duke’s Tutoring
Main Interface
Java Persistence API Entities Used in the Main Interface
Enterprise Beans Used in the Main Interface
Facelets Files Used in the Main Interface
Helper Classes Used in the Main Interface
Properties Files
Deployment Descriptors Used in Duke’s Tutoring
Administration Interface
Enterprise Beans Used in the Administration Interface
Facelets Files Used in the Administration Interface
Running the Duke’s Tutoring Case Study Application
Setting Up GlassFish Server
To Create the JDBC Realm in GlassFish Server
Running Duke’s Tutoring
To Build and Deploy Duke’s Tutoring in NetBeans IDE
To Build and Deploy Duke’s Tutoring Using Ant
Using Duke’s Tutoring
To Use the Main Interface of Duke’s Tutoring
To Use the Administration Interface of Duke’s Tutoring
Duke’s Forest Case Study Example
Design and Architecture of Duke’s Forest
The events Project
The entities Project
The dukes-payment Project
The dukes-resources Project
The Duke’s Store Project
Enterprise Beans Used in Duke’s Store
Facelets Files Used in the Main Interface of Duke’s Store
Facelets Files Used in the Administration Interface of Duke’s Store
Managed Beans Used in Duke’s Store
Helper Classes Used in Duke’s Store
Qualifiers Used in Duke’s Store
Event Handlers Used in Duke’s Store
Properties Files Used in Duke’s Store
Deployment Descriptors Used in Duke’s Store
The Duke’s Shipment Project
Enterprise Bean Used in Duke’s Shipment
Facelets Files Used in Duke’s Shipment
Managed Beans Used in Duke’s Shipment
Helper Class Used in Duke’s Shipment
Qualifier Used in Duke’s Shipment
Properties Files Used in Duke’s Shipment
Deployment Descriptors Used in Duke’s Shipment
Building and Deploying the Duke’s Forest Case Study Application
Prerequisite Task
To Create the JDBC Realm and Populate the Database
To Build and Deploy the Duke’s Forest Application Using NetBeans IDE
To Build and Deploy the Duke’s Forest Application Using Ant
Running the Duke’s Forest Application
To Register as a Duke’s Store Customer
To Purchase Products
To Approve Shipment of a Product
To Create a New Product
Index
The book hasn't received reviews yet.