J2EE in 21Days pdf

1.1K 206 0
J2EE in 21Days pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

201 West 103rd St., Indianapolis, Indiana, 46290 USA Martin Bond Dan Haywood Debbie Law Andy Longshaw Peter Roxburgh J2EE in 21 Days Teach Yourself 00 0672323842 FM 3/20/02 9:31 AM Page i Sams Teach Yourself J2EE in 21 Days Copyright  2002 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photo- copying, recording, or otherwise, without written permission from the publish- er. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-672-32384-2 Library of Congress Catalog Card Number: 2001098579 Printed in the United States of America First Printing: April, 2002 03020100 4321 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages aris- ing from the information contained in this book. EXECUTIVE EDITOR Michael Stephens MANAGING EDITOR Matt Purcell ACQUISITIONS EDITOR Todd Green DEVELOPMENT EDITOR Michael Watson PROJECT EDITOR Christina Smith COPY EDITOR Pat Kinyon INDEXERS Tom Dinse Erika Millen PROOFREADER Melissa Lynch TECHNICAL EDITOR Harold Finz, Steve Heckler, Farooq Karim, and Ari Krupnikov TEAM COORDINATOR Pamalee Nelson INTERIOR DESIGNER Gary Adair COVER DESIGNER Aren Howell PRODUCTION Cheryl Lynch Michelle Mitchell 00 0672323842 FM 3/20/02 9:31 AM Page ii Contents at a Glance Introduction 1 WEEK 1 Introducing J2EE and EJBs 7 Day 1 The Challenge of N-Tier Development 9 2 The J2EE Platform and Roles 27 3 Naming and Directory Services 81 4 Introduction to EJBs 125 5 Session EJBs 165 6 Entity EJBs 211 7 CMP and EJB QL 271 WEEK 2 Developing J2EE Applications 333 Day 8 Transactions and Persistence 335 9 Java Message Service 395 10 Message-Driven Beans 429 11 JavaMail 461 12 Servlets 501 13 JavaServer Pages 555 14 JSP Tag Libraries 603 WEEK 3 Integrating J2EE into the Enterprise 651 Day 15 Security 653 16 Integrating XML with J2EE 701 17 Transforming XML Documents 741 18 Patterns 787 19 Integrating with External Resources 827 20 Using RPC-Style Web Services with J2EE 869 21 Web Service Registries and Message-Style Web Services 923 Appendixes Appendix A An Introduction to UML 965 B SQL Reference 977 C An Overview of XML 987 D The Java Community Process 999 Glossary 1003 Index 1025 00 0672323842 FM 3/20/02 9:31 AM Page iii Contents Introduction 1 WEEK 1 Introducing J2EE and EJBs 7 DAY 1 The Challenge of N-Tier Development 9 Monolithic Development 10 Consequences of Monolithic Applications 10 The Move into the Second Tier 11 Consequences of the 2-Tier Design 12 Complexity Simplified by Modularity 14 Component Technology 15 Benefits of Modularity 16 Benefits of the 3-Tier Scenario 16 A Model for Enterprise Computing 17 Lifecycle 18 Persistence 18 Naming 18 Transaction 19 Java 2 Enterprise Edition (J2EE) 20 Components and Containers 20 J2EE Standard Services 21 J2EE Blueprints 23 J2EE Compatibility Test Suite 24 The Future of J2EE 25 Summary 25 Q&A 25 Exercises 26 D AY 2 The J2EE Platform and Roles 27 Revisiting the J2EE Platform 28 Using Sun Microsystems’ J2EE SDK 28 Installing J2EE SDK 1.3 29 Starting the J2EE Reference Implementation (RI) 32 Troubleshooting J2EE and Cloudscape 34 Closing Down J2EE RI and Cloudscape 37 Optional Software Used in this Book 37 Understanding Tiers and Components 38 The Business Tier 39 The Presentation Tier 44 00 0672323842 FM 3/20/02 9:31 AM Page iv Components: Web-Centric 45 The Client Tier 49 Standalone Client 52 Understanding Containers 55 Understanding the Services Containers Supply to Components 56 Hypertext Transfer Protocol (HTTP) 57 HTTP over Secure Sockets Layer (HTTPS) 57 Java Database Connectivity (JDBC) 57 Java Transaction API (JTA) 58 Java Authentication and Authorization Service (JAAS) 58 Java API for XML Parsing (JAXP) 58 Java Naming and Directory Interface (JNDI) 59 JavaBeans Activation Framework (JAF) 59 JavaMail 60 Java Message Service (JMS) 60 Java Interface Definition Language (Java IDL) 60 Remote Method Invocation over Internet Inter-Orb Protocol (RMI-IIOP) 61 Connector Architecture 62 Introducing Platform Roles 62 J2EE Product Provider 63 Application Component Provider 63 Application Assembler 63 Application Deployer 64 Systems Administrator 64 Tool Provider 65 Future of J2EE tools 65 Packaging and Deploying J2EE Applications 66 J2EE applications 67 Breaking Modules down into Components 68 Summary 70 Q&A 70 Exercises—Case Study 71 The Job Agency 72 Using the Agency Case Study 73 Practice Makes Perfect 75 The Case Study Directory on the CD-ROM 76 Installing the Case Study Database 76 D AY 3 Naming and Directory Services 81 Naming and Directory Services 82 Why Use a Naming Service? 82 What is JNDI? 83 00 0672323842 FM 3/20/02 9:31 AM Page v Common Naming Services 83 Naming Conventions 84 Using JNDI 85 Using Sun Microsystems’ J2EE Reference Implementation 85 Obtaining an Initial Context 86 Initial Context Naming Exceptions 86 Defining the JNDI Service 87 JNDI Properties Files 88 Application Properties 89 Applet Parameters 90 Hard-Coded Properties 90 Binding JNDI Objects 90 Binding Objects 91 Binding Problems 91 Name Persistence 92 Rebinding Objects 92 Unbinding Objects 92 Renaming Objects 93 JNDI Name Lookup 93 Changing Contexts 94 Narrowing RMI-IIOP Objects 95 Contexts 96 Listing Contexts 96 Creating and Destroying Contexts 98 More on JNDI Names 100 Special Characters 100 Composite and Compound Names 100 URLs 101 Attributes 102 Overview of LDAP X.500 Names 102 Obtaining an LDAP Server 103 Using OpenLDAP 104 Configuring JNDI to use LDAP 106 Testing the LDAP Server 107 Obtaining a Directory Context 108 Reading Attributes 108 Searching for Objects 109 Manipulating Attributes 112 More on Objects 114 Loading Classes from a Code Base 114 Defining a Code Base 114 References 117 vi Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9:31 AM Page vi Contents vii What Else Can JNDI Do? 120 JNDI Events 120 Security 121 Summary 122 Q&A 123 Exercise 124 D AY 4 Introduction to EJBs 125 What Is an EJB? 126 Beans, Clients, Containers, and Servers 126 The EJB Landscape 127 Discovering EJBs 127 Types of EJB 128 Common Uses of EJBs 128 Why Use EJBs? 129 Hiding Complexity 130 Separation of Business Logic from UI and Data Access 130 Container Services 131 What’s in an EJB? 132 The Business Interface 132 The Business Logic 134 Factory Information 140 Bean Metadata 141 How Do I Create an EJB? 142 The Creation Mechanism 142 Caveats on Code Creation 143 Create the Deployable Component 143 How Do I Deploy an EJB? 147 Plugging into the Container 147 Performing the Deployment 148 How Do I Use an EJB? 148 Discovery 148 Retrieval and Use 149 Disposing of the EJB 150 Running the Client 150 Deploying and Using an EJB in the J2EE Reference Implementation 151 Opening the Case Study EAR File 152 Examining the Case Study Application 154 Deploying the Case Study Application 156 Testing the Case Study Application 158 Troubleshooting the Case Study Application 160 00 0672323842 FM 3/20/02 9:31 AM Page vii Summary 161 Q&A 161 Exercises 162 D AY 5 Session EJBs 165 Overview 165 The javax.ejb Package for Session Beans 167 Stateless Session Bean Lifecycle 168 Specifying a Stateless Session Bean 172 Implementing a Stateless Session Bean 175 Implementing javax.ejb.SessionBean 175 Implementing the Home Interface Methods 175 Implementing the Remote Interface Methods 177 Exceptions 179 Configuring and Deploying a Stateless Session Bean 180 Using deploytool 181 Structural Elements 182 Presentational Elements 183 Session Element 184 Deploying the Enterprise Application 193 Stateful Session Bean Lifecycle 193 Specifying a Stateful Session Bean 196 Implementing a Stateful Session Bean 198 Passivation 198 Timeouts 199 Chaining State 200 Configuring and Deploying a Stateful Session Bean 200 Client’s View 201 Patterns and Idioms 202 Business Interface 203 Adapter 204 Coarse-Grained 205 Gotchas 205 Summary 206 Q&A 207 Exercises 207 D AY 6 Entity EJBs 211 Overview 211 The N-tier Architecture Revisited 212 Comparison with RDBMS Technology 213 Identifying Entities 214 viii Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9:31 AM Page viii Contents ix The javax.ejb Package for Entity Beans 216 Entity Bean Types 217 Remote Versus Local Interfaces 217 BMP Entity Bean Lifecycle 219 Specifying a BMP Entity Bean 225 Local-Home Interface 225 Local Interface 230 Implementing a BMP Entity Bean 231 Implementing the Local-Home Interface Methods 235 Implementing the Local Interface Methods 241 Generating IDs 243 Granularity Revisited 245 Beware Those Finder Methods! 245 EJB Container Performance Tuning 247 Configuring and Deploying a BMP Entity Bean 248 Entity Element 249 Client’s View 252 Session Beans Revisited 254 Patterns and Idioms 258 Interfaces, Façades, and State 258 Use Local Interfaces for Entity Beans 258 Dependent Value Classes 259 Self-Encapsulate Fields 261 Don’t Use Enumeration for Finders 262 Acquire Late, Release Early 262 Business Interface Revisited 264 Gotchas 264 Summary 265 Q&A 266 Exercises 266 D AY 7 CMP and EJB QL 271 Overview of Container-Managed Persistence 271 N-tier Architecture (Revisited Again) and CMP Fields 273 A Quick Word about the Case Study Database 276 CMP Entity Bean Lifecycle 277 Container-Managed Relationships 279 Relationship Types 280 Navigability 282 cmr-fields 282 Manipulating Relationships 286 00 0672323842 FM 3/20/02 9:31 AM Page ix EJB QL 291 Select Methods 291 Syntax and Examples 293 Further Notes 300 Specifying a CMP Entity Bean 301 The Local-Home Interface 301 The Local Interface 301 Implementing a CMP Entity Bean 302 Implementing javax.ejb.EntityBean 302 Implementing the Local-Home Interface Methods 305 Finder Methods 308 Implementing the Local Interface Methods 312 Configuring a CMP Entity Bean 313 The entity Element 313 The relationships Element 317 Deploying a CMP Entity Bean 322 Patterns and Idioms 323 Normalize/Denormalize Data in ejbLoad()/ejbStore() 323 Don’t Expose cmp-fields 324 Don’t Expose cmr-fields 325 Enforce Referential Integrity Through the Bean’s Interface 326 Use Select Methods to Implement Home Methods 327 Gotchas 328 Summary 329 Q&A 329 Exercises 330 WEEK 2 Developing J2EE Applications 333 DAY 8 Transactions and Persistence 335 Overview of Transactions 336 Container-Managed Transaction Demarcation 338 Bean Managed Transaction Demarcation 345 Motivation and Restrictions 345 Using the Java Transaction API 345 Deploying a BMTD Bean 349 Client-Demarcated Transactions 350 Exceptions Revisited 350 Extended Stateful Session Bean Lifecycle 352 Transactions: Behind the Scenes 354 Transaction Managers, Resource Managers, and 2PC 354 The JTA API 356 x Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9:31 AM Page x [...]... 400 Developing JMS Applications Using JBoss1 402 JMS Implementation in JBoss 402 Programming a JMS Application Using J2EE RI 404 J2EE RI Connection Factories 404 Adding Destinations in J2EE RI 404 Creating a Queue in J2EE RI 404 Point-to-Point Messaging Example 406 JMS Messages 407 Creating a Message 409 Sending a Message ... Security in J2EE 661 J2EE Security Terminology 661 Working with J2EE RI Security 663 Security and EJBs 666 Defining EJB Security 666 Defining Roles 666 Defining the Security Identity 668 Defining Method Permissions 670 Mapping Principals to Roles 674 Using Roles as the Security Identity 676 Security in Web Applications... with consulting, training and technical writing, specializing in OO design, Java and J2EE, Sybase technical consulting, and data modeling Previously, Dan worked at Sybase Professional Services, performing a variety of roles, mostly in the financial industry, including architect, performance specialist, and project manager Dan started his IT career at (what was then) Andersen Consulting, working as a developer... Responsibilities 830 Using the Common Client Interface 834 Interacting with an EIS 834 Installing a Resource Adapter 835 Creating a First CCI Application 836 Managing Transactions and Exploring Records 843 Introducing Other Connectivity Technologies 848 Introducing CORBA 849 Introducing Java IDL 851 Using RMI over IIOP ... a technical authoring company in the United Kingdom specializing in the production of training and educational materials For more information on Content Master, please see its Web site at www.contentmaster.com Martin Bond, B.Sc M.Sc C.Eng, M.B.C.S., was born near Manchester England in 1958 Martin left a budding academic career to develop parallel processing compilers for Inmos Martin has designed and... Accessing Information in a UDDI Registry 929 Manipulating Service Information using UDDI4J 929 Manipulating Service Information Using the IBM WSTK Client API 932 Retrieving and Using Service Information 933 00 0672323842 FM 3/20/02 9:31 AM Page xxi Contents xxi Using JAXR for Registry Access 934 A Generic Approach 934 Using JAXR to Store and Retrieve Service Information... Iterative Tags 622 Co-operating Tags 626 Using Shared Scripting Variables 626 Hierarchical Tag Structures 627 Defining Tag Extra Info Objects 634 Validating Attributes 635 Defining Scripting Variables 637 00 0672323842 FM xvi 3/20/02 9:31 AM Page xvi Sams Teach Yourself J2EE in 21 Days Processing Tag Bodies 637 JavaServer... the same machine Monolithic Development In the days of the mainframe or the standalone personal computer, when an application was housed on a single machine, it was common to find monolithic applications containing all the functionality of the application in one large, frequently unmaintainable piece of software (sometimes referred to as spaghetti code) All user input, verification, business logic,... developed systems using C++, Java, and JavaScript and has developed training courses on Unix programming, Solaris security, Java programming, and XML Martin has an honors degree and a masters degree in computer science from Aberystwyth, Wales, and is a European chartered engineer Martin currently works as an IT trainer and consultant based in Cornwall, England Dan Haywood has been working on large and... 790 Types of Patterns 790 J2EE Patterns 791 Pattern Catalogs 792 Applying J2EE- Specific Patterns 792 Applying Patterns in a Context 793 Generic Patterns 794 J2EE Presentation-Tier Patterns 795 J2EE Business-Tier Patterns 795 J2EE Integration-Tier Patterns 796 Patterns Within J2EE 797 00 0672323842 FM 3/20/02 . 660 Security in J2EE 661 J2EE Security Terminology 661 Working with J2EE RI Security 663 Security and EJBs 666 Defining EJB Security 666 Defining Roles 666 Defining the Security Identity 668 Defining. Factories 404 Adding Destinations in J2EE RI 404 Creating a Queue in J2EE RI 404 Point-to-Point Messaging Example 406 JMS Messages 407 Creating a Message 409 Sending a Message 409 Closing the Connection. Properties 90 Binding JNDI Objects 90 Binding Objects 91 Binding Problems 91 Name Persistence 92 Rebinding Objects 92 Unbinding Objects 92 Renaming Objects 93 JNDI Name Lookup 93 Changing Contexts

Ngày đăng: 27/06/2014, 21:20

Mục lục

  • Contents at a Glance

  • Week 1 -- Introducing J2EE and EJBs

    • Day 1 -- The Challenge of N-Tier Development

    • Day 2 -- The J2EE Platform and Roles

    • Day 3 -- Naming and Directory Services

    • Day 4 -- Introduction to EJBs

    • Day 5 -- Session EJBs

    • Day 6 -- Entity EJBs

    • Day 7 -- CMP and EJB QL

    • Week 2 -- Developing J2EE Applications

      • Day 8 -- Transactions and Persistence

      • Day 9 -- Java Message Service

      • Day 10 -- Message-Driven Beans

      • Day 13 -- JavaServer Pages

      • Day 14 -- JSP Tag Libraries

      • Week 3 -- Integrating J2EE into the Enterprise

        • Day 15 -- Security

        • Day 16 -- Integrating XML with J2EE

        • Day 17 -- Transforming XML Documents

        • Day 19 -- Integrating with External Resources

        • Day 20 -- Using RPC-Style Web Services with J2EE

        • Day 21 -- Web Service Registries and Message-Style Web Services

        • Appendix A -- An Introduction to UML

Tài liệu cùng người dùng

Tài liệu liên quan