ebook img

BEA WebLogic server bible PDF

741 Pages·2002·15.039 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview BEA WebLogic server bible

BEA WebLogic Server Bible Joe Zuffoletto Gary Wells, Brian Gill, Geoff Schneider, Barrett Tucker, Rich Helton, Michael Madrid, Sunil Makhijani Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 http://www.hungryminds.com/ Copyright © 2002 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. Library of Congress Control Number: 2001118280 ISBN: 0−7645−4854−9 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/RV/QS/QS/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland. For general information on Hungry Minds’ products and services please contact our Customer Care department within the U.S. at 800−762−2974, outside the U.S. at 317−572−3993 or fax 317−572−4002. For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign−language translations, please contact our Customer Care department at 800−434−3422, fax 317−572−4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our Sub−Rights Customer Care department at 212−884−5000. 1 Table of Contents BEA WebLogic Server Bible..............................................................................................................................1 Part I: Preparing Your Enterprise for WebLogic...........................................................................................5 In This Part...............................................................................................................................................5 Chapter 1: A Quick Tour of WebLogic Server................................................................................................6 Introducing WebLogic Server..................................................................................................................6 Taking WebLogic for a Spin....................................................................................................................8 Spotting WebLogic in the Real World...................................................................................................10 Sparks.com................................................................................................................................12 Surveying WebLogic’s Features, Services, and Architecture...............................................................12 HTTP server..............................................................................................................................12 J2EE containers.........................................................................................................................13 Gateway to the J2EE APIs........................................................................................................13 Web Services............................................................................................................................14 J2EE Connector Architecture...................................................................................................14 CORBA support........................................................................................................................14 Security services.......................................................................................................................15 Clustering services....................................................................................................................16 Management and monitoring tools...........................................................................................16 Understanding WebLogic’s Role in the Enterprise...............................................................................17 Is WebLogic Right for Your Project?....................................................................................................18 Summary................................................................................................................................................18 Chapter 2: Assembling and Managing a WebLogic Development Team....................................................20 What WebLogic Developers Need to Know.........................................................................................20 Object−oriented programming in Java.....................................................................................20 J2EE..........................................................................................................................................21 Object−Oriented Analysis and Design.....................................................................................21 HTML and JavaScript...............................................................................................................22 XML..........................................................................................................................................22 TCP/IP networking and distributed systems.............................................................................22 Relational databases and SQL..................................................................................................23 Legacy systems.........................................................................................................................23 Collaborative discipline............................................................................................................24 Project Team Roles and Responsibilities...............................................................................................26 Project manager........................................................................................................................26 Application architect.................................................................................................................27 Database designer/database administrator................................................................................27 User Interface (UI) designer.....................................................................................................28 Java/J2EE developer.................................................................................................................28 Quality Assurance (QA) team...................................................................................................29 Documentation team.................................................................................................................30 WebLogic administrator...........................................................................................................30 Project Management Strategies..............................................................................................................31 Gathering requirements.............................................................................................................31 Designing the solution..............................................................................................................32 Managing development.............................................................................................................32 Planning the rollout...................................................................................................................33 Keeping morale high.................................................................................................................34 Summary................................................................................................................................................35 Table of Contents Chapter 3: Designing WebLogic Applications...............................................................................................36 Overview................................................................................................................................................36 Understanding Multitier Applications...................................................................................................36 How J2EE separates applications into tiers..............................................................................36 The Model−View−Controller design pattern............................................................................37 Model−View−Controller in action: An ATM machine............................................................38 Model−View−Controller as a methodology for designing multitier applications....................38 Building Multitier Applications with J2EE: Containers and Components............................................39 Containers.................................................................................................................................39 Components..............................................................................................................................40 Organizing Components into Applications............................................................................................41 Model tier patterns....................................................................................................................42 View tier patterns......................................................................................................................43 Controller tier patterns..............................................................................................................44 Deploying Components in WebLogic’s Containers..............................................................................46 Designing an Example Application: WebLogic Online Brokerage.......................................................47 Identifying requirements...........................................................................................................47 Organizing requirements by user role.......................................................................................49 Expressing requirements in use case diagrams.........................................................................51 Exploding use cases into activity diagrams..............................................................................52 Mapping functionality to MVC with swimlanes......................................................................53 Selecting appropriate J2EE components and modeling their interactions................................55 Other considerations.................................................................................................................56 Summary................................................................................................................................................58 Chapter 4: Creating a WebLogic Environment.............................................................................................59 Overview................................................................................................................................................59 Configuring a Computer for Development............................................................................................59 Obtaining a Copy of WebLogic Server.................................................................................................60 Installing WebLogic Server...................................................................................................................60 Running the installer.................................................................................................................61 Starting WebLogic Server........................................................................................................65 Running the WebLogic Console...............................................................................................66 Shutting down WebLogic Server..............................................................................................66 Optimizing the WebLogic Server startup process for development.........................................67 Examining the environment......................................................................................................68 Adding domains for testing and production.............................................................................70 Installing JDBC Drivers.........................................................................................................................73 Selecting an IDE to use with WebLogic Server....................................................................................74 Summary................................................................................................................................................74 Part II: WebLogic and the J2EE APIs...........................................................................................................75 In This Part.............................................................................................................................................75 Chapter 5: Working with WebLogic JDBC...................................................................................................76 Overview................................................................................................................................................76 Understanding JDBC.............................................................................................................................76 JDBC versions and packages....................................................................................................76 JDBC architecture.....................................................................................................................77 Understanding WebLogic JDBC...........................................................................................................83 WebLogic and third−party drivers............................................................................................83 MultiPools.................................................................................................................................85 Table of Contents Chapter 5: Working with WebLogic JDBC DataSources..............................................................................................................................86 Clustered JDBC........................................................................................................................87 Configuring WebLogic JDBC...............................................................................................................87 Configuring connection pools...................................................................................................87 Configuring MultiPools............................................................................................................93 Configuring DataSources..........................................................................................................95 Configuring Tx DataSources....................................................................................................97 Programming WebLogic JDBC.............................................................................................................97 Obtaining connections..............................................................................................................98 Using Connections to execute Statements and process Results.............................................101 Closing connections................................................................................................................102 Summary..............................................................................................................................................103 Chapter 6: Working with WebLogic JTA....................................................................................................104 Overview..............................................................................................................................................104 Understanding Transactions.................................................................................................................104 What is a transaction?.............................................................................................................104 Transactions and the ACID test..............................................................................................105 Resources and resource managers..........................................................................................105 Local and distributed transactions..........................................................................................105 Transaction isolation levels....................................................................................................106 Transaction demarcation.........................................................................................................108 Two−phase commit and the XA interface..............................................................................109 Understanding JTA..............................................................................................................................109 JTA versions and packages.....................................................................................................110 JTA architecture......................................................................................................................110 Transaction−aware resource managers...................................................................................110 Configuring WebLogic JTA................................................................................................................112 Programming WebLogic JTA..............................................................................................................113 Programming a local transaction with the WebLogic JTS driver...........................................113 Programming a distributed transaction with the Oracle XA driver........................................116 Summary..............................................................................................................................................120 Chapter 7: Working with WebLogic JNDI..................................................................................................121 Overview..............................................................................................................................................121 Understanding JNDI............................................................................................................................121 JNDI versions and packages...................................................................................................121 JNDI architecture....................................................................................................................122 Programming WebLogic JNDI............................................................................................................125 Obtaining a reference to WebLogic’s context........................................................................125 Binding objects to the WebLogic JNDI tree...........................................................................127 Using subcontexts to organize the JNDI tree..........................................................................127 Performing lookups on objects bound to the WebLogic JNDI tree........................................128 Performing lookups against an LDAP directory.....................................................................129 Using WebLogic JNDI to Deploy Objects in a Clustered Environment.............................................133 Write an RMI proxy for the custom object.............................................................................134 Pin the custom object to one server........................................................................................134 Deploy the custom object separately to all servers.................................................................134 Summary..............................................................................................................................................135 Table of Contents Chapter 8: Working with WebLogic RMI...................................................................................................136 Overview..............................................................................................................................................136 Understanding RMI.............................................................................................................................136 RMI versions and packages....................................................................................................136 RMI architecture.....................................................................................................................138 Comparing WebLogic RMI to JavaSoft RMI......................................................................................140 Ease−of−use............................................................................................................................141 Performance and scalability....................................................................................................141 Writing Your First WebLogic RMI Application.................................................................................144 Write the remote interface......................................................................................................145 Write the server.......................................................................................................................145 Compile the remote interface and the server..........................................................................146 Generate stubs and skeletons for the server............................................................................147 Write a client that remotely calls the server...........................................................................147 Compile the client...................................................................................................................148 Configure the RMI server as a WebLogic startup class.........................................................148 Stop and restart WebLogic Server..........................................................................................150 Verify correct deployment of the RMI server........................................................................150 Run the client and test the server............................................................................................151 Using WebLogic RMI with JNDI and Multiple Clients......................................................................152 Building a server.....................................................................................................................152 Building the clients.................................................................................................................155 Invoking Client Methods from RMI Servers.......................................................................................161 Calling EJBs from RMI Servers..........................................................................................................166 Summary..............................................................................................................................................168 Chapter 9: Working with WebLogic JMS....................................................................................................169 Understanding JMS..............................................................................................................................169 JMS versions and packages....................................................................................................169 JMS architecture.....................................................................................................................169 Configuring WebLogic JMS................................................................................................................173 Creating a connection factory.................................................................................................174 Defining a file backing store...................................................................................................176 Defining a JDBC backing store..............................................................................................177 Defining destination keys.......................................................................................................178 Defining templates..................................................................................................................179 Defining a JMS server............................................................................................................180 Creating a message queue.......................................................................................................181 Creating a message topic........................................................................................................182 Programming WebLogic JMS.............................................................................................................183 Sending messages...................................................................................................................183 Receiving messages synchronously........................................................................................191 Receiving messages asynchronously......................................................................................196 Receiving messages concurrently using session pools...........................................................202 Filtering incoming messages..................................................................................................205 Browsing messages in a queue...............................................................................................207 Creating durable subscribers to topics....................................................................................208 Working with Transactions..................................................................................................................210 Working with JMS transacted sessions..................................................................................210 Working with JTA transactions..............................................................................................211 Summary..............................................................................................................................................219 Table of Contents Chapter 10: Working with WebLogic JavaMail..........................................................................................221 Understanding JavaMail......................................................................................................................221 JavaMail versions and packages.............................................................................................221 JavaMail architecture..............................................................................................................221 Configuring WebLogic JavaMail........................................................................................................226 Creating a mail session...........................................................................................................226 Adding POP3 to WebLogic....................................................................................................227 Sending Messages with WebLogic JavaMail......................................................................................228 Obtaining a mail session via JNDI.........................................................................................228 Sending a simple message......................................................................................................229 Deployment descriptor for the examples................................................................................229 Example: Send Mail servlet....................................................................................................230 Overriding mail session properties.........................................................................................232 Authenticating a mail session.................................................................................................233 Sending an enclosure using a MimeMultipart........................................................................234 Example: Send Mail servlet 2.................................................................................................234 Sending a message to multiple recipients (bulk mail)............................................................237 Navigating stores....................................................................................................................238 Retrieving and Displaying Messages with WebLogic JavaMail.........................................................241 Listing messages.....................................................................................................................242 Example: Display messages....................................................................................................242 Analyzing message flags........................................................................................................246 Deleting a message.................................................................................................................247 Expunging messages...............................................................................................................247 Example: Displaying message details.....................................................................................248 Summary..............................................................................................................................................253 Part III: Developing Web Components........................................................................................................254 In This Part...........................................................................................................................................254 Chapter 11: Developing Servlets...................................................................................................................255 Overview..............................................................................................................................................255 Understanding Servlets........................................................................................................................256 The servlet API: Versions and packages................................................................................256 The Web container and Web applications..............................................................................257 How servlets work..................................................................................................................259 When to use servlets...............................................................................................................261 The servlet life cycle...............................................................................................................261 Programming Servlets..........................................................................................................................262 Creating a simple Web application.........................................................................................262 Writing a simple servlet..........................................................................................................264 Deploying and testing the servlet............................................................................................266 Advanced Servlet Programming Techniques.......................................................................................267 Working with sessions............................................................................................................267 Working with the servlet context............................................................................................272 Dispatching requests to other resources..................................................................................273 Securing your application.......................................................................................................274 Building an Advanced Application with Servlets................................................................................277 Gathering the requirements.....................................................................................................277 Brainstorming a design...........................................................................................................278 Building the application..........................................................................................................278 Deploying the application as a WAR file...............................................................................294 Table of Contents Chapter 11: Developing Servlets Summary..............................................................................................................................................295 Chapter 12: Developing JavaServer Pages...................................................................................................296 Overview..............................................................................................................................................296 Understanding JavaServer Pages.........................................................................................................296 Product of evolution................................................................................................................296 How JSPs work.......................................................................................................................297 Model−View−Controller........................................................................................................298 Configuring WebLogic Server for JSPs..............................................................................................299 The JSP compiler....................................................................................................................299 Configuring the WebLogic Application Extension Deployment Descriptor..........................300 Deploying your first JSP in WebLogic Server.......................................................................307 Support for JSP 1.2.................................................................................................................310 Programming JavaServer Pages...........................................................................................................310 Tag conventions......................................................................................................................311 Directives................................................................................................................................311 Scripting..................................................................................................................................314 Comments...............................................................................................................................317 Implicit objects.......................................................................................................................318 Actions....................................................................................................................................320 JSP example............................................................................................................................322 Error handling.........................................................................................................................329 Debugging...............................................................................................................................330 Programming JSPs with JavaBeans.....................................................................................................332 Deploying your first JavaBean...............................................................................................332 JSP bean tags..........................................................................................................................334 JSP and JavaBean example.....................................................................................................339 Using servlets to handle requests............................................................................................341 Summary..............................................................................................................................................345 Chapter 13: Developing Tag Libraries.........................................................................................................346 Understanding Tag Libraries...............................................................................................................346 Tag handler lifecycle..............................................................................................................346 Tag handlers and the Tag Extension API...............................................................................349 Main interfaces.......................................................................................................................349 Convenience classes...............................................................................................................350 Supporting interfaces and classes...........................................................................................354 Programming and Using a Tag Extension...........................................................................................357 Programming a tag handler class............................................................................................357 Defining a Tag Library Descriptor.........................................................................................360 Configuring the WebLogic Web application deployment descriptor.....................................364 Using a tag extension within a JSP.........................................................................................365 Resolving a tag extension.......................................................................................................369 Programming a TagExtraInfo Class.....................................................................................................370 WebLogic Tag Libraries......................................................................................................................373 WebLogic JSP form validation tags.......................................................................................373 WebLogic custom JSP tags.....................................................................................................375 WebLogic EJB−to−JSP Integration Tool............................................................................................375 Summary..............................................................................................................................................376 Table of Contents Part IV: Developing EJB Components.........................................................................................................377 In This Part...........................................................................................................................................377 Chapter 14: Understanding Enterprise JavaBeans.....................................................................................378 Overview..............................................................................................................................................378 EJB Architecture..................................................................................................................................379 EJB Types............................................................................................................................................379 Session beans..........................................................................................................................379 Entity beans.............................................................................................................................380 Message−driven beans............................................................................................................380 EJB Client−Access Models.................................................................................................................381 EJB Components..................................................................................................................................381 Home interface........................................................................................................................382 Remote interface.....................................................................................................................383 Implementation class..............................................................................................................384 Deployment descriptors..........................................................................................................386 WebLogic’s EJB Container Services...................................................................................................389 Lifecycle management............................................................................................................389 Transaction support.................................................................................................................389 Persistence..............................................................................................................................391 Clustering support...................................................................................................................391 Security...................................................................................................................................392 EJB 1.1 versus 2.0................................................................................................................................392 New: Message−driven beans..................................................................................................392 Improved: CMP for entity beans............................................................................................392 Summary..............................................................................................................................................394 Chapter 15: Developing Session Beans.........................................................................................................395 Overview..............................................................................................................................................395 Common session bean uses..................................................................................................................396 Using session EJBs to model workflow..............................................................................................396 Client−server architecture.......................................................................................................396 EJB Container functionality....................................................................................................396 No synchronization issues......................................................................................................396 Inherently reusable..................................................................................................................396 Scalability...............................................................................................................................397 Comparing Stateless and Stateful Beans..............................................................................................397 Programming Session Beans...............................................................................................................399 Home interfaces......................................................................................................................399 Session EJB interfaces............................................................................................................400 Implementation class..............................................................................................................401 Stateful EJB example—AnalyzePortfolio..............................................................................413 Clustering Session Beans.....................................................................................................................419 Programming Transactions in Session Beans......................................................................................420 Summary..............................................................................................................................................420 Chapter 16: Developing Entity Beans...........................................................................................................421 Overview..............................................................................................................................................421 Understanding Entity Beans................................................................................................................421 Entity beans and persistence...................................................................................................421 Types of entity beans..............................................................................................................421 Entity bean lifecycle...............................................................................................................421 Table of Contents Chapter 16: Developing Entity Beans EJB 2.0.................................................................................................................................................422 CMP relationships...................................................................................................................422 Local interfaces.......................................................................................................................423 CMP abstract persistence schema...........................................................................................423 EJB QL...................................................................................................................................423 Entity Bean Component Files..............................................................................................................424 Programming BMP..............................................................................................................................424 Define the home interface.......................................................................................................424 Define the local home interface..............................................................................................425 Define the remote interface.....................................................................................................425 Define the local interface........................................................................................................426 Create the bean........................................................................................................................426 Create the primary key class (optional)..................................................................................434 Create value object class (optional)........................................................................................434 Create the deployment descriptors..........................................................................................436 Notes.......................................................................................................................................438 Programming CMP..............................................................................................................................438 Create the Department bean....................................................................................................438 Define the Course bean...........................................................................................................443 Create the deployment descriptors..........................................................................................447 Deployment to WebLogic....................................................................................................................458 Advanced WebLogic Features for Entity Beans..................................................................................458 Concurrency and locking........................................................................................................458 Automatic table creation.........................................................................................................460 CMP, BMP, and Other Options...........................................................................................................460 Trade−offs between BMP and CMP.......................................................................................460 Session beans..........................................................................................................................461 Java Data Objects....................................................................................................................461 Third−Party Tools................................................................................................................................461 WebGain Studio......................................................................................................................461 JBuilder...................................................................................................................................461 Cocobase Enterprise O/R........................................................................................................462 TogetherSoft Control Center..................................................................................................462 Summary..............................................................................................................................................462 Chapter 17: Developing Message−Driven Beans.........................................................................................463 Overview..............................................................................................................................................463 Understanding Message−Driven Beans...............................................................................................463 Versions and packages............................................................................................................463 How message−driven beans differ from other EJBs..............................................................463 Deciding whether to write a message−driven bean or a JMS client.......................................464 Programming Message−Driven Beans................................................................................................465 The MessageDrivenBean interface—javax.ejb.MessageDrivenBean....................................465 The message−driven bean context..........................................................................................465 Implementing business logic..................................................................................................466 Deploying Message−Driven Beans in WebLogic Server....................................................................467 Deployment descriptors..........................................................................................................467 Transaction attributes..............................................................................................................468 Deploying message−driven beans using WebLogic Console.................................................469 Building an Application Using Message−Driven Beans and XML....................................................470 The business problem: Sending medical prescriptions over a wireless network....................470

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.