Professional WebObjects 5 0 with Java pdf pdf

Professional WebObjects 5.0 with Java

  Michael DeMan Josh Flowers Gustavo Frederico Ben Galbraith

  John Hopkins Pero Maric Max Muller Jim Roepcke

  Bernhard Scholz Daniel H. Steinberg Thomas Termini Pierce Wetter

  with

  Douglas Bergere mmalcolm Crawford   

  Wrox Press Ltd.

Professional WebObjects 5.0 with Java

  © 2001 Wrox Press All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews. The author and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Wrox Press nor its dealers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.

  Published by Wrox Press Ltd, Arden House, 1102 Warwick Road, Acocks Green,

  Birmingham, B27 6BH, UK Printed in the United States

  ISBN 1861004311 Trademark Acknowledgements

  Wrox has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee the accuracy of this information.

  Credits

  Authors Technical Reviewers Michael DeMan John Paul Ashenfelter Josh Flowers Michael Boerner Gustavo Frederico Oliver Breidenbach Ben Galbraith Bill Bumgarner John Hopkins Robert Burns Pero Maric Patrice Collardez Max Muller David A. Coyle Jim Roepcke Dave Every Bernhard Scholz Hang Lau Daniel H. Steinberg Paul Lynch Thomas Termini Phil Powers-deGeorge Pierce Wetter Patrick Robinson Contributing Authors Production Manager Douglas Bergere Liz Toy mmalcolm Crawford

  Production Coordinator Technical Architect

  Pip Wonson Chanoch Wiggers

  Production Assistants Technical Editors

  Paul Grove John R. Chapman Natalie O’Donnell Tabasam Haseen Abbie Forletta Christian Peak Mohammed Rfaquat

  Indexers Adrian Axinte

  Category Manager Louay Fatoohi

  Proofreader Agnes Wiggers

  Author Agent Velimir Ilic Cover Design

  Dawn Chellingworth Project Administrators Simon Brand About the Authors

Michael DeMan

  Michael DeMan is a senior consulting engineer specializing in enterprise software development and systems integration using WebObjects and J2EE technologies. He has been developing scalable multi-tier Internet applications since 1996, and has worked with object-oriented technologies since 1990.

  Michael is the founder of Gemini Solutions, Inc., a software services and solutions company, and also co-founded the Pattern Research Foundation, a non-profit organization that provides technical assistance to other non-profit organizations. Michael graduated with his Bachelor's degree in Philosophy from Western Washington University (WWU) in 1994. He also attended the computer science graduate program at WWU before beginning work in the commercial sector.

  Michael can be reached at michael@geminisolutions.com

  Josh Flowers

  BIO NOT RECEIVED YET

  Gustavo Frederico

  After nine years trying to learn how to play the violin, Gustavo Frederico started studying Computer Science at Universidade Federal do Rio Grande do Sul (Brazil) in 1992, where he graduated. Gustavo now lives in Ottawa, Canada, and has survived four winters, so far. He develops web- based solutions in Java for e-commerce projects at MONTAGE.DMC eBusiness Services, a division of AT&T Canada.

  To my wife, Louise.

  Ben Galbraith

  Ben Galbraith first started programming when he was eight years old. He spent a considerable amount of his youth as a hobby programmer. In his late teens, he was hired by a Silicon Valley computer manufacturer to develop Windows-based client-server applications. In 1995,Ben began developing for the web and fell in love with Unix, VI, and Perl.

  After some years as an Internet consultant, Ben now leads the Java development team at an insurance company in Salt Lake City. He regularly lectures, evangelizes, and gives classes on Java technology.

  To my wife Jessica.

