Enterprise Java Programming with IBM WebSphere, Second Edition Brown, Craig, Hester, Stinehour, Pitt, Weitzel, Amsden, Jakab, and Berg... When the first edition came out, it was easy to
Trang 1Russell Stinehour, W David Pitt, Mark
Weitzel, Jim Amsden, Peter M Jakab, Daniel
Trang 2environmentsandsystematic guidance for delivering systems of exceptional performance, robustness, and businessvalue.
Coverage includes
Sum Practical introductions to J2EE, WebSphere Application Server 5.0, and Web application
Sum In-depth insight into EJB architecture,
including transactions, security, and advanced
Trang 3Sum Web services: examples and best practices leveraging WebSphere Application Server 5.x's latest enhancements
Trang 4• Table of Contents
• Examples
Enterprise Java™ Programming with IBM® WebSphere®, Second Edition
By
Kyle Brown, Gary Craig, Greg Hester, Russell Stinehour, W David Pitt, Mark Weitzel, Jim Amsden, Peter M Jakab, Daniel Berg
Trang 8Chapter 5.
Trang 9Section 8.1.
Edit the Web Deployment Descriptor
Trang 10Section 8.2.
Summary
Chapter 9.
Trang 13Chapter 13.
Trang 14Chapter 14.
XML/XSL Web Interfaces in WSAD
Section 15.1.
Strategy for Using XML/XSL for Web Interfaces Section 15.2.
Example XML/XSL Web Interface with WSAD
Trang 19Chapter 20.
Trang 20Simple CMP Entity Beans
Trang 22Section 24.5.
Summary
Chapter 25.
Trang 23Introduction to Message-Driven Beans
Trang 24Participating in a Transaction
Trang 27Implementing the Case Study User Interface Section 31.1.
User's Guide
Trang 28Section 31.2.
Summary
Chapter 32.
Constructing J2EE Web Services for WebSphere
Section 33.1.
Getting Started with Web Services
Section 33.2.
Trang 29Building Web Service Clients
Section 33.3.
Summary
Chapter 34.
Trang 31Summary
Bibliography
LICENSE AGREEMENT AND LIMITED WARRANTY
About the CD-ROMs
Index
Trang 32© Copyright International Business Machines Corporation 2003 All
rights reserved.
Note to U S Government UsersDocumentation related to restrictedrightsUse, duplication, or disclosure is subject to restrictions set forth inGSA ADP Schedule Contract with IBM Corp
Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks Where those
designations appear in this book, and Addison-Wesley was aware of atrademark claim, the designations have been printed with initial capitalletters or in all capitals
The authors and publisher have taken care in the preparation of thisbook, but make no expressed or implied warranty of any kind and
assume no responsibility for errors or omissions No liability is assumedfor incidental or consequential damages in connection with or arising out
of the use of the information or programs contained herein
IBM and WebSphere are trademarks of IBM Corporation in the UnitedStates, other countries, or both
U.S Corporate and Government Sales
(800) 382-3419
corpsales@pearsontechgroup.com
Trang 33in a retrieval system, or transmitted, in any form, or by any means,
electronic, mechanical, photocopying, recording, or otherwise, without theprior consent of the publisher Printed in the United States of America.Published simultaneously in Canada
Gary CraigTo my wife Judy, and my three terrific children, Andrew,
Trang 34Greg HesterI would like to thank my wife, Sherry, and my four children
for their patience while I worked on this book Without their love and
support, this book would not have been possible I'd also like to thankGod for the many blessings and opportunities
Russell StinehourI would like to thank my wife, Lee Ann, and my
children for their patience while I missed family functions to work on thisbook Lee Ann is a patient saint and a real asset in editing my work Iwould also like to thank Greg Hester and David Pitt for their support to
me personally It's nice to be able to work with your friends on a dailybasis I thank God for blessing me to be able to work on this book and forCrossLogic
W David PittTo my daughter Lauren for her enthusiasm in pointing out
our first edition in retail bookshelves
Mark WeitzelThis book is dedicated to Marialana, for her support,
encouragement, and Loveand for Big Sky And to Montana and Reece,for their patience and understanding when this work had to come first Ialso owe special thanks to Kyle Brown and Steve Graham for their adviceand friendship
Jim AmsdenI'd like to thank my wife Marjorie, and son Carl for their
support in this endeavor, and for their continued patience during the nextone I'd also like to thank Kyle for the wonderful opportunity to participatewith such a great team of co-authors
Peter M JakabTo my wife Mabel, my daughter Jessie and my son
Justin Without their support and encouragement this book would nothave been written And lastly, to Shadow, our black lab, who always kept
me company during the long days and nights writing this book
Daniel BergI would like to dedicate this book to my lovely wife Michelle.
She has selflessly supported me in this endeavor For this I have to saythank you and I love you I would also like to dedicate this book to my
Trang 35it possible to create an amazing J2EE development tool in WebSphereStudio
Trang 36IBM Press SeriesInformation Management
On Demand Computing Books
DB2 Books
More Books from IBM Press
Trang 39Sloan and Hernandez
Trang 40Enterprise Java Programming with IBM WebSphere, Second Edition
Brown, Craig, Hester, Stinehour, Pitt, Weitzel, Amsden, Jakab, and Berg
Trang 41I don't often find books like this one terribly interesting Books on a
specific technology, such as WebSphere, are often handy if you're usingthat technologybut they don't contain any great insights I look to thesebooks to tell me exactly which animal I need to sacrifice with which
incense in order to get a job done And this book does tell you that forthese tools
What makes this book stand out is that it doesn't stop at that As the oldadage says, a fool with a tool is still a fool If you're developing enterpriseapplications with a technology like J2EE, it's easy to be a fool There arelots of ways you can mess things up, and all the wizards and cute
graphical interfaces in the world can't save you!
So this book also tells you how to reduce your foolishness by passing ondesign advice The authors have been building these kinds of
applications since before Java was invented Kyle Brown, in particular,has more than once steered me around a nasty distributed rock So here,you don't just find chapters on how to build a servlet, and what the
transaction attributes are for Enterprise JavaBeansthey actually give yousome advice on how to design these things Rather than just give a
offs you'll need to make in putting an Enterprise Java application
simple solution, suitable for a hands-on tutorial, they talk about the trade-together As a result, you may find some of this book hard work, but byputting the effort in to understanding it you'll avoid many of the pitfalls thatregularly send these kinds of projects to the great cubicle farm in the sky
In particular, the authors put a strong emphasis on layeringcentering theirdesign around a five-layer architecture While carefully separating layersare an odd complexity for simple examples, they are a key life vest forserious enterprise applications Time and time again, I've seen teamsbegin by reluctantly following layers, shrinking from the fact that simplelogic gets separated into several different classes Then slowly, they
appreciate that the layers allow changes to be made more easily, thatlayers make a system easier to test and easier to root out bugs If there is
Trang 42architecture, even if it seems awkward to you You future self will thankyou for it
When the first edition came out, it was easy to find books on J2EE
technology but impossible to find any books giving good design advice.Indeed this was the first book that contained substantial design advice onJ2EE and as such influenced many writers of enterprise design booksitcertainly was very useful for me
The second edition builds on this by building its design advice on thework that has appeared since the first edition was published It spends alot of time showing you how to take some of the common enterprise
application patterns and implement them in J2EE As such it both
integrates and extends the work of authors like myself, and lays out morefoundations for our future work
So if you're a WebSphere developer, buy this book for its tutorial on
WebSphere, but treasure it for its design advice If you don't develop inWebSphere, or even J2EE, get this book for its design advice anyway
Martin Fowler
Chief Scientist, Thoughtworks
Trang 44The first edition of Enterprise Java Programming with IBM WebSphere
was the first book that addressed J2EE development within the context of
an application server and Integrated Development Environment Thefeedback about the first edition was very positive, and led us to concludethat we had made the right choicethat developers usually learn J2EEtechnologies and the details of an application server together and that asingle book that teaches both is valuable
Since we published the first edition, a lot has changed When we wrotethe first edition, we couldn't use J2EE in the title because IBM was notyet a licensee of the newly developed J2EE brand, even though
WebSphere Application Server implemented all of the technologies in thenascent J2EE 1.0 specification Also, when we wrote the first edition,IBM's premier development environment for WebSphere was VisualAgefor Java; that environment has since been superseded by WebSphereStudio Application Developer
In this edition we will build on the firm foundation laid in the first edition,and expand the coverage of topics to include all of the major parts ofWebSphere Application Server 5.02 and WebSphere Studio ApplicationDeveloper 5.0 Those who have read the first edition will find a lot that isnew; new readers can be assured that we've built on a strong foundation
of describing the more mature parts of J2EE, while also describing newtechnologies like Web services and the EJB 2.0 specification
Trang 45OO languages and programming environments While the details of thesystems that we have worked on have differed, they all shared somecommon features What we hope to do is to introduce J2EE, WebSphere,and WebSphere Studio by referring you to the things you already know,while showing you some best practices that we've learned in buildingclient/server and enterprise systems both before the age of Java and inthe J2EE universe.
Trang 46We set forward to achieve several goals in the writing of this book Theyare to:
Introduce developers to the primary J2EE technologies
Teach developers how to apply these technologies within the rightarchitectural framework
Demonstrate how WebSphere Application Server implements theJ2EE standard, and what advantages it gives to developers as aJ2EE application server
Demonstrate the advantages WebSphere Studio Application
Developer conveys as a platform for developing J2EE programs fordeployment on WebSphere Application Server
Of these four goals, the most important one is listed second: to teachdevelopers how to apply J2EE technologies within the right architecturalcontext It has been our experience that teaching someone a new
technology without teaching how to apply it is a terrible mistake A lot ofour time as consultants is spent getting customers out of problems thathave been created either by trying to make a technology do something itwas not intended to do or by viewing one particular technology as ahammer and all problems as nails
While we can convey some of this architectural context by teaching youthe dos and don'ts of the technologies, most of you are like usyou learnbest by doing To help you gain a feel for the J2EE technologies we willcover, you will want to walk with us through the example system that weare building and find out for yourselves how the pieces fit together It isonly by seeing the entire system end-to-end, and by working through theexample on your own, that you will start to understand how the different
Trang 47specifications
So, we want to welcome you on an adventure It's been a long, hard roadfor us in mastering these technologies, tools, and techniques We hope
we can make the way easier for you who are following us It will take a lot
of preparation and effort for you to really learn how and why to applythese technologies, and how best to take advantage of the features ofWebSphere, but we feel that the effort is worthwhile
side systems, and IBM has developed a wonderful set of tools that makethose technologies real We hope that by the time you reach the end ofthis book, you will understand and agree with why we think so highly ofthese tools We also hope that this book will enable you to start designingand building these large-scale, enterprise systems that J2EE,
J2EE is a terrific architecture for building scalable, manageable server-WebSphere, and WebSphere Studio Application Developer make
possible Thanks for coming along with us on this journey, and good luck
in reaching your destination
Trang 48Building a book like this is a team effort We would like to acknowledgeall of those team members who contributed to this book but whose
names are not mentioned on the cover Without the important
contributions from these people, this book would not have been possible.These include Keys Botzum, Jaime Niswonger, Rachel Reinitz, ScottRich, and Geoff Hambrick We would also like to thank the remarkablegroup of people who have participated as reviewers of this project andprovided very insightful feedback and help That dedicated group
consisted of Keys Botzum, John Smith, Dan Kehn, Roland Barcia, PaulIlechko, Johannes DeJong, and Bobby Woolf You have our gratitude andour thanks
Trang 49Welcome to Enterprise Java Programming with IBM WebSphere, 2nd Edition This book was designed to help you understand how to design,
build, and deploy applications based on the Java 2 Enterprise Edition(J2EE) using the IBM WebSphere family of tools and runtime This bookwas written for technical managers seeking guidance in understandingJ2EE and WebSphere; architects who wish to design scalable, secureenterprise applications; and for the day-to-day developer who wishes tocreate more robust, consistent code
You'll find our approach to be a bit different than other books Rather thansimply focusing on the bits and bytes of each technology component thatmakes up WebSphere, we take a slightly broader view We will show youhow J2EE and WebSphere combine to form an architecture and runtimesuitable for large, mission-critical applications
If you have already invested in the award-winning WebSphere Studiofamily of tools, or you are considering doing so, this book will ensure thatyou get the maximum productivity benefits WebSphere has to offer
Through hands-on examples, we will illustrate how the IBM WebSphereStudio family of tools helps you master enterprise application
development These examples will also demonstrate some of the J2EEbest practices which are intended to make your development tasks
easier, your code more maintainable, and your enterprise projects
successful Along the way, we will also provide rationale for our
approaches to building enterprise applications We will start by
discussing the importance of enterprise development, explaining thedevelopment process, and presenting the topology of properly layeredenterprise applications