WILEY Advantage Dear Valued Customer
Total Page:16
File Type:pdf, Size:1020Kb
Y L F M A E T Team-Fly® The WILEY advantage Dear Valued Customer, We realize you’re a busy professional with deadlines to hit. Whether your goal is to learn a new technology or solve a critical problem, we want to be there to lend you a hand. Our primary objective is to provide you with the insight and knowledge you need to stay atop the highly competitive and ever- changing technology industry. Wiley Publishing, Inc. offers books on a wide variety of technical categories, including security, data warehousing, software development tools, and networking - everything you need to reach your peak. Regardless of your level of expertise, the Wiley family of books has you covered. • For Dummies – The fun and easy way to learn • The Weekend Crash Course –The fastest way to learn a new tool or technology • Visual – For those who prefer to learn a new topic visually • The Bible – The 100% comprehensive tutorial and reference • The Wiley Professional list – Practical and reliable resources for IT professionals In the book that you now hold in your hands, Darren Broemmer shares best practices and lessons learned for J2EE development. As you design and build a banking application with J2EE and design patterns, you'll also utilize metadata-driven configurable foundation components to help automate much of the development for Web-based business applications. And of course, the tools and technologies used to construct the sample application are not from any one vendor, but best of breed—Jakarta Struts, Servlets, JSP, XML, EJB, UML, WebLogic, WebSphere, and many more. Our commitment to you does not end at the last page of this book. We’d like to open a dialog with you to see what other solutions we can provide. Please be sure to visit us at www.wiley.com/compbooks to review our complete title list and explore the other resources we offer. If you have a comment, suggestion or any other inquiry, please locate the “contact us” link at www.wiley.com. Thank you for your support and we look forward to hearing from you and serving your needs again in the future. Sincerely, Richard K. Swadley Vice President & Executive Group Publisher Wiley Publishing, Inc. J2EETM Best Practices JavaTM Design Patterns, Automation, and Performance Darren Broemmer Wiley Publishing, Inc. Publisher: Bob Ipsen Editor: Theresa Hudson Developmental Editor: Kenyon Brown Editorial Manager: Kathryn A. Malm Managing Editor: Pamela Hanley New Media Editor: Brian Snapp Text Design & Composition: Interactive Composition Corporation Designations used by companies to distinguish their products are often claimed as trade- marks. In all instances where Wiley Publishing, Inc., is aware of a claim, the product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should contact the ap- propriate companies for more complete information regarding trademarks and registration. This book is printed on acid-free paper. Copyright © 2003 by Darren Broemmer. All rights reserved. Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspointe Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-mail: [email protected]. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Cataloging-in-Publication Data: ISBN 0-471-22885-0 Printed in the United States of America 10987654321 This book is dedicated to my mother, Joan, and in loving memory of my father, Gary, for all of their love, support, and encouragement. Contents Acknowledgments x About the Author xi Introduction xii Overview of the Book and Technology xii How This Book Is Organized xx Who Should Read This Book xxiii Tools You Will Need xxiii What’s on the Web Site xxiv Summary xxiv Chapter 1 Building Business Applications with J2EE 1 Elements of Transactional, Web-Based Business Applications 2 The Reference Architecture 4 The J2EE Platform Approach 9 The Model-View-Controller Architecture Approach 16 Best Practices for Building Business Applications with J2EE 20 Summary 21 Chapter 2 The Business Object Architecture: Design Considerations 23 Business Objects in a Banking Application 25 Elements of Business Objects 26 vii viii Contents Design Considerations 29 Best Practices for Designing Business Objects 50 Summary 53 Chapter 3 Building Business Objects: Managing Properties and Handling Errors 55 Managing Properties 55 Value Objects and Lightweight Business Objects 83 Object Validation and Error Handling 87 Best Practices for Implementing Business Objects: Part One 102 Summary 103 Chapter 4 Building Business Objects: Persistence, Relationships, and the Template Method Pattern 105 Object Persistence 105 The Base Class as a Template 159 Overall Business Object Metadata Approach 168 Data Caching 174 Best Practices for Implementing Business Objects: Part Two 185 Summary 188 Chapter 5 The Service-Based Architecture: Design Considerations 189 Elements of Service-Based Components 193 Design Considerations 196 Best Practices for Designing Service-Based Components 207 Summary 208 Chapter 6 Building Service-Based Components 209 The Actual Service Interface 209 An Implementation for Argument Lists 210 The Session Bean as a Component Wrapper to the Service 215 Responsibilities of the Service Component 221 Update Service Examples 225 Updating Multiple Business Objects 233 The New Customer Service 234 Data Retrieval Services 240 Building Generic, Reusable Services 251 Implementing the Controller Pattern in Services 253 Best Practices for Implementing Service-Based Components 255 Summary 257 Contents ix Chapter 7 The User Interaction Architecture: Design Considerations and an Overview of Jakarta Struts 259 Elements of the User Interaction Architecture 261 Design Considerations 265 An Overview of Jakarta Struts 284 Best Practices for Designing the User Interaction Architecture 298 Summary 300 Chapter 8 Building the User Interaction Architecture 301 The Change Address Page 301 The Change Address JSP 307 The View Accounts Page 332 The New Customer Wizard 342 A Template for the Action Class 362 Web Services 369 Best Practices for Implementing the User Interaction Architecture 371 Summary 372 Chapter 9 Strengthening the Bank Application: Adding Security and Advanced Functionality 375 Application Security 375 Interesting Aspects of the Bank Application 392 Best Practices for Advanced Web Application Development 417 Summary 418 Chapter 10 Performance 421 Overall Performance Approach 421 Performance in J2EE Applications 430 Best Practices for J2EE Performance Engineering 440 Summary 442 Chapter 11 Moving toward Reuse in the Reference Architecture 443 Common Roadblocks and Corresponding Best Practices 444 Reuse in the Reference Architecture 452 The Strategic View of the Architecture 454 Best Practices for Moving toward Reuse 456 Summary 457 Bibliography 459 Index 461 Acknowledgments I owe countless thanks to my parents, John and Joan, Shirley and my late father Gary, for always being there and giving so much of themselves to help me. Without question, this book would not have been possible without everything that they have done for me. Special thanks also goes to John Abbey, Jeff Nelms, and Ken Young for reviewing the chapters, providing their insight, and contributing to this effort. John and I have collaborated for years on J2EE development and had many a lively and entertaining discussion on the topic. Likewise, Jeff and I have Ydebated the finer points of business objects many times and much of the performanceL slant in this book can be traced back to his influence. Ken’s early feedback helpedF to shape the perspective that the book eventually took. I would also like to recognize Ron Carden for his influence in my work and the development of this material. Another person who made this book pos- sible is my wife Caroline who enthusiasticallyM supported me throughout the effort. I would also like to acknowledgeA Bill Hough who unquestionably supported this effort. Special thanks to Jack Greenfield, Terri Hudson, and all the folks at Wiley for their sup- port and help in putting thisE book together. Finally, thanks to God through whom all things are made possible.T Darren Broemmer September 2002 x Team-Fly® About the Author Darren Broemmer is an application architect working on next-generation J2EE soft- ware solutions in the mortgage industry at Freddie Mac. His previous work includes architecture, development, and management experience in Internet and client-server systems implementations for consulting clients in North America, Europe, and the Middle East.