John Hopkins

  Native of Fort Worth, Texas, I earned my B.S. in Mathematics at Texas Christian University, then started my programming career in the local aircraft industry at General Dynamics, where I met my wife. From there, we worked together in the electronic music industry in Australia, for Fairlight Instruments, Pty Ltd. on a music printing system. After a year of tutoring college-level mathematics, I moved on to desktop applications for the Mac OS, first with Data Tailor, then The SU5 Group, helping with the creation of Trapeze, Persuasion, DeltaGraph, FaxSTF Network and Meeting Maestro, and products for VariLite's theatrical lighting systems.

  For the millennium, I helped scour UNIX system code for Y2K bugs. Then, I helped implement web sites, using WebObjects and J2EE technologies and Tensor Information Systems. I also taught classes in Java and XML, wrote for the company newsletter on programming and mathematics, and wrote a case study for Java Report. I am studying current and upcoming XML and peer-to-peer computing technologies for virtual supercomputing and cycle selling projects. In my spare time, I help Dr Laurence Furr with Trinity Lutheran Church's music activities: singing, playing piano, organ, violin and hand bells, composing and arranging. I also play violin in the Fort Worth Civic Orchestra. Occasionally, I get a jazz piano gig, either live performance or recording session (check out the Paul Warren CD "Sweet Deliverance"). I try to keep up with developments in physics with the help of my friend, Dr Bruce Miller at TCU. Most of all, I enjoy spending time with my wife, Darlene – a fellow software engineer and musician, and my daughter, Elise – a fellow author and musician.

  Pero Maric

  Pero has been working with WebObjects since version 4.0 and has been developing Java applications since 1997. Currently he is a Technical Support Lead at MONTAGE.DMC (a Division of AT&T Canada), where he mentors and assists team members in providing support for WebObjects applications at Nortel Networks.

  Pero's interests include application servers, long Ultimate games, cycling and squash.

  Thanks to all the editors, authors and reviewers at Wrox Press for making this book possible. Also, a big thanks goes out to Samantha for her support.

Max Muller

  Max Muller was raised in the Midwest and first discovered the joys of programming while attending the Oklahoma High School for Science and Mathematics. Being a chronic overachiever, in four years at Georgetown University Max completed both a Bachelor of Science, majoring in Computer Science and Economics, and a Masters in Economics, focusing on mathematical modeling. At Georgetown, Max competed on various mathematical modeling and ACM competitions. It was also at university that Max first started working with WebObjects in his spare time, before taking an internship on a large Department of Defense WebObjects project in his junior year. After graduating, Max moved to the bay area and worked for several dotcoms before finding the perfect combination in NetStruxr, a corporate real estate procurement and transaction platform. Since starting at NetStruxr and learning the secrets of DirectToWeb from the original author and CTO of NetStruxr, Patrice Gautier, Max has become an outspoken advocate of building template and rule based user interfaces with WebObjects. Max has written articles for online publication Stepwise, as well as giving presentations at the Bay Area NeXT Group. In his spare time Max enjoys writing, reading, sailing and traveling. Max lives in San Jose, California with his wife, and fellow WebObjects developer, Angela and their two hybrid Serval cats.

  Jim Roepcke

  Jim Roepcke is an experienced WebObjects developer from Canada currently experiencing WO nirvana at NetStruxr in San Francisco. Having lost much hair fighting with Active Server Pages in his early years developing web applications, Jim appreciates the refreshingly sane approach WebObjects takes.

  Jim is a life-long Edmonton Oilers hockey fan, and a lover of silly British comedy – Red Dwarf and Black Adder are his favorites. Jim wants to thank his daughter Cyan and wife Cheryl for putting up with his neglect as he toiled on this book, and WROX for not asking for a full-body shot for the cover. ;-)

Bernhard Scholz

  I am currently working as a Consulting Engineer for Apple Germany, specializing in WebObjects and networking technologies. After studying Computer Science at the Technische Universität München I signed a contract with the biggest WebObjects company in Germany, joining the team for two years before I finally joined Apple. Before this time I was also supporting the NeXT community by administrating the Peanuts-FTP-Server, which I'm told is still of high value for many people who love their black NeXT-boxes. I've used Amiga, Windows32, X11R6, NEXTSTEP, OpenStep, WebObjects, Linux, Solaris, HP- UX, VMS and other technologies trying to learn the best from them. Currently I'm focusing on OO Design, project management, WebObjects and Mac OS X (especially server versions). I have used WebObjects from its early development and I believe it is one of the most beautiful pieces of software currently available.

  

For this book I want to thank my parents for giving me all the support and freedom to form

my life as I wanted it to be. I hope they are happy with the current result.

Daniel H. Steinberg

  Daniel Steinberg is the Director of Java Offerings for Dim Sum Thinking in Cleveland, Ohio. He has covered Java on the Mac for the last five years for JavaWorld magazine, writes a monthly column for the O'Reilly Mac DevCenter, and is a regular contributor for IBM's developerWorks. Daniel is a recovering Mathematician who runs seminars in the latest interest areas in Computer Science for area colleges trying to stay current. He is a non-apologetic Mac fan who curses whenever he has to spend too much time on his Windows box. His favorite moments are cooking for and with his wife and kids.

