THE EXPERT'S VOICE®
STVole lalla eMC IRelURea
Cedric Buest witn
John Davies, Tyler Jewel, Rod Johnson, Andrew Longshaw,
Ramesh Nagappan, Dr P.G. Sarang, Alex Toussaint,
Sameer Tyagi, Gary Watson, Mark Wilcox, Alan Williamson,
Daniel O'Connor
J2EE 1.3 Edition
‘The J2EE container architecture and runtime services
Web component development with Serviets 2.3 and JavaServer Pages 1.2
Business logic components with EJB 2.0, including container-managed
persistence, EJB QL, and message-driven beans
Underlying J2EE technologies for distributed development — RMI, JDBC
and JNDI
Introduction to Web Services covering SOAP, SWA, WSDL,
and UDDI .
a!
*-
Apress*Table of Contents
Introduction _
‘What's Changed in this Edition of the Book?
Who is this Book For?
What's Covered in this Book
What You Need to Use this Book
Conventions
Customer Support
How to Download the Sample Code for the Book
Ecrata
E-mail Support
Wai Ne
he
Chapter 1: The J2EE Platform
Programming for the Enterprise
The Enterprise Today
Te Java the Answer?
‘atom Independence
Managed Objects
Rewsabily
Modularity
Enterprise Architecture Styles
‘Two-Tier Architecture
‘Three-Tier Architecture
neTicr Architecture
Enterprise Architecture
‘Component Costracts
‘Container ServiceAPis
RRREBE bebe breEke eoooes &Table of Contents
J2EE Technologies 28
‘Component Technologies 28
‘Web Components 29
nterise JavaBean Components 29
ML 20
Service Technologies 31
DEG. 4
‘wn Tensicion APLand 3
‘NDL uu
isaMai
The tor Acchist 2
1 2
Communication Technologies 32
Intent Brtocolt 2
‘Heme Object Protocols 33
Developing J2EE Applications 33
) Application Development and Deployment Roles 3
Application Component Development 35
Composition of Application Components into Modules 35
Composition of Modules into Applications 35
‘Application Deployment 36
Summary 37
Chapter 2: Directory Services and JNDI 39
Naming and Directory Services 39
‘Naming Services 40
Directory Senviees a1
‘LDAP 2
LDAPData 4a
Introducing JNDI 44
“The Lads rt
‘Why Use JNDI Wher We Have LDAP? 47
Using JNDI 48
‘nstalling INDI a
Hass to Obtain INDI Service Providers 0
Developing Your Own Service Provider 50
Javaand LDAP i 50
Contra 7
hentia 1
utherzai :
White Pages Services z 2
Diswibuted Computing Directory 32
‘Anplisation Configuaton. 33
LDAP Operations 53
‘Standard LDAP Operations 54
Connecting tothe LDAP Server with INDI E = 3a
Binding = 55
ii
Copyrighted materialTable of Contents
Simple, SSL/TLS, and SASL Security ss
‘LDAP v2.and LDAP vi Authenticating
‘Searching an LDAP Server 87
‘Example LDAP Filters 7
Determining LDAP Scope ST
“LDAP. SCOPE SUBTREE 58
EDAP_SCOPE_ONELEVEL 58
LDAP_SCOPE_BASE 59
Performing a INDI Search 53,
How the Search Program Works 1
Authenticated Searching 2
Restricting the Attributes Displayed 64
‘Adding Entries : 6
Modifying an Entry 2
Delete an Entry 74°
Storing and Retrieving Java Objects in LDAP_ 15
“ational LDAP
‘Sealzed lava
Java References
Returning to JNDI without LDAP 7
Example DNS Application 78
Summary 80
ter 3: Distributed Computing Using RMI 83
The RMI Architecture Ba
‘The Stub and Skeleton Layer 85.
Skeletons 86
‘The Remote Reference Laver a
‘The Transport Layer 87
Locating Remote Objects 88
Policy Files 0
RMI Exceptions "1
Developing Applications with RMI 92
Defining the Remote Interface 93
Implementing the Remote Interface 93
‘Writing the Client that Uses the Remote Objects 9s
Generating Stubs and Skeletons 96
Registering the Object 96,
‘Running the Client and Server 97
‘The RMISecurityManager 98
Parameter Passing in RMI 98
‘Primitive Parameters SR
Object Parameters 99
‘Remote Parameters 2
Copyrighted materialTable of Contents
‘The Distributed Garbage Collector 100
Dynamically Loading Classes 104
Remote Callback: 108
Object Activation 11
‘The Activation Group 113
Activation Deseripior Ms
‘Making Objects Activatable_ 116
‘Step 1: Create the Remote Inerfoce rT]
‘Step 2: Create the Object Implementation 417
Step 3: Register the Object with the System 3 117
‘Allcuative to Extending the Astivatable Class ng
‘Starting Multiple JVMs other than with mid 120
Deactivation 123
Custom Sockets and SSL
RMI, Firewalls, and HTTP 136
HTTP Tunneling 136
MIP, mW
HTP soCGL 2
‘The SOCKS Protacal 1k
‘Downloaded Socket Factorie 138
BMI Over 10P 138
Intopesbiliy with CORBA 139
‘Writing Programs with RMI-LIOP_ 140,
‘nth 40
Inthe Client Li
RMI-IIOP and Java PDL
‘The DLBil 1a
“The Sener implementation 143
‘The Clicat Implementation 6
RMI-I1OP and DEE —___148
Tuning RMI Applications 149
‘Summary 154
Chapter 4: Database Programming with JDBC 157
Database Drivers 159
‘Type 1 - JDBC-ODBC Bridge 159
‘Type 2— Part Java, Part Native Driver 160
‘Type 3— Intermediate Database Access Server 161
‘Type 4— Pure Java Drivers = 161
Getting Started 162
‘The java.sql Package 162
(Connection Management 163Table of Contents
Data Types _164
Database Metadata 16
Exceptions and Warnings 165
® Loading a Database Driver and Opening Connections 166
TRC URLs Leb
DriverManager 161
Das 170
Establishing a Connection ~ 170
Creating and Executing SQL Statements: 174
‘An Example: Movie Catalog 175
Quorying the Database 180
. Prepared Statements 183,
Mapping SOL Types io Java 186
‘Transaction Support 183
Savepoints 190,
Scrollable and Updateable Resilses 191
cclabe Reals 1
Upduteabie Resulsats 191
Batch Updates 198
| The javax.sql Package 199
DBC Data Sources 00
‘The javax.sql.DataSource Interface 201
"The getConnection() Method 201
The setLeginTancout) Method 201
‘The set oginTimeout) Method 202
‘The gotLog Writer) Method 202
‘The setLogWrier) Method 202
INDI and Data Sources 00203
Creating « Dat Source 203
Retrieving a DataSource Object 208
Key Features 03
‘The Movie Catalog Revisied 205
Connection Pooling 207
“Traditional Connection Pooling 208,
‘Connection Pooling with the javax.sql Package 210
“The vax gl. ConnsstioaPoo\DataSouree Interice a
‘The avax.sqlPooledConneeton Iterfve 2u1
‘The avax ag] ConnecionEvenListenerIntrice 211
‘The avaxsal.Connoctioafivert Class 212
Connection Pooling Implementation 213
Distributed Transactions Z 213
What isa Transaction? = uu
Brisf Background 214
‘Transaction Processing ~ Concepts 215.
‘Tramaction Demarestion 1s
‘Transootion Context and Propsgation 216
‘Resource Enlistment 216
Tun Phase Commit Dé
‘Building Blocks of Transaction Processing Systems 217
‘Application Components 211
Resource Managers 2
Thnatction Mana 21Table of Contents
{DRC Disirhutad Transactions 19
“Thejavan so XADuusSoureeInrice 219
Thelavas.sa1XACoanertion neice 219
‘Thejavarrnsction UsefTrmeacionlnerie 220
‘Steps for Implementing Distributed Transactions 221
Configuntion 2
Beginning s takastion 221
"Database Operations 222
Endng sTranacton 23
Sperial Precautions 223
RowSet Objects 223
The javax si RowSet Interface 25
Properien 28
Events 2
Command Execution and Results ||
‘Types of RowSet Objects 236
The CechedRowSet implementation a]
‘The JDBC Rowset Implementation 228
‘The Web Rowset Implementation 229
Summary 230
Chapter 5: Introduction to Web Containers 233
‘The HTTP Protocot 088
HITP Reavest Methods 2
“TheGET Request Method 25
The POST Keques Metod 23
The HEAD Request Metiod 23
+ The HTTP Response 235
Web Containers and Web Applications 236
Java Servlets 231
TersServer Pages 230
Deployment Descriptors 2H
‘Structure of Web Applications 241
‘Types of Web Container 22
A Simple Web Application 242
Prepare the Web Container 243,
Create the HTML File 243
Gaon Servet 283
‘Constructing the Web Application ~ 244
Deploying te Web Application 248
Running the Web Apptication 250
How the Application Works 251
‘The Greeting Serviet_ 252
TheDeployment Descripor 284
Summary 5 255