coldfusion mx developer’s handbook · is a software engineer for mindseye, inc. a longtime...

30
ColdFusion MX Developer’s Handbook Raymond Camden Arman Danesh Hal Helms Charles Mohnike Selene Bainum Guy Rish John Colasante William Baum Shlomy Gantz Kenneth N. Fricklas Matt Liotta Jen deHaan Peter deHaan San Francisco • London ®

Upload: others

Post on 12-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

  • ColdFusion MXDeveloper’s Handbook

    Raymond CamdenArman Danesh

    Hal HelmsCharles Mohnike

    Selene BainumGuy Rish

    John ColasanteWilliam BaumShlomy Gantz

    Kenneth N. FricklasMatt LiottaJen deHaan

    Peter deHaan

    San Francisco • London

    ®

    4029FM.qxd 12/20/02 8:51 AM Page iii

    File AttachmentC1.jpg

  • 4029FM.qxd 12/20/02 8:51 AM Page ii

  • ColdFusion MXDeveloper’s Handbook

    4029FM.qxd 12/20/02 8:51 AM Page i

  • 4029FM.qxd 12/20/02 8:51 AM Page ii

  • ColdFusion MXDeveloper’s Handbook

    Raymond CamdenArman Danesh

    Hal HelmsCharles Mohnike

    Selene BainumGuy Rish

    John ColasanteWilliam BaumShlomy Gantz

    Kenneth N. FricklasMatt LiottaJen deHaan

    Peter deHaan

    San Francisco • London

    ®

    4029FM.qxd 12/20/02 8:51 AM Page iii

  • Associate Publisher: Joel FugazzottoAcquisitions Editor: Tom CirtinDevelopmental Editor: Carol HenryEditor: Rebecca RiderProduction Editor: Susan BergeTechnical Editors: Selene Bainum, Raymond Camden, Arman Danesh, Kenneth N. Fricklas, Guy RishGraphic Illustrator: Jeff Wilson, Happenstance Type-O-RamaElectronic Publishing Specialist: Jill NilesProofreaders: Amey Garber, Emily Hsuan, Eric Lach, Dave Nash, Laurie O’Connell, Yariv Rabinovitch, Monique van den BergIndexer: Nancy GuentherCover Design: Caryl Gorska, Gorska DesignCover Photograph: Akira Kaede, PhotoDisc

    Copyright © 2003 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. No part of this publication maybe stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic, orother record, without the prior agreement and written permission of the publisher.

    Library of Congress Card Number: 2002112934

    ISBN: 0-7821-4029-7

    SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc. in the United States and/or other countries.

    Developer’s Handbook is a trademark of SYBEX Inc.

    Screen reproductions produced with FullShot 99. FullShot 99 © 1991-1999 Inbit Incorporated. All rights reserved.FullShot is a trademark of Inbit Incorporated.

    Internet screen shots using Microsoft Internet Explorer 6 reprinted by permission from Microsoft Corporation.

    TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by followingthe capitalization style used by the manufacturer.

    The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software wheneverpossible. Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s). The author and the publisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and acceptno liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damagesof any kind caused or alleged to be caused directly or indirectly from this book.

    Manufactured in the United States of America

    10 9 8 7 6 5 4 3 2 1

    4029FM.qxd 12/20/02 8:51 AM Page iv

  • Acknowledgments

    I ’d like to begin by thanking my wife. I would not have been able to do this without hersupport and love. I also want to thank everyone at Sybex, including Tom Cirtin, CarolHenry, and Susan Berge. This book would not have been possible without the amazing effort,patience, and skill of our co-authors. It was wonderful working with them and I hope I getthe chance again.

    –Raymond Camden

    Writing a book of this scope and depth is, undoubtedly, a collaborative effort. I must thankall my co-authors on this project. Their commitment and efforts made this project the successthat it has been. I am also grateful to the efforts of the project team at Sybex including TomCirtin, Carol Henry, Susan Berge, and the many others who helped in the task of producingthis book. Finally, my wife, Tahirih, and son Ethan deserve credit for tolerating the longhours I spent in front of the computer screen.

    –Arman Danesh

    4029FM.qxd 12/20/02 8:51 AM Page v

  • About the Authors

    Raymond Camden is a software engineer for Mindseye, Inc. A longtime ColdFusion user,Raymond is a member of Team Macromedia and a coauthor of Mastering ColdFusion MX(Sybex, 2002) and its earlier editions. He also presents at numerous conferences and contributesto online webzines and the ColdFusion Developer’s Journal. He and Rob Brooks-Bilson createdand run the Common Function Library Project (http://www.cflib.org), an open-sourcerepository of ColdFusion UDFs. Ray also formed and helped manage the Hampton RoadsColdFusion User Group (http://www.hrcfug.org).

    Arman Danesh serves as the technical manager for The Bahá’í World (http://www.bahai.org), the official website of the Bahá’í International Community, and Bahá’í WorldNews Service (http://www.bahaiworldnews.org), a ColdFusion-driven online news service.Additionally, he is the editorial director for Juxta Publishing Limited (http://www.juxta.com) and manages the ColdFusion-based websites of Landegg International University, aprivate, international university in Switzerland. He has been working with ColdFusion since1997 and maintains many other ColdFusion-based websites. Arman has written more than adozen books, including Mastering ColdFusion MX (Sybex, 2002) and its earlier editions, SAIRLinux & GNU Certified Administrator All-in-One Exam Guide, Safe and Secure: Secure Your HomeNetwork and Protect Your Privacy Online, and Teach Yourself JavaScript in a Week. He is pursuingan advanced degree in computer science at Simon Fraser University in Vancouver.

    Hal Helms is an internationally known writer, speaker, and trainer on the subject of soft-ware development. He is a member of Team Macromedia, serves on the Macromedia ClientAdvisory Board, and is a monthly columnist for the ColdFusion Developer’s Journal. Hal haswritten and contributed to several books, including Discovering Fusebox 3 with ColdFusion,Discovering CFCs: ColdFusion MX Components, and the ColdFusion MX Bible. Hal also publishesthe popular free Occasional Newsletter available at http://www.halhelms.com. You can reachhim at [email protected].

    Charles Mohnike has been using ColdFusion to develop commercial websites for morethan six years. He operates Zapt Digital Media (http://www.zapt.com), a consulting firmthat provides ColdFusion consultation, web application programming, site marketing, andelectronic publishing. Among other things, he combines his extensive background in printmedia and skills in electronic publishing to convert printed documents to digital format andserve them up on the Web. He has written several books on web publishing, including Sams

    4029FM.qxd 12/20/02 8:51 AM Page vi

  • viiAbout the Authors

    Teach Yourself Macromedia ColdFusion in 21 Days, and has contributed to Microsoft BookshelfInternet Directory, Wired Digital, and Smart TV.

    Selene Bainum has been working with ColdFusion since version 1.5 back in 1996, andwith both SQL Server and Oracle for over five years. She has created several dynamic web-based applications for notable clients, including the National Institutes of Health, Citibank,General Electric, and Schlumberger Limited. Selene has spoken at several ColdFusion con-ferences and seminars across the country, and is a coauthor of Mastering ColdFusion MX(Sybex, 2002). She created and maintains WebTricks (http://www.webtricks.com), a well-known tutorial site for ColdFusion, SQL, and JavaScript developers. Since 1998, she hasbeen a member of Team Allaire/Team Macromedia, providing assistance to hundreds ofdevelopers on Macromedia’s ColdFusion support forums. Selene is also the cofounder andchief software architect of Limited Reality (http://www.limitedreality.com), a softwaredevelopment firm specializing in applications for mobile devices and web platforms.

    Guy Rish is a freelance software developer. He holds instructor certificates from Macromediaand Rational Software and has taught in the Multimedia Studies program at San FranciscoState University. Most recently, he has been the technical editor or coauthor for various webtools books, including Mastering ColdFusion MX (Sybex, 2002), Dreamweaver MX/Fireworks MXSavvy (Sybex, 2002), and Inside Flash MX. He also writes the article series “Cold Cup O’ Joe”in the ColdFusion Developer’s Journal. Guy has spoken at numerous conferences and user groups(in and out of the U.S.) about the intersection of object-oriented programming and webtechnologies and practices.

    John Colasante is a principal at Solar Productions, Inc., a technology company based inNew York City. John has used ColdFusion to build many highly complex and scalable appli-cations for a variety of businesses. On any Sunday you will find him racing. He can be con-tacted at [email protected].

    William M. Baum is the Chief Technology Officer of GT Alliance, a Macromedia PremierVAR. As one of the youngest licensed NASD brokers in the country, Bill has had an extensiverelationship with mission-critical data and systems that he began while working at ShearsonAmerican Express (which became Shearson Lehman Brothers). Bill has also been an indepen-dent software consultant and has developed management applications for the service industry,in the areas of network engineering, design, and security. In addition, he is proficient in serveradministration, including load-balancing and clustering technologies, and in database designand administration, including load-balancing and replication, on a variety of platforms. Bill isalso an expert in cross-platform connectivity issues, directory services technologies, and appli-cation architecture. His comprehensive technical knowledge is currently at work on robustdata solutions, many of which involve ColdFusion as the primary client interface.

    4029FM.qxd 12/20/02 8:51 AM Page vii

  • viii

    Shlomy Gantz is founder and president of BlueBrick, Inc., a technology and management-consulting firm based in New York. Before that, he was founder and vice president of tech-nology for CoreActive ACG, a premier Allaire partner. He has over a decade of softwaredevelopment experience and an extensive background in database development and projectmanagement. He contributes regularly at technology and management conferences and sem-inars in the U.S. and Europe. Shlomy has worked with ColdFusion since version 1.5 and is afrequent presenter at ColdFusion conferences and user groups. He is also comanager of theNew York ColdFusion User Group. Mastering ColdFusion 4.5 (Sybex, 2000) benefited fromShlomy’s technical editing expertise.

    Kenneth N. Fricklas is Chief Technical Officer of Mallfinder Network, a web services com-pany for retail property management companies. Ken, who has been a ColdFusion user sinceversion 1.5 and a Macromedia Trainer, teaches classes on advanced ColdFusion developmentthroughout the U.S. He has presented at Internet World and the Macromedia DevelopersConference and serves on the boards of the Boulder Community Network (http://bcn.boulder.co.us) and Alt-X Publishing (http://www.altx.com). He is also a cofounder of thewebsite Disinformation (http://www.disinfo.com). In addition, Ken was a technical editorof Ben Forta’s The ColdFusion 4.0 Web Application Construction Kit.

    Matt Liotta, president and CEO of Montara Software, has been developing applicationssince he was 12, assisting faculty at Emory University. He built his first web page soon after therelease of Mosaic 1.0. Since then he has built a wide variety of ColdFusion-based applicationsfor companies, including Cignify, Consumer Financial Networks, Grizzard Communications,Williams-Sonoma, Inc., and Yipes Communications. He built gMoney’s Group TransactionSystem using an innovative XML messaging architecture similar to the now-popular web ser-vices paradigm. At TeamToolz, he designed a highly secure and scalable network architectureto support n-tier distributed applications. He has also implemented a cutting-edge contentmanagement system for DevX.

    Jen and Peter deHaan have been busy in 2002 writing, contributing to, and editing ninebooks about Macromedia products for Sybex and other publishers. The deHaans primarilywork with ColdFusion, Flash, and ActionScript. Jen mainly uses Flash MX, and is most inter-ested in remoting with ColdFusion, handhelds, and building Flash components. She holds aB.F.A. in art education, as well as honors certification in new media. She will give her firstconference presentation in 2003, and you can find her on the web at http://www.ejepo.comand http://www.flash-mx.com. Peter comes from a computer science background and hasbeen programming for the Web since 1995, focusing on using a mix of client- and server-sidetechnologies to create dynamic and interactive websites. He has used ColdFusion since 1997to create several e-commerce sites, scheduling systems, web portals, and an inventory systemusing barcode scanners.

    About the Authors

    4029FM.qxd 12/20/02 8:51 AM Page viii

  • Introduction xxvii

    Part I Managing Content and Applications

    Chapter 1: Designing and Planning a ColdFusion Application 3

    Chapter 2: Troubleshooting and Debugging ColdFusion MX Code 33

    Chapter 3: State Management in a Clustered Environment 77

    Chapter 4: The Fusebox Framework and Development Methodology 107

    Chapter 5: Developing Component-Based Applications 179

    Chapter 6: Creating Search Engines with Verity 199

    Chapter 7: Advanced WDDX 245

    Chapter 8: Application Security Techniques 285

    Chapter 9: Archives and Deployment 317

    Chapter 10: Source Code Management 333

    Part II Advanced Database Integration

    Chapter 11: Advanced SQL 349

    Chapter 12: Stored Procedures 389

    Chapter 13: Upsizing Databases to SQL Server 419

    Part III Client-Side Coding

    Chapter 14: Using JavaScript and DHTML with ColdFusion 449

    Chapter 15: Working with WAP and WML Clients 497

    Contents at a Glance

    4029FM.qxd 12/20/02 8:51 AM Page ix

  • Part IV Enhancing Performance

    Chapter 16: Performance Tuning 533

    Chapter 17: Clustering: Load Balancing and Failover 569

    Chapter 18: Caching Techniques 601

    Part V Custom Server-Side Coding

    Chapter 19: Working with Java Objects 623

    Chapter 20: Building Java Extensions 651

    Chapter 21: Building C++ Extensions 709

    Chapter 22: Using cfexecute 745

    Part VI Integrating with External Services

    Chapter 23: Integrating with Flash MX 765

    Chapter 24: Web Services 837

    Appendices

    Appendix A: Configuring ColdFusion for Java 857

    Appendix B: Understanding UML Class Diagrams 863

    Appendix C: Using the Code from This Book 871

    Index 873

    4029FM.qxd 12/20/02 8:51 AM Page x

  • Introduction xxvii

    Part I Managing Content and Applications 1

    Chapter 1 Designing and Planning a ColdFusion Application 3

    Gathering Technical Requirements 4Designing the Application Architecture 6

    Setting Up a Physical Architecture 6Designing Databases and Data Models 8Creating Tiered Applications 10Mapping the Logical Architecture 16Identifying Third Party Products 17

    Prototyping a Front End 18Naming Conventions 20

    Naming Variables/Queries/Structures/Arrays 21Naming Files/Directories 21Naming Database Tables/Columns 22

    Comments and Documentation 23Using Template Headers 24Using a Program Design Language 25

    Applying Coding Standards 26Cohesion and Coupling 26Security Considerations 29Using a Methodology 29Exception Handling 30

    Additional Planning 30Project Planning 30Backup 31

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xi

  • xii

    Version Control 31Integration 31

    In Sum 32

    Chapter 2 Troubleshooting and Debugging ColdFusion MX Code 33

    Interpreting Error Messages 34Syntax versus Logic Errors 34MX Error Messages 36

    ColdFusion MX Administrator Debug Settings 43Debugging in Dreamweaver MX 55Implementing Your Own Debugging Template 56Tag-Based Debugging 58

    The debug Attribute in cfquery and cfstoredproc 58Working with cfsetting showDebugOutput 59The cfdump Tag 59The cftrace Tag 61Logging Errors 64

    Debugging on a Live Server 67Using the Error Handlers 67Missing Pages 71Team Debugging 72

    Some Tips 75In Sum 76

    Chapter 3 State Management in a Clustered Environment 77

    State Management with ColdFusion 78Managing State over HTTP 78CF Variables for State Maintenance 80

    Clustering Fundamentals 83Clusters and Sideways Scalability 84Clustering Configurations 84

    Guidelines for Clustering in the ColdFusion Environment 85Managing CFID/CFTOKEN 85Using Session Variables Properly 86Inter- and Intra-Session State 87

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xii

  • Setting Up the Cluster Database Walk-Through 89Creating the Client Variable Database 89Setting the Network Client Connections 90Configuring the ODBC Data Source 91Configuring the CF Servers to Use the Database 96Using the Client Variable Cluster Database 99

    Putting Advanced Features to Work 100In Sum 106

    Chapter 4 The Fusebox Framework and Development Methodology 107

    A Cautionary Tale 108Current Software Development Practices 109

    Bad News for Developers 109Worse News for the Clients 110Of Methodologies and Frameworks 111

    What Is Fusebox? 113Benefits of Fusebox 113Code Reuse with Fusebox 115

    A Fusebox Overview 116Solving the Complexity Syndrome with Fusebox 117The Fusebox Skeleton 121Nested Circuits with Fusebox 123Defining Circuit Aliases 125Exit Fuseactions (XFAs) 126Nested Layouts 127Query Sims 132

    A FLiP Overview 133The FLiP Steps 135Summing It Up 159

    A Sample Fusebox Application 159In Sum 178

    Chapter 5 Developing Component-Based Applications 179

    Object-Oriented Concepts within CFML 180Instance Construction 180Encapsulation 182

    Contents xiii

    4029FM.qxd 12/20/02 8:51 AM Page xiii

  • xiv

    Inheritance 183Polymorphism 187

    Applying the Concepts 189Creating Components 189

    An Example of Applying Object-Oriented Design Concepts to a ColdFusion Application 190

    The AddressBook Story 191Identifying Components 191Abstracting Component Types 193The Record Search 194

    In Sum 197

    Chapter 6 Creating Search Engines with Verity 199

    The Basics of Verity 200Creating Collections 200Indexing Data 202Searching an Index 204The Verity K2 Server 209

    Using cfindex and cfcollection 210Creating Collections with cfcollection 211Indexing Files with cfindex 211Indexing and Searching Dynamic Query Results 213

    Creating Search Interfaces 219Presenting Useful Results 219Paging through Results 229Helping Users Build Queries 233

    Multilingual Indexing and Searching 239Multiformat Indexing and Searching 240Automating Indexing 242

    Creating an Indexing Template 242Optimizing Verity 244In Sum 244

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xiv

  • Chapter 7 Advanced WDDX 245

    Introducing WDDX 246The History of WDDX 246WDDX Concepts 247

    Exploring the Functionality of WDDX Language Tools 249CFML Tools for Working with WDDX 249WDDX and CFML Queries 250Utilities for Constructing and Displaying Packets 253Database Caching with WDDX 254

    The WDDX JavaScript Library 256Accessing the Library 256Converting CFML into JavaScript 257Working with the WddxRecordset Class 260Exploring the WddxDeserializer Class 262Using the WddxSerializer Class 266The WddRecordset Class Revisited 273

    WDDX Syndication 277Using WDDX with Moreover.com 278Slashdot.org 281

    In Sum 283

    Chapter 8 Application Security Techniques 285

    Before You Begin 286Security Basics 286

    Authentication 289Authorization 296Our Authorization Data Scheme 297Roles-Based Security in ColdFusion MX 303

    Building Secure Web Applications 307Protecting Input Points 307Security through Obscurity 312Cross-Site Scripting 312

    In Sum 315

    Contents xv

    4029FM.qxd 12/20/02 8:51 AM Page xv

  • xvi

    Chapter 9 Archives and Deployment 317

    Archiving as Part of Deployment 318Preparing and Generating an Archive 319Defining and Generating an Archive Definition 319

    Creating an Archive Definition 321Building an Archive 328

    Deploying an Archive 330In Sum 332

    Chapter 10 Source Code Management 333

    What Is Source Code Management? 334Locking and Concurrency 335Versioning and History 336Synchronization 337Parallel Projects and Forking 337

    Source Code Management Tools 337Using Dreamweaver with RDS 338SourceSafe 343WebDAV 344Other Technologies to Consider 344

    In Sum 346

    Part II Advanced Database Integration 347

    Chapter 11 Advanced SQL 349

    SQL and Database Basics 350Relational Data 350The Database Used in This Chapter 351

    Table Manipulation 353Create 353Alter 355Drop 356

    Data Manipulation 356Inserting 356Updating 360Deleting 361

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xvi

  • Querying Data 362select Statements 362Column and Table Aliases 363Unique Rows 364Functions 364Subqueries 370Joins 376Unions 378Grouping 379

    CFSQL 384Performance Testing 386

    Server-Side Debugging 386GetTickCount 387

    In Sum 388

    Chapter 12 Stored Procedures 389

    Working with Stored Procedures 390Naming Conventions 390Creating, Modifying, and Deleting Stored Procedures 391Parameters 392

    Executing Stored Procedures 394The exec Statement 395exec Syntax 395Returning Output Parameters 396

    Calling Stored Procedures from ColdFusion 397Using the cfquery Tag 397Using the cfstoredproc Tag 398

    Using cfstoredproc 400Input and Output Parameters 400Multiple Result Sets 402

    Advanced Transact-SQL 406Replacing cfset 406Replacing cfif 407Replacing cfloop 409Replacing cfoutput/cfloop Query 410

    Contents xvii

    4029FM.qxd 12/20/02 8:51 AM Page xvii

  • xviii

    Putting It All Together 412In Sum 417

    Chapter 13 Upsizing Databases to SQL Server 419

    What’s Upsizing? 420Before You Upsize 421

    Do You Need to Upsize? 421How Will Users Manage SQL Server Data? 423Choosing an Upsizing Method 423

    Using the Access Upsizing Tools 424Examining Your Database for Trouble Spots 424Running the Upsizing Wizard 429Known Problems with the Upsizing Tools 434

    Using SQL Server DTS 434Running the DTS Import/Export Wizard 435Verifying Your DTS Import 437

    Modifying ColdFusion Applications for Upsized Databases 438Modifying SQL Syntax 438Working with Identity Columns 440Other Differences between Access and SQL Server 443

    In Sum 446

    Part III Client-Side Coding 447

    Chapter 14 Using JavaScript and DHTML with ColdFusion 449

    Client versus Server Processing 450The Server: ColdFusion 451The Client: JavaScript 451

    Introducing the Document Object Model (DOM) 452Object References 453Object Components 455

    Integrating JavaScript and ColdFusion 457ColdFusion to JavaScript 457JavaScript to ColdFusion 462

    Validating Form Fields 465Server-Side Validation 465

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xviii

  • ColdFusion’s Server-Side Form Validation 467Client-Side Validation: JavaScript 469

    DHTML 482Considerations 482Image Rollovers 485Exploring Styles 488Hiding/Showing Elements 492

    In Sum 496

    Chapter 15 Working with WAP and WML Clients 497

    What Is WAP/WML? 498A Typical WAP/ColdFusion Architecture 500

    WML Browser Emulators for the PC 501WML Basics 503

    WML Document Structure 503The WML Header 505WML Syntax Rules 505Card Navigation in WML 506Intolerance for Coding Errors 510Passing URL Attributes Using & 511Accessing Variables in WML Using the $ 512

    Using WML from ColdFusion 513Setting the Content Type with cfcontent 514Determining the Browser Type with cgi.http_accept 515Working with WML Forms 516Handling ColdFusion Errors in a WAP/WML-Friendly Manner 523

    Architecture for a WML/HTML-Capable Site 525Prudent Use of cfabort 529

    In Sum 530

    Part IV Enhancing Performance 531

    Chapter 16 Performance Tuning 533

    Performance Testing 534Load Testing Software 535Using the Web Application Stress Tool 536

    Contents xix

    4029FM.qxd 12/20/02 8:51 AM Page xix

  • xx

    Performance Metrics: What to Measure 540ColdFusion MX Performance Counters 543

    Monitoring Performance: Tools and Methods 544System Monitor for Windows (Performance Tool) 544The CFSTAT Utility 545

    ColdFusion Administrator Settings 546Server Settings 546Caching 549Client Variables 551ColdFusion MX Data Source Settings 553

    Tuning the Database 555Database Design 555Indexes 556Common Query Pitfalls 557

    Profiling ColdFusion MX Templates 563Profiling Template Execution 563Using cftrace and getTickCount to Profile within a Page 563

    Tuning the Operating System 565Windows NT/2000 565Internet Information Server Configuration 566Solaris and Linux Systems 567

    In Sum 568

    Chapter 17 Clustering: Load Balancing and Failover 569

    High-Availability Systems 570Clustering 570Scalability and Reliability 571

    Software Load Balancing 572DNS 573Round Robin DNS 573ClusterCATS 574Windows Network Load Balancing 576Other Software Load Balancers 577

    Hardware Load Balancing 577

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xx

  • Creating a ClusterCATS Cluster 578Cluster Requirements 579Planning the Cluster 579Configuring DNS and IP Address Settings 581Installing ClusterCATS 583Configuring ClusterCATS 585

    Administering a ClusterCATS Cluster 588ClusterCATS Explorer 589ClusterCATS Server Administrator 590

    Testing a ClusterCATS Cluster 591Creating a Test Home Page 591Testing Load Balancing 593Testing Server Failover 594

    Content Deployment and Management 596Deployment Strategy 596Packaging the Content 597Delivering the Content 598Synchronizing the Web Servers 598

    Database Clustering Considerations 599Database Replication 599

    In Sum 600

    Chapter 18 Caching Techniques 601

    Identifying Caching Opportunities 602Handling Stale Content 604

    Using cfcache 604Adding the cfcache Tag 605How cfcache Works 607Handling Dynamic Pages with cfcache 607

    Query Caching 609Using Query Caching 611Query Caching Options 612Expiring Cached Queries 614

    Caching in RAM 617In Sum 619

    Contents xxi

    4029FM.qxd 12/20/02 8:51 AM Page xxi

  • xxii

    Part V Custom Server-Side Coding 621

    Chapter 19 Working with Java Objects 623

    Introduction to Java Objects 624What You Should Already Know about Java 625Terminology 625Required Setup Examples in This Chapter 626

    Creating Java Objects in CFML 626The Greeting Class 626Using the cfobject Tag 627Using the createObject Function 628

    Working with Java Objects in CFML 629Instantiation 629Displaying Method Results 632Static Members 632Handling Exceptions 633Class Caching 634Overloading 637Datatype Conversion 641Nested Objects 648

    In Sum 649

    Chapter 20 Building Java Extensions 651

    Introducing Java Extensions 652Rationale for Using Java CFX Tags 652What You Should Already Know about Java 653Chapter Setup 654Installing Java CFX Tags 655

    Java CFXAPI 658The CustomTag Interface 659The Request Interface 660The Response Interface 660The Query Interface 661

    Basic Java CFX 662Basic Tag I/O 662

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xxii

  • Special CFX Attributes 665Working with Queries 667

    Debugging 673The DebugRequest Class 674The DebugResponse Class 674The DebugQuery Class 675Simple Debugging 675Query Debugging 677

    Advanced Construction 679Working with Complex Data: Help from WDDX 679

    Serializing CFML Datatypes 680Serializing Query and ResultSet Objects 690

    Extending the CFXAPI 695The Transubstantiator Interface 696The ComplexRequest Class 696The ComplexResponse Class 697A Complex Look 697

    CFML Wrapped CFX Tags 699A Simple XSLT Tag 700

    In Sum 707

    Chapter 21 Building C++ Extensions 709

    Chapter Setup 710Choosing a C++ Compiler 710Chapter Sample Code 711Installing C++ CFX Tags 711

    Introducing the C++ CFXAPI 714The CCFXRequest Class 715The CCFXQuery Class 716The CCFXStringSet Class 716The CCFXException Class 717

    C++ CFX Basics 717The CFX Tag Wizard 718Basic CFX Construction 718Portable CFX Construction 724Returning Variables 731

    Contents xxiii

    4029FM.qxd 12/20/02 8:51 AM Page xxiii

  • xxiv

    Working with Queries 734Passing a Query 734Reference Altering a Passed Query 736Returning a Query 740Returning Multiple Queries 743

    In Sum 743

    Chapter 22 Using cfexecute 745

    Why Use cfexecute? 746Reasons for Using cfexecute 746

    Specifying the Application to Be Run 747Passing Multiple Arguments to Commands 750Using Timeouts to Avoid Endless Loops 753Limitations on Executing Applications 756

    Effective Use of Output 757Storing Output in a File 757Capturing the Output in a Variable 759

    cfexecute Security Issues 760Risks of cfexecute on a Server with FTP/RDS Access 761Limiting the Risks of Using cfexecute 761

    In Sum 762

    Part VI Integrating with External Services 763

    Chapter 23 Integrating with Flash MX 765

    Using Flash MX 766Building Applications Using Flash 767Putting Flash Documents Online 775An Overview of ActionScript 776

    Integration Using LoadVars 780Flash and the LoadVars Object 780Building a Mail Application Using LoadVars 782

    Flash Remoting MX 788Using Remoting for Communication 788Your First Flash Remoting Document 789RecordSets and Flash Remoting 801

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xxiv

  • Using the DataGlue Class 803Building a Dynamic Image Gallery 805Working with Server-Side ActionScript 815

    Web Services and Flash Remoting MX 820Determining the Weather Using Flash Remoting and Web Services 821Calculating Distance with Flash, ColdFusion, and Flash Remoting 826

    In Sum 835

    Chapter 24 Web Services 837

    Web Services Defined 838WSDL 838SOAP 839UDDI 839

    Interoperability Stack 839Consuming Web Services 840

    Consuming Web Services Automatically with cfinvoke 840Consuming Web Services Automatically with createObject( ) 843Consuming Web Services Manually 843The Process Flow for Consuming Web Services 845Consuming Web Services Manually with cfhttp and cfxml 846Consuming Web Services Manually with Apache Axis 849

    Producing Web Services 851Using CFCs 851The Process Flow for Producing Web Services 854

    In Sum 855

    Appendices 857

    Appendix A Configuring ColdFusion for Java 857

    JVM Requirements 858Sun Microsystems 858IBM 858HP 858

    The Administrator’s Java Settings 859Java Virtual Machine Path 860Memory Sizes 860

    Contents xxv

    4029FM.qxd 12/20/02 8:51 AM Page xxv

  • xxvi

    Class Path 860JVM Arguments 861

    Appendix B Understanding UML Class Diagrams 863

    UML 864Elements of a Class Diagram 864

    Classes 864Types of Relationships 865Packages 868Notes 869

    Appendix C Using the Code from This Book 871

    Index 873

    Contents

    4029FM.qxd 12/20/02 8:51 AM Page xxvi

  • Introduction

    I still remember the day my mother brought home our first computer. It was an Apple IIewith 64K of RAM and a lovely monochrome monitor. More importantly, it came with astack of floppy disks—most of which were games to which I became quickly addicted. Afterhaving trouble with one game in particular (for those who are old enough to remember, itwas Bard’s Tale), I decided to cheat. But I was more interested in how I could cheat and whetherit was even possible, than I was in winning the game. I soon discovered a software program thatlet me actually edit the hex of my saved game, and so began my introduction to the hexadecimalnumber system.

    Next came my first attempts at programming, using what I think was called ApplesoftBASIC. As hard as I tried, I couldn’t get even the simplest program to work. And the docu-mentation was no help. But then I accomplished a huge leap forward: I read the documenta-tion again, more slowly. I discovered that I had forgotten to hit the Enter key! I was enteringa line of code, and then hitting the spacebar until the cursor wrapped to the next line. It wasmoments like that—both agonizing and exciting at once—that got me into computer pro-gramming so many years ago. A language (both computer and spoken) is more than the sumof its parts, more than just its syntax. There is also a “way” or a style that needs to be applied.

    Much later, but when the Web was still young (and though it feels like many years ago, itreally isn’t), I did all of my web application programming in the wonderful Perl language. Atthat time, using Perl with the Web was a bit difficult—especially when it was time to wrapthe Perl code with site formatting. One day, a project came in that required database access. Iknew that Perl could do this, but I had no idea how. On a whim, I downloaded a free trial ofColdFusion 2. What a revelation! It was so easy to use that I had a fully functional site up andrunning in one week!

    ColdFusion landed in a sweet spot: It was both powerful and easy to use. In addition, itstag-based syntax melded nicely with HTML. This last point is crucial, and in a way it is thissyntax that formed the basis for both ColdFusion’s success and its resulting community ofprogrammers. When the World Wide Web started attracting attention from people outsideof the government and academia, it seemed that everyone wanted to learn HTML—frommiddle-school kids to middle-aged used-bookstore owners. You didn’t need training in com-puter science to learn HTML well enough to create compelling websites, and home pagesbegan to pop up like dandelions. Soon, people with backgrounds in medieval French poetry,

    4029FM.qxd 12/20/02 8:51 AM Page xxvii

  • xxviii

    ecology, and music pedagogy (and, yes, even computer science) found careers as web pro-grammers for companies that suddenly felt the need for a web presence.

    When the requirement for web pages—driven by the burgeoning world of e-commerce—grew from presenting static presentations to serving up data on demand, ColdFusion was exactlywhat HTML programmers needed: a language designed to access databases that worked likeextensions of good ol’ HTML. It was an easy solution to a difficult problem. (Compare aColdFusion query to a database query in ASP sometime, and you’ll see what I mean.)

    Despite its ease of use, ColdFusion—especially after the quantum leap of the new version,ColdFusion MX—is a powerful language that attracts professional programmers who needsophisticated solutions for large-scale enterprises. Here’s where this book comes in. It’s onething to learn the fundamentals of ColdFusion, and quite another to take your skills to thenext level by using ColdFusion along with other, less-easy-to-learn languages such as XML,Java, and C++. Furthermore, large applications need speed and efficiency, and you get thatwith performance turning, load balancing, and caching—topics that are only touched upon,if addressed at all, in standard ColdFusion books. Other topics, as well, are crucial for theenterprise application developer: security, troubleshooting, writing complex SQL queries,integrating Flash, and designing applications, to name just a few. All these topics and moreare found within these pages.

    Not all of this book is for everyone: It wasn’t intended to be. But every chapter is packedwith technical knowledge that gives you what you need to create serious solutions. You mightfind that one chapter alone is worth the cost of the book because of the time and frustrationyou save yourself by reading it. Most readers, however, will use various parts of this book atdifferent times, depending on the constantly changing challenges faced by enterprise pro-grammers. The mission of this book is to take you “outside the box” and provide the extraskills you need to be a successful ColdFusion developer in today’s demanding environment.

    —Raymond Camden

    Introduction

    4029FM.qxd 12/20/02 8:51 AM Page xxviii