Thomas Termini

  Tom Termini is a founder and managing director of BlueDog Inc. (www.bluedog.net), the premier WebObjects application service provider. Tom has been a NeXT and Apple developer since 1990, with clients from the World Bank, the U.S. Government, Volkswagen of America, Lockheed Martin, Allied Irish Banks, Philip Morris Companies, among others.

  Tom processes with an eye towards innovative user interfaces. His ongoing goal: find new ways for information technology to serve business needs. In the 1980s he trail blazed multimedia application design with database integration, and founded the new-media firm Enigma Concepts Inc. Tom was born in Washington, DC; graduated in 1986 with a degree in Pre-17th Century English Literature from the University of Maryland, and was awarded an M.B.A. in 1993 from Loyola College of Baltimore.

  When not pushing a mouse, Tom explores the backcountry on his mountain bike with Indy, the Australian Cattle Dog mascot of BlueDog.

Pierce Wetter

  Pierce Wetter lives in beautiful Flagstaff, Arizona surrounded by one billion pine trees. When not shoveling snow; visiting the nearby Grand Canyon; making fun of "flatlanders"; or reassuring people that Arizona does get snow (at least at 7,300 feet it does); Pierce works at Marketocracy (www.marketocracy.com) doing WebObjects programming.

  Prior to trying to take over Wall Street, Pierce worked as a WebObjects consultant for companies like Apple and Time/Warner. He was very excited about contributing to this book, because he feels that WebObjects is the best web application platform, but the Apple documentation stopped just short of demonstrating how powerful WebObjects can be.

  Introduction

What is WebObjects?

  WebObjects 5 is the powerful new release of Apple's award-winning application server, built from the ground up in Java. WebObjects was the first object oriented application server, and year on year remains the top application environment for many developers, offering a suite of tools for developing scalable three-tier web and standalone applications.

  This mature product offers easy to develop and deploy distributed Java applications, and has powerful and simple data access, templating capabilities, and session management that allow the developer to get on with the task of writing business logic. In addition, as WebObjects is based on java, it can now run on virtually any server making it easily accessible to millions of Java programmers. In addition WebObjects application development is in Java and WebObjects also integrates with other Java-based solutions such as EJB containers, servlets, and web services.

  The combination of a Java runtime with advanced native tools for Mac OS X and Windows 2000 makes WebObjects an obvious environment for customers needing rapid development of flexible, scalable web applications.

It's An Application Server

  Static web sites store all their content, presentation, and navigation in HTML files. Not only does this make it very difficult for web masters to do rapid and complex updates, it also means that every visitor sees exactly the same information in exactly the same way. Some rising new standards such as XML help address some shortcomings, but a different approach has been around since the early days of the Web – the application server. Evolving beyond client-server architecture developed in the 1980s, application serving addresses how to create, maintain, and distribute dynamic information.

Introduction

  An application server typically stores content in a database and employs some form of scripting to create web pages dynamically. While this approach allows web developers to create sites that have easily updated content, flexibility comes at the price of greater complexity. This complexity increases development time and makes a web site harder to maintain.

  WebObjects improves on the traditional application server architecture by cleanly separating the database access layer, the application-specific Java code, and the web page presentation layer. Supported by rich object-oriented frameworks and an object-relational mapping engine, this architecture is the foundation of the powerful technologies in WebObjects. Web components enable the efficient generation of HTML, XML, or SMIL from reusable templates. WebObjects provides an abstracted layer for database access via Enterprise Objects. When an HTML interface just won't do, Java applets or multi-tier Java client applications are supported.

It's A Development Environment

  WebObjects provides an integrated suite of graphical tools to speed application development. Unlike other graphical tools that generate hard-to-read code, WebObjects dynamically binds application components with XML-like data structures, greatly simplifying application maintenance. Application components can be reused, and incremental development is easy – reducing total cost of ownership over the life cycle of an application. At the heart of the WebObjects development process is Project Builder, a multilanguage integrated development environment used extensively by Mac OS X developers. In addition to helping edit, compile, and debug WebObjects applications, Project Builder organizes all your components (including localized resources for multiple languages); provides templates and assistants covering the common application types; and, on Mac OS X, integrates with source code repositories such as CVS. Perhaps the most powerful tool, EOModeler manages the object-relational mappings used by the data access layer, and can even help you organize your business logic. It can also be used to manage your database schema, either by reverse engineering a model from the schema or by using a new model to create the schema. In EOModeler, graphical entity-relationship diagrams represent the object relationships created and maintained by data access frameworks. Although WebObjects uses standard HTML that can be edited with any text editing tool, a comprehensive layout tool called WebObjects Builder is also included that can manage the associated mapping files. WebObjects Builder can be used for general HTML layout and provides the usual preview mode and drag-and-drop palettes common in such tools. A developer can also drag a dynamic element into the web page, specify the mappings, and set the properties. WebObjects Builder automatically generates the appropriate HTML and mapping information. One widely used technique that takes advantage of Apple's integrated development environment is to have a web designer focus on the aesthetics of the user interface design as represented in dynamic HTML, JavaScript, and Flash, while letting a programmer focus on writing the associated Java code to implement the mapped methods.

