D53942GC10 Toc
D53942GC10 Toc
D53942GC10 Toc
Authors
Bijoy Choudhury Gary Williams
Copyright 2009, Oracle. All rights reserved. Disclaimer This document contains proprietary information and is protected by copyright and other intellectual property laws. You may copy and print this document solely for your own use in an Oracle training course. The document may not be modified or altered in any way. Except where your use constitutes "fair use" under copyright law, you may not use, share, download, upload, copy, print, display, perform, reproduce, publish, license, post, transmit, or distribute this document in whole or in part without the express authorization of Oracle. The information contained in this document is subject to change without notice. If you find any problems in the document, please report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not warranted to be error-free. Restricted Rights Notice If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United States Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS The U.S. Governments rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract. Trademark Notice Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Editors
Aju Kumar Amitha Narayan
Graphic Designer
Priya Saxena
Publishers
Sujatha Nagendra Joseph Fernandez
Contents
Introduction Objectives 1-2 Course Objectives 1-3 Course Agenda 1-4 Fundamentals of Java EE Technology 1-9 Designing Java EE Applications 1-10 Developing a Web Application Using Servlets 1-11 Developing a Web Application Using JavaServer Pages 1-12 Accessing Resources with JNDI and Dependency Injection 1-13 Developing the Business Logic with Session Beans 1-14 Developing the Persistence Layer with JPA Entities 1-15 Manipulating JPA Entities with the EntityManager API 1-16 Developing the Business Logic with Web Services 1-17 Developing the Web Interface Using JavaServer Faces 1-18 Planning Navigation and Page Flow 1-19 Handling Application Events 1-20 Asynchronous Communication with Message-Driven Beans 1-21 Managing Transactions with Session and Message-Driven Beans 1-22 Securing Java EE Applications with JAAS 1-23 Packaging and Deploying Java EE Applications 1-24 Troubleshooting Java EE Applications 1-25 Summary 1-26 Fundamentals of Java EE Technology Objectives 2-2 Java Platform, Enterprise Edition 2-3 Java EE Platform 2-4 Distributed Multitiered Applications 2-5 Benefits of the Java EE Platform 2-6 Java EE Platform and APIs 2-8 Quiz 2-11 Java EE Components 2-12 Business-Tier Components 2-13 Enterprise JavaBeans (EJB) 2-14 Enterprise JavaBeans Application Architecture 2-16
iii
Types of Enterprise JavaBeans 3.0 2-17 Enterprise JavaBeans 3.0 Component Architecture 2-18 Java Persistence API (JPA) 2-19 Quiz 2-21 Web Services 2-22 Java EE Web Services Architecture 2-23 Client-Tier Components 2-25 Java EE Web-Tier Components 2-26 Java EE Web Application Architecture 2-28 What Is a Servlet? 2-29 What Is a JavaServer Page? 2-30 What Is JavaServer Faces? 2-31 Web-Tier Components: Summary 2-32 Java EE Applications 2-33 Packaging Java EE Applications 2-34 Packaging Java EE Application Components 2-35 Security in Java EE Applications 2-36 Using Deployment Descriptors for Declarative Security 2-37 Quiz 2-38 Java EE Server 2-39 Oracle WebLogic Server 10.3 2-41 WebLogic Server Domain 2-42 WebLogic Server Servers 2-44 Administration Server 2-45 Managed Server 2-46 WebLogic Server Machines 2-47 JDeveloper and Java EE 2-48 Oracle JDeveloper 11g Environment 2-49 Oracle JDeveloper 11g Visual Design Tools 2-50 Summary 2-51 Practice: Overview 2-52 3 Designing Java EE Applications Objectives 3-2 Realizing the Benefits of Java EE 3-3 Java EE Issues 3-4 Design Patterns 3-5 Java EE Design Patterns 3-6 Implementing a Session Facade Pattern 3-7 Defining the MVC Architecture 3-8 The Model 3-9
iv
The View 3-10 The Controller 3-11 Designing a Java EE Application 3-12 Quiz 3-13 Struts: Overview 3-14 Struts Components 3-15 Struts Architecture 3-16 Struts Page Flow Design 3-17 JSF and Struts 3-19 Implementing the User Interface with JSF and Core Java EE Patterns 3-20 Selecting a Persistence Strategy 3-21 Quiz 3-22 What Is a Data Source? 3-23 What Is a Connection Pool? 3-24 Benefits of Data Sources Plus Connection Pools 3-25 JDBC Data Source Architecture 3-26 Data Source Architecture: Connecting 3-27 Creating a Data Source in WebLogic Server 3-28 Summary 3-30 Practice: Overview 3-31 4 Developing a Web Application Using Servlets Objectives 4-2 Servlets: Overview 4-3 About Java Servlets 4-4 Principal Features of Servlets 4-5 Life Cycle of Servlets 4-6 HTTP Servlets 4-7 Inside an HTTP Servlet 4-8 doGet() Method 4-9 doPost() Method 4-10 HttpServletRequest Object 4-11 HttpServletResponse Object 4-12 HttpSession 4-13 Session Objects 4-14 Methods for Invoking Servlets 4-15 Quiz 4-16 Handling Input: The Form 4-17 Handling Input: The Servlet 4-18 Initialization and Destruction 4-19
Error Handling 4-20 Debugging a Servlet 4-21 JDeveloper Environment 4-22 Servlet Mapping 4-23 Servlet Mapping in JDeveloper 4-24 Invoking a Servlet 4-25 Specifying Java EE Web Module Settings 4-26 Summary 4-27 Practice: Overview 4-28 5 Developing a Web Application Using JavaServer Pages Objectives 5-2 JavaServer Pages 5-3 Comparing Servlets and JSPs 5-4 Invoking JSPs 5-5 Date.jsp 5-6 Date Servlet 5-7 Automated JSP Features 5-8 JSP Life Cycle 5-9 Basic JSP Elements 5-10 Declarations 5-11 Expressions 5-13 Scriptlets 5-14 Implicit Objects 5-15 Example 5-17 Quiz 5-19 Directives 5-20 include: Example 5-21 page Directive 5-22 JSP and JavaBeans 5-24 Using JavaBeans with JSP 5-25 scope Attribute of <jsp:useBean> Tag 5-27 Accessing and Setting Bean Properties 5-28 JSP XML Document 5-30 Traditional Syntax Versus XML Syntax 5-31 JSP Segments 5-33 Quiz 5-34 What Is a Tag Library? 5-35 Tag Interfaces 5-36 Tag Handlers 5-37
vi
Tag Library Descriptor 5-38 Implementing Simple Tags 5-39 JSP Expression Language 5-40 Expression Language Implicit Objects 5-41 JDeveloper and JSPs 5-42 Summary 5-43 Practice: Overview 5-44 6 Accessing Resources with JNDI and Dependency Injection Objectives 6-2 Java Naming and Directory Interface 6-3 JNDI Structure 6-4 Naming Service 6-5 JNDI Tree 6-6 Contexts and Subcontexts 6-8 Referencing Java EE Resources with JNDI 6-9 Providing JNDI Properties 6-10 Referencing a Local Session EJB with JNDI 6-11 Referencing a Remote Session EJB with JNDI 6-12 JNDI State Replication 6-13 Quiz 6-14 What Are Annotations? 6-15 Dependency Injection 6-16 Types of Dependency Injection 6-18 Defining the @Resource Annotation 6-19 Using Java EE Resources with Dependency Injection 6-20 Working with Dependency Injection 6-21 Referencing EJBs with Dependency Injection 6-22 Summary 6-23 Practice: Overview 6-24 Developing the Business Logic with Session Beans Objectives 7-2 What Is a Session Bean? 7-3 Stateless Versus Stateful Session Beans 7-4 Dependency Injection in EJB 7-5 Life Cycle of a Stateless Session Bean 7-6 Elements of a Stateless Session Bean 7-7 Defining the Stateless Session Bean 7-8 Analyzing the Remote and Local Interfaces 7-9 Creating a Test Client for the SLSB 7-11
vii
Life Cycle of a Stateful Session Bean 7-12 Passivation and Activation Concepts 7-14 Creating a Stateful Session Bean 7-15 Defining the Stateful Session Bean 7-16 Analyzing the Remote and Local Interfaces 7-17 Creating a Test Client for the SFSB 7-18 Calling a Stateless Bean from a Stateful Bean by Implementing DI 7-19 Interceptor Methods and Classes 7-20 Interceptor Method 7-21 Interceptor Classes 7-22 Summary 7-23 Practice: Overview 7-24 8 Developing the Persistence Layer with JPA Entities Objectives 8-2 What Are JPA Entities? 8-3 Domain Modeling with Entities 8-5 Managing Persistence of Entities 8-6 Declaring an Entity 8-7 Mapping Entities 8-8 Quiz 8-9 Mapping Inheritance 8-10 Single-Table Strategy 8-12 Joined-Tables Strategy 8-14 Specifying Entity Identity 8-16 Generating Primary Key Values 8-17 Mapping Relationships Between Entities 8-19 Implementing One-to-One Relationships 8-21 Implementing Many-to-One Relationships 8-23 Implementing One-to-Many Relationships 8-25 Implementing Many-to-Many Relationships 8-26 Quiz 8-27 Managing Entities 8-28 Summary 8-29 Practice: Overview 8-30 Manipulating JPA Entities with the EntityManager API Objectives 9-2 What Is EntityManager? 9-3 Managing an Entity Life Cycle with EntityManager 9-5
viii
Accessing an EntityManager Instance in an Application 9-7 Creating a Container-Managed EntityManager Instance 9-8 Creating an Application-Managed EntityManager Instance 9-9 Specifying Database Operations with the EntityManager API 9-10 Commonly Used Methods in the EntityManager Interface 9-11 Quiz 9-13 Inserting New Data 9-14 Deleting Data 9-15 Updating and Synchronizing the Entity with the Database 9-16 Updating Data 9-17 Finding an Entity by Primary Key 9-18 Quiz 9-19 What Is JPA Query API? 9-20 Retrieving Entities by Using the Query API 9-21 Writing a Basic JPQL Statement 9-22 Creating Named Queries 9-23 Writing Dynamic Queries 9-24 Summary 9-25 Practice: Overview 9-26 10 Developing the Business Logic with Web Services Objectives 10-2 Web Service 10-3 Web Service Standards 10-4 SOAP: XML Messaging for Web Services 10-5 Web Services Description Language (WSDL) 10-6 UDDI Registry 10-7 Web Service Architecture 10-9 Quiz 10-11 Web Service Metadata for Java Platform (JSR-181) 10-12 Examining the JSR-181 Processor Model 10-13 Describing JSR-181 Annotations 10-14 Sample Annotated Java Web Service File 10-15 What Is JAX-WS? 10-16 Quiz 10-17 Web Service Development Approach 10-18 Bottom-Up Approach 10-19 Top-Down Approach 10-20 Developing a Web Service by Using the Top-Down Approach 10-21 Defining an XSD Schema 10-22
ix
Creating the WSDL Document 10-23 Modifying the WSDL Document 10-25 Creating the Web Service by Using Oracle JDeveloper 11g 10-26 Implementing the Web Service Logic 10-27 Summary 10-28 Practice: Overview 10-29 11 Developing the Web Interface Using JavaServer Faces Objectives 11-2 JSF: Overview 11-3 JSF: Benefits 11-4 Key Terms 11-5 JSF Architecture 11-6 JSF Components 11-8 JSF UI Components 11-9 JSF Component Architecture 11-10 Quiz 11-11 Tag Handlers and Component Trees 11-12 Tag Libraries 11-13 Configuration Files 11-14 JSF Renderers 11-15 Managed Beans 11-16 Expression Language 11-17 Life Cycle of a JSF Page 11-18 JSF Life Cycle: Initial Request 11-19 JSF Life Cycle: Postback 11-20 Quiz 11-22 Using JSF Tag Libraries 11-23 JSF Applications 11-24 JSF and JDeveloper 11g 11-25 JSF Navigation Diagram 11-26 Adding to JSF with ADF Faces 11-27 Using ADF Faces Layout Components 11-28 Creating Resizable Panes 11-29 Creating Collapsible Panes with the Panel Splitter Component 11-30 Creating Collapsible Panes with the Panel Accordion 11-31 Panel Accordion Overflow 11-32 Setting Panel Accordion Properties 11-33 Creating Titled Sections and Subsections 11-35 Grouping Related Components 11-36 Arranging Items Around a Central Area 11-37
x
Summary 11-39 Practice: Overview 11-40 12 Planning Navigation and Page Flow Objectives 12-2 Traditional Navigation 12-3 What Is JSF Navigation? 12-4 JSF Navigation: Example 12-5 JSF Navigation Rules 12-6 faces-config Console 12-8 faces-config.xml 12-9 JSF Navigation Modeler 12-10 JSF Navigation Diagram 12-11 Navigation Elements 12-12 Global Rules 12-14 Pattern-Based Rules 12-15 JSF: Example 12-16 JSF Navigation: Example 12-18 Using the JSF Configuration Editor 12-21 Managed Beans 12-22 Creating Managed Beans 12-24 Managed Bean: Example 12-25 Setting Managed Bean Scope 12-26 Relationships Between Managed Beans 12-27 Managed Properties 12-28 Managed Properties: Examples 12-29 Using the Managed Bean on the JSF Page 12-31 Summary 12-32 Practice: Overview 12-33 13 Handling Application Events Objectives 13-2 JSF Event Model 13-3 Types of Events 13-4 Action Events 13-5 Creating Action Events 13-6 Value Change Events 13-7 Creating Value Change Events 13-8 Event Listener Classes 13-9 Handling Action Events 13-10 Handling Value Change Events 13-11
xi
Event and Listener Execution Order 13-12 Validation in the JSF Life Cycle 13-13 Creating Custom Exception Handlers 13-15 Registering an Exception Handler 13-16 Changing Life Cycle Exception Reporting 13-17 JavaServer Faces Validators 13-18 Creating Backing Bean Validation in JDeveloper 13-19 Backing Bean Validator: Code Example 13-20 Input Validation 13-21 Summary 13-22 Practice: Overview 13-23 14 Asynchronous Communication with Message-Driven Beans Objectives 14-2 Messaging Systems 14-3 Message-Oriented Middleware 14-4 Java Message Service 14-5 JMS Application Architecture 14-6 Point-to-Point Queue 14-7 Publish-Subscribe Topics 14-8 Quiz 14-9 WebLogic Server JMS Features 14-10 JMS Architecture: Connecting 14-11 JMS Architecture: Sending Messages 14-12 Transacted Messaging 14-13 WebLogic Server JMS Server 14-14 Creating a JMS Server 14-15 Connection Factory 14-16 JMS Destination 14-17 Creating a Queue Destination 14-18 Message-Driven Beans 14-20 Life Cycle of a Message-Driven Bean 14-21 Creating a Message-Driven Bean 14-22 Creating a JMS/MDB Client 14-24 Summary 14-26 Practice: Overview 14-27 15 Managing Transactions with Session and Message-Driven Beans Objectives 15-2 What Is a Transaction? 15-3 Example of a Transaction 15-4
xii
Types of Transactions 15-5 Transaction Management 15-7 Two-Phase Commit Protocol 15-8 Successful Two-Phase Commit 15-9 Unsuccessful Two-Phase Commit 15-10 Quiz 15-11 Java Transaction API (JTA) 15-12 EJB Transaction Model 15-13 Managing Transactions with EJBs 15-14 Types of Transaction Management 15-16 Container-Managed Transactions 15-17 Transaction Attribute: REQUIRED 15-18 Transaction Attribute: SUPPORTS 15-19 Transaction Attribute: MANDATORY 15-20 Transaction Attribute: NEVER 15-21 Transaction Attribute: REQUIRES_NEW 15-22 Transaction Attribute: NOT_SUPPORTED 15-23 Quiz 15-24 CMT: setRollbackOnly() 15-25 Container-Managed Transaction: Example 15-26 Java Transaction API (JTA) 15-27 JTA: UserTransaction Interface 15-29 Bean-Managed Transactions 15-30 Bean-Managed Transaction: Example 15-31 BMT Demarcation: Restrictions 15-32 Enlisting Database Resources 15-33 Summary 15-34 Practice: Overview 15-35 16 Securing Java EE Applications with JAAS Objectives 16-2 Goals of Java EE Security Architecture 16-3 Overview of Java EE Security Architecture 16-4 Java Authentication and Authorization Service (JAAS) 16-5 Authorization of a Client 16-8 Quiz 16-9 Security Process Architecture 16-10 Security Services 16-11 Security Realms 16-12 Users and Groups 16-13
xiii
Configuring New Users in WebLogic Server 16-14 Adding Users to Groups 16-16 Logical Roles 16-17 Quiz 16-19 Configuring Security 16-20 Determining Protected Resources 16-21 Defining the Logical Roles 16-22 Defining and Using Logical Roles in Web Applications (web.xml) 16-23 Defining and Using Logical Roles in EJBs (ejb-jar.xml) 16-24 Mapping Logical Roles to Users and Groups 16-25 Setup Authentication 16-26 Authentication Examples 16-27 Setting Access Control with JDeveloper 16-28 Creating Web Application Security Roles 16-29 Web Application Login Authentication 16-30 Web Application Authorization 16-31 EJB Security Roles 16-32 Security Annotation: Example 16-33 Summary 16-34 Practice: Overview 16-35 17 Packaging and Deploying Java EE Applications Objectives 17-2 Deploying Java EE Applications 17-3 Packaging Business-Tier Components 17-5 Packaging Web Applications 17-6 Web Application Structure 17-7 Configuring Web Applications 17-9 What Is web.xml? 17-10 What Is weblogic.xml? 17-11 Web Application Archive 17-12 Creating Web Application Archives 17-13 Quiz 17-14 EJB Application Directory Structure 17-15 Java EE Enterprise Application (EAR) 17-17 Creating EJB Archives 17-18 Creating Enterprise Archives 17-19 Deploying Entities 17-20 Persistence.xml File 17-21 Configuring Oracle WebLogic ServerSpecific Features 17-22
xiv
Deploying with the Oracle WebLogic Server Console 17-23 Deploying with Oracle JDeveloper 17-24 What Is Ant? 17-25 Ant Build Files 17-26 A Sample build.xml File 17-27 Creating a JAR File by Using Ant Task 17-28 Creating a WAR File by Using Ant Task 17-29 Creating an EAR File by Using Ant Task 17-30 Deploying an Application by Using Ant Task 17-31 Packaging Best Practices for Production Environments 17-32 Summary 17-33 18 Troubleshooting Objectives 18-2 Troubleshooting Basics 18-3 Diagnosing the Problem 18-4 Requesting Help 18-5 Creating Test Cases 18-6 Java Logging 18-7 Configuring Java Logging 18-8 Sending Logger Output to a File 18-9 Turning on Diagnostics in JDeveloper 18-10 Sample Java Clients 18-11 Sample Client for Web Service 18-12 Tools and Utilities 18-13 Identifying Search Paths with FileMon 18-14 Testing Java Code with JUnit 18-15 Analyzing HTTP Requests 18-16 Debugging with JDeveloper 18-17 Summary 18-18 Appendix A: Practices and Solutions B Working with ADF Faces Components Objectives B-2 Using ADF Faces Layout Components B-3 Adding Spaces and Lines B-4 Stretching Components B-5 Enabling Automatic Component Stretching B-6 Stretching a Table Column B-7 Creating Resizable Panes B-8
xv
Printing Layout Panel Content B-9 Creating Collapsible Panes with the Panel Splitter Component B-10 Creating Collapsible Panes with the Panel Accordion B-11 Panel Accordion Overflow B-13 Setting Panel Accordion Properties B-14 Arranging Items in Columns or Grids B-15 Creating Stacked Tabs B-17 Hiding and Displaying Groups of Content B-18 Arranging Items Horizontally or Vertically, with Scrollbars B-20 Displaying Table Menus, Toolbars, and Status Bars B-22 Creating Titled Sections and Subsections B-24 Grouping Semantically Related Components B-25 Displaying a Bulleted List B-26 Displaying Items in a Content Container Offset by Color B-27 Arranging Items Around a Central Area B-28 Using ADF Faces Skins B-30 Using Dynamic Page Layout B-31 Using Expression Language to Conditionally Display Components B-32 Characteristics of Partial Page Rendering (PPR) B-33 Enabling PPR Declaratively B-34 Native PPR Example B-36 Declarative PPR Example B-37 Enabling PPR Programmatically B-39 Conforming to PPR Guidelines B-40 Summary B-41 Index
xvi