Who Uses WebObjects?

  Many organizations are using WebObjects for both global internet and corporate intranet applications, including reservation systems, virtual catalogs, customer services, groupware, and several migration projects from Windows applications to the web.

Introduction

  A combination of outstanding technology and innovative partners has attracted some of the best-known brands in the world to WebObjects. Fortune 500 companies have trusted it for years for Intranet application development, personalized Internet content delivery, and e-commerce. WebObjects-based solutions in this market include cutting-edge Internet sites such as the BBC, AAA, and MCI/WorldComm. WebObjects is also being used in powerful online applications for asset management or customer services, including tracking United Parcel Service packages and providing online services to U.S. Postal Service customers. FannieMae and other financial institutions have built large, complex, and mission-critical applications with WebObjects.

  In higher education, WebObjects is used by universities to create portals, labs, and administrative solutions, such as a student information site at the University of Michigan. Many universities are looking to use WebObjects as the basis of their web development courses, allowing students (or continuing education professionals) to create complete web applications in a single semester.

  WebObjects is the basis of some of the most important publishing solutions for creative markets. Most notable is Adobe's InScope software for publishing workflows, which is built entirely around WebObjects.

Who Is This Book For?

  Read this book if you want to develop and manage WebObjects applications. You'll need to have a beginning-to-intermediate understanding of Java. It also helps to have an understanding of HTML, JavaScript, and the workings of relational databases. WebObjects handles much of the work for you, but sometime you need to get your hands dirty – for example, writing some original SQL code for a database search, although this is rare. This book is meant to supplement the excellent on-line documentation that accompanies the development suite. Having a Java reference handy is a good idea as well: try Wrox's Beginning Java 2 by Ivor Horton, Thinking in Java by Bruce Eckel (published by Prentice Hall) or O'Reilly's Java in a Nutshell by David Flanagan.

  This book is a roadmap because as you follow the examples paired with explanations of theory, you will come to understand how to navigate application development and serving with WebObjects. When you are finished, you will be able to create dynamic applications that allow users to find, view, and modify data from back-end databases, accessible in any browser.

The History of WebObjects

  When Tim Berners-Lee invented the World Wide Web using NeXTSTEP development tools while working at CERN (the European Organization for Nuclear Research, the world's largest particle physics center), the idea was to create a vast network of information and hypertext that would be an easy but powerful global information system.

  NeXTSTEP employed a number of powerful design patterns that greatly simplified the creation of rich, graphical applications. This ease of use led to its adoption by a number of large enterprises that wanted to rapidly create sophisticated database applications. To better serve this market, NeXT created a technology known as Enterprise Objects, the first commercially successful object-relational modeling framework. Because Enterprise Objects abstracted away all the work of database access, it quickly became the technology of choice for financial institutions creating sophisticated client/server applications.

Introduction

  In 1995, NeXT realized that the World Wide Web would soon become the dominant format for client/server applications. Therefore, NeXT programmers applied that same object-oriented know-how to create a sophisticated set of frameworks for managing HTTP requests and HTML generation. In January 1996, NeXT announced WebObjects 1.0, the world's first object-oriented web application server. The power of WebObjects, leveraging the strengths of Enterprise Objects, quickly made it the dominant product in NeXT's portfolio. In 1997, NeXT was acquired by Apple, primarily for its engineering talent and the UNIX-based operating system technology that eventually became the core of Mac OS X. WebObjects played a key role at Apple during this time, driving Apple's public Internet efforts such as the Apple Store and iTools. A combination of direct sales and a high price (up to $50,000 for a multi-CPU deployment license) kept WebObjects out of the reach of the vast majority of Apple developers. Apple announced in May 2000 a reduction of the price of WebObjects to less than $700 for both developer tools and a full deployment license, which would be sold via both the Apple Store and traditional retail channels.

  Why Should I Choose WebObjects?

  There are several competing products similar to WebObjects. Most offer similar-in-scope system-level services, website creation tools, integrated development environments, and datasource conductivity features. Most notable are SilverStream, WebSphere, and Bluestone Software's Sapphire/Web. According to Network Computing magazine, if developers are going to spend most of their time with the integrated development environment, good tools and a clean, efficient process will pay for themselves a hundred times over in improved productivity and reduced development, deployment and maintenance costs.

WebObjects Uses Java

  In its first several releases, WebObjects was written in Objective-C, one of the original object-oriented languages that provided much of the inspiration for Java. As Java became more important for server- side development, on-going iterations of WebObjects added Java APIs. With this version, the power of WebObjects is now fully accessible to Java programmers. The WebObjects runtime is written to the Java 2 Platform, allowing it to run virtually anywhere. Now that WebObjects is available on Java, it is instantly familiar and accessible to the millions of programmers who prefer that language. The use of standard Java also makes it easy for WebObjects to interoperate with other Java solutions, such as EJB containers, servlets, ORBS, and web services. Apple chose a programming language that is of general purpose, easily available, and widely used. Java fits these requirements quite well: it is a relatively simple language supporting most aspects of object- oriented design. Java also has several modern technologies designed into the language (memory management, for example); and the high demand for Java programmers indicates the success people have with the language.

Why Should We Use Object-Oriented Programming?

  Simplify and streamline. That's why object-oriented programming makes sense. Key to the concept of object-oriented software development is the definition of classes and methods. This process is independent from a specific programming language – object-oriented design deals with general techniques and notations about how to derive the software components that best model a given problem. A simple rule of thumb might help: Write a quick and dirty problem specification. Nouns are candidates for classes, while verbs are candidates for methods. WebObjects provides an easy-to-use environment to implement object-oriented coding with Java.

  Introduction

  WebObjects efficiently generates HTML, XML, or SMIL output from reusable templates separating the presentation layer from business logic and the data model, allowing each piece to evolve independently. WebObject's object-relational mapping engine means the developer writes all the business logic using objects. WebObjects automatically fetches, caches, and updates data from any JDBC 2.0 database or

  XML stream, even saving the developer from writing SQL statements. In a sense, WebObjects can extend the concept of the model-view-controller paradigm.

  WebObjects is Well-Designed

  In a review of the top application servers, Network Computing magazine said:

  "The best enterprise-class product is Apple's WebObjects, a true powerhouse with its elegant

interface and architecture. It's well designed from top to bottom, and full of useful architectural and

design features that make it the best of breed in this fast-changing arena. Its IDE is clean and consistent, and encourages true code reuse and good object-oriented design."

  Here are some of the reasons that the WebObjects architecture gets such rave reviews:

  Friendly Development Tools

  WebObjects incorporates a family of user-friendly project development and management tools. One of the tools available is Monitor, itself a WebObjects application that manages all the different WebObjects applications and the servers on which they are running. Monitor is used to start and stop instances, generate statistics, and configure how applications are run. Other tools enable you to record and play back sessions for both functional and stress testing.

  Plethora of Deployment Options

  WebObjects deploys on any Java 2 Platform, Standard Edition version 1.3 runtime environment, using JDBC 2.0 for universal database connectivity. WebObjects applications run on Mac OS X Server, Windows 2000 Pro, Solaris 8, even Linux. WebObjects applications are designed to use JDBC 2.0 for universal database connectivity, and is widely used with Oracle 8i, FrontBase, OpenBase, and MySQL.

  With Monitor, you easily add servers using a variety of prebuilt scheduling mechanisms. In your system design, you can add more web servers to handle more static web connections. You can add more application servers to handle more instances. You can also add more memory to application servers to add more instances on that processor. You can also add multiple database servers to off-load processor- intensive actions. This means that WebObjects is scalable. WebObjects is also robust. WebObjects Monitor automatically restarts instances and connections as needed. Larger application size and better response can be addressed easily by adding more memory to the server .

  Standards-Based

  WebObjects incorporates the latest standards. For example, WebObjects has the Xerces parser from the Apache Software Foundation integrated directly. This allows developers to import and export XML datastreams as well as supporting SMIL for multimedia applications. Introduction Wide Development Community

  WebObjects development and deployment is cross-platform-enabling development on both Mac OS X and Windows 2000 and deployment on any Java 2 Platform, Standard Edition v1.3 system. But WebObjects 5 is especially designed to take full advantage of the power of Mac OS X, and is bundled as part of the newest release of Mac OS X Server.

  Competitive Pricing

  WebObjects also packs a powerful price-to-power ratio, with deployment costing less than $700 per processor. Coupled with the ease of development for quicker coding and easier maintenance, developers will realize a lower total cost of ownership.

  Installing WebObjects 5.0

  Given that WebObjects 5 is a great environment to develop dynamic web applications in, hopefully you'll want to install it and give it a try. The first installation step is to choose whether you wish to simply develop WebObjects applications, or if you want to deploy them for use on the World Wide Web as well. Apple implement this choice as two installation options:

  ❑ WebObjects Developer ❑ WebObjects Deployment

  As we mentioned before, you also have the luxury of being able to develop and deploy WebObjects on Mac, Windows 2000, and to deploy on Solaris too.

Installing on a Mac

  To use WebObjects 5 on a Power Macintosh running Mac OS X, you will need at least 128 MB of RAM and 500MB of available hard disk space. Although not essential if you are simply developing applications, a web server (such as Mac OS X Server) would be pretty handy too, so that you can learn how to deploy your applications.

  The first step for installation is to insert the WebObjects 5 for Mac OS X CD-ROM into the appropriate drive of your Mac. You should navigate to the Developer folder on the disk. Click on either the WebObjectsDeveloper.pkg or WebObjectsDeployment.pkg depending on your preference. This starts up the installer.

  If you haven't logged on as the administrator (root) on the machine then you will have to click on the padlock icon. A window will pop up asking for the administrator username and password, then press Continue

  . The next screen is the license which you read, on pressing the Continue another window will appear and you have a choice whether to accept the license agreement or not. Assuming you have agreed to the license, you will be given the choice of which volume on your hard drive that you want to install WebObjects on, after choosing click Continue. You can then choose to have the default Easy install, which is recommended, or by clicking on the Custom button, you can decide on installing only parts of WebObjects.

  Introduction

  The Install button will take you to the next stage where you enter the license key; this is on the front of your CD-ROM envelope. You then click install and then OK on the new window that appears. The installation will start; after WebObjects has installed you will have to restart your computer.

  Installing on Windows

  To install in the Windows environment you'll need Windows 2000 with at least 500MB of available disk space. As with developing on the Mac, you would be strongly advised to have a web server such as Microsoft's IIS installed as well, in order to test application deployment. Before you start the installation, make sure that you are logged into an account that has Administrative privileges, otherwise you will not be allowed to install new software. Pop the WebObjects 5 for Windows

  

and Solaris CD into your computer's CD-ROM drive, and navigate to the Developer or Deployment

folder on the disk (depending on your preference).

  You should see a Windows folder inside this, which contains a SetUp.exe icon. Click on this; the WebObjects installer should start up. Click on Next and read the subsequent license agreement. Provided you agree with its terms, click Yes. In the subsequent dialog box you will be asked to enter your name and the name of your company, as well as a valid license key (which can be found on the CD-ROM envelope). When you have entered this information, click Next. The next choice to be made is whether you require a Typical installation or a Custom installation. As usual, a typical installation is strongly recommended unless you really need to customize. When you click on Next, you will be asked to Choose Destination Location. This is where you get to specify the WebObjects root directory... you can either accept the default or click on Browse and specify a different (or new) folder.

  

A few words of warning: don't install WebObjects into a system-related folder such as

WinNT, and make sure the path to the root directory doesn't exceed twelve characters

in length, or you may encounter problems with the software.

  Next you will be asked for the path to your web server's CGI Bin (or Scripts) folder, and then the path to the root directory of the web server (for example wwwroot for IIS). The final option to specify is the program group for the WebObjects software. When you have specified these options, the installer should install the WebObjects Developer components; this process will take a few minutes. Once installation is complete, you should restart your computer.

After Installation

  You will probably want to use a database with your applications too. WebObjects comes with the OpenBase Lite relational database system, although Oracle 8i is the data source that is officially supported for WebObjects.

  Before beginning, you should install and test WebObjects on your development platform. Run the 'Hello World' example to ensure everything installed properly. Keep an eye on permissions settings for the directories containing your work, as well as those containing the WebObjects application and framework files. Introduction Conventions Used In This Book

  To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book. For instance:

  These boxes hold important, not-to-be forgotten information, which is directly relevant to the surrounding text.

  While this background style is used for asides to the current discussion.

  As for styles in the text: ❑ When we introduce them, we highlight important words.

  ❑ We show keyboard strokes like this: Ctrl-A. ❑

  We show filenames and code within the text like so: doGet() ❑ Text on user interfaces and URLs are shown as: Menu. We present code in three different ways. Definitions of methods and properties are shown as follows: protected void doGet(HttpServletRequest req, HttpServletResponse resp throws ServletException, IOException ) Example code is shown like this:

  In our code examples, the code foreground style shows new, important, pertinent code while code background shows code that is less important in the present context, or has been seen before.

  Customer Support

  We always value hearing from our readers, and we want to know what you think about this book: what you liked, what you didn't like, and what you think we can do better next time. You can send us your comments, either by returning the reply card in the back of the book, or by e-mail to feedback@wrox.com . Please be sure to mention the book title in your message.

How to Download the Sample Code for the Book

  When you visit the Wrox site, http://www.wrox.com/, simply locate the title through our Search facility or by using one of the title lists. Click on Download in the Code column, or on Download Code on the book's detail page. The files that are available for download from our site have been archived using WinZip. When you have saved the attachments to a folder on your hard-drive, you need to extract the files using a de- compression program such as WinZip or PKUnzip. When you extract the files, the code is usually extracted into chapter folders. When you start the extraction process, ensure your software (WinZip, PKUnzip, etc.) is set to use folder names.

  Introduction

Errata

  We've made every effort to make sure that there are no errors in the text or in the code. However, no one is perfect and mistakes do occur. If you find an error in one of our books, like a spelling mistake or a faulty piece of code, we would be very grateful for feedback. By sending in errata you may save another reader hours of frustration, and of course, you will be helping us provide even higher quality information. Simply e-mail the information to support@wrox.com, your information will be checked and if correct, posted to the errata page for that title, or used in subsequent editions of the book.

  To find errata on the web site, go to http://www.wrox.com/, and simply locate the title through our Advanced Search or title list. Click on the Book Errata link, which is below the cover graphic on the book's detail page.

  E-Mail Support

  If you wish to directly query a problem in the book with an expert who knows the book in detail then e-mail support@wrox.com, with the title of the book and the last four numbers of the ISBN in the subject field of the e-mail. A typical e-mail should include the following things:

  ❑ The title of the book, last four digits of the ISBN, and page number of the problem in the Subject field.

  ❑ Your name, contact information, and the problem in the body of the message. We won't send you junk mail. We need the details to save your time and ours. When you send an e-mail message, it will go through the following chain of support:

  ❑ Customer Support – Your message is delivered to our customer support staff, who are the first people to read it. They have files on most frequently asked questions and will answer anything general about the book or the web site immediately. ❑ Editorial – Deeper queries are forwarded to the technical editor responsible for that book.

  They have experience with the programming language or particular product, and are able to answer detailed technical questions on the subject. ❑ The Authors – Finally, in the unlikely event that the editor cannot answer your problem, he or she will forward the request to the author. We do try to protect the author from any distractions to their writing; however, we are quite happy to forward specific requests to them. All Wrox authors help with the support on their books. They will e-mail the customer and the editor with their response, and again all readers should benefit. The Wrox Support process can only offer support to issues that are directly pertinent to the content of our published title. Support for questions that fall outside the scope of normal book support, is provided via the community lists of our http://p2p.wrox.com/ forum.

  p2p.wrox.com

  For author and peer discussion join the P2P mailing lists. Our unique system provides programmer to

  programmer™

  contact on mailing lists, forums, and newsgroups, all in addition to our one-to-one e-mail support system. If you post a query to P2P, you can be confident that it is being examined by the many Wrox authors and other industry experts who are present on our mailing lists. At p2p.wrox.com you will find a number of different lists that will help you, not only while you read this book, but also as you develop your own applications. Particularly appropriate to this book is the pro_webobjects list. To subscribe to a mailing list just follow these steps: Introduction

  1. Go to http://p2p.wrox.com/.

  2. Choose the Web Apps category from the left menu bar.

  3. Click on the pro_webobjects mailing list you wish to join.

  

4. Follow the instructions to subscribe and fill in your e-mail address and password.

  5. Reply to the confirmation e-mail you receive.

  ❑ Use the subscription manager to join more lists and set your e-mail preferences.

Why This System Offers the Best Support

  You can choose to join the mailing lists or you can receive them as a weekly digest. If you don't have the time, or facility, to receive the mailing list, then you can search our online archives. Junk and spam mails are deleted, and your own e-mail address is protected by the unique Lyris system. Queries about joining or leaving lists, and any other general queries about lists, should be sent to listsupport@p2p.wrox.com.

  Introduction

  

Introduction

WebObjects Architecture

  WebObjects and its associated frameworks are an extremely powerful and flexible way to design, develop and deploy a variety of applications. First and foremost WebObjects is an application server. As an application server, WebObjects can not only deliver applications through to a traditional HTML- based presentation layer, but also to Java clients distributed either as downloadable applets to be executed in the client browser or as full blown java desktop applications. A "classic" WebObjects application is one that only uses the core functionality that WebObjects was intended to deliver when it was first released in 1996: database-driven dynamic HTML. More recent versions of WebObjects have built upon this core functionality, and introduced more advanced features. In this chapter we will discuss key architectural concepts that apply to all WebObjects applications. This will provide you with a foundation for understanding WebObjects as a whole. We will also briefly introduce you to some of the more advanced features for WebObjects 5.0, in preparation for later chapters where we will cover these features in depth.

  In the first part of the chapter, we will gently review the general architecture of WebObjects by covering the following subjects: ❑ WebObjects and the Request-Response Cycle ❑ Multi-Tier WebObjects Architecture

  Then we will turn our attention to data persistence in WebObjects, which is handled by a group of classes called the Enterprise Objects Framework (EOF). In particular, we will discuss the following aspects of EOF:

  ❑ Advantages of Using EOF ❑ EOF Architecture and Layers ❑ EOF Classes Towards the end of the chapter we will briefly review advanced WebObjects topics, such as: ❑ Direct To Web ❑ Java Client ❑ Direct To Java Client

  We will finish off by looking at the sources of WebObjects documentation available to us, and other tools that we can turn to for help when we are developing in WebObjects. Let's begin, then, by looking at the process of sending a client request to a WebObjects application and receiving a response back from the application, which will allow us to get a useful overview of the WebObjects architecture.

The Request-Response Cycle

  In this section we will briefly cover the request-response cycle, and how this applies to WebObjects applications. Fundamentally the WebObjects request-response loop provides an event-driven programming model, except that the events are HTTP requests rather than mouse clicks, keyboard strokes or other more traditional IO. A client passes a bundle of data to an application via a webpage, expecting the application to process this data in some way. This is known as a client request. The application processes this information and passes the processed data back to the client. This is known as the response. Therefore we say that this whole loop is the request-response cycle. In WebObjects the client request and the response to the client are usually passed using the HTTP protocol. A simple example of how the request-response loop fits into a typical WebObjects application is given in the figure below. In WebObjects we often refer to the complete processing of a request-response cycle as a transaction. (2) WebObjects Adapter WebObjects Application Internet Explorer Web Browser (1) OmniWeb (7) (5) Netscape Others HTTP Response HTTP Response HTTP Request Apache HTTP Request Web Server (3) Netscape 2 runtime Others IIS isapi Deployed on any Java mod_apache nsapi cgi (4) (6)

  The steps in the figure above are as follows

  hyperlink or some other type of activity. This HTTP request is sent like any other to the web server defined in the host portion of the URL. Note that this request may also be an SSL encrypted HTTPS request.

  WebObjects Architecture

  2. The web server receives the HTTP request and forwards it to the WebObjects Adaptor,

  which executes on the same host as the web server. The simplest way to do it is through the default CGI adaptor installed during WebObjects installation, and Apple provides the source code for this adaptor so you can compile it to run on a wide variety of platforms. However, if you are using Apache, Netscape or Microsoft IIS for your web server you can configure it to communicate through their native APIs, which improves performance quite a bit compared to CGI. Once the WebObjects Adaptor has received the HTTP request from the web server it parses it and determines which WebObjects application the request is destined for. For high traffic sites we typically run many instances of each application to improve performance, and these may be spread across multiple servers. In this case, the adaptor also makes the determination of which application instance the request is destined for. In the case of brand new requests (from a new user entering a site for example) the instance is chosen randomly or round-robin.

  Once the adaptor has determined which application you wish to access, it then consults a configuration file to find out which host that application is running on and which TCP/IP socket it is listening on.

  3. The adaptor then opens up a TCP/IP socket to the location WebObjects Application is

  listening on and forwards the request via HTTP to the WebObjects Application as a request object (of class WORequest).

  4. The WebObjects Application receives the WORequest object from the adaptor, processes

  it and generates a response object (of class WOResponse). This response object usually contains HTML content but may be anything, such as a PDF document, an XML document or a QuickTime movie. It also contains the HTTP information required to send the response back to the client. We will look at the internals of how an application handles the request-response loop in Chapter 4.

  

5. The WebObjects Application then passes the WOResponse back to the WebObjects

Adaptor via HTTP and the socket connection is closed.

  6. The WebObjects Adaptor then passes the (HTTP) response to the web server.

  

7. The web server forwards the HTTP response to the client, and the client web browser

displays the HTML (or whatever form the content of the response takes).

  We will come back to the subject of the WebObjects request-response cycle in Chapter 4, and look at it in far more detail.

  WebObjects Architecture