Enterprise Architecture Planning Guide

3,486 views

Published on

Published in: Technology

Enterprise Architecture Planning Guide

  1. 1. POWERTIER™ FOR THE J2EE PLATFORM ENTERPRISE ARCHITECTURE PLANNING GUIDE FROM DESIGN TO DEPLOYMENT VERSION 7.0 NOVEMBER 2001
  2. 2. Enterprise Architecture Planning Guide Version 7.0 Copyright  1993–2001 Persistence Software Inc. All rights in the software and the documentation reserved. This documentation is an instruction manual and not an agreement or contract. The software and documentation is provided under a license agreement containing restrictions on use and disclosure. No part of this documentation may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by information storage or retrieval system without permission in writing from Persistence Software. Reverse engineering of the software is prohibited. The software and documentation are “commercial item(s),” as that term is defined in 48 C.F.R. 2.101, consisting of “commercial computer software” and “commercial computer software documentation,” as those terms are used in 48 C.F.R. 12.212. If the software and/or documentation is/are used by a U.S. Government Agency of the Department of Defense, then such software and documentation shall be governed by 48 C.F.R. 227.7202-1 through 227.7202-4. If the software and/or documentation is/are used by a U.S. Governmental Agency not within the Department of Defense, then such software and documentation shall be considered, delivered and used as “restricted computer software,” as defined and governed by 48 C.F.R. 52.227-19. Persistence Software, Inc. products and technology are protected by U.S. Patent Nos. 5,499,371, 5,615,362, 5,706,506, and 6,078,926. PERSISTENCE, POWERTIER and PROACTIVE AGENTS are trademarks of Persistence Software, Inc. JAVA, JAVABEANS, and other JAVA-based terms used in the software and documentation are trademarks of Sun Microsystems, Inc. Other trademarks used in the software and documentation are the property of their respective owners. Information in this documentation is subject to change without notice. Persistence Software does not warrant that this document is error free. Companies, names, and data used in the software and documentation examples are fictitious unless otherwise noted.
  3. 3. Table of Contents About This Guide Chapter 1. Introduction The Challenges of Enterprise Development ...................................................................................... 1 PowerTier’s End-to-End Development and Deployment Solution................................................ 2 Client Tier ........................................................................................................................................ 3 Middle Tier ...................................................................................................................................... 4 Information System Tier ................................................................................................................ 4 PowerTier’s Product Suite .................................................................................................................... 5 Development Tools......................................................................................................................... 5 Runtime Processes .......................................................................................................................... 9 Chapter 2. J2EE Development J2EE and Enterprise Applications ..................................................................................................... 13 The J2EE APIs ....................................................................................................................................... 16 Enterprise JavaBeans (javax.ejb) ................................................................................................. 16 JDBC (javax.sql)............................................................................................................................. 17 JavaMail (javax.mail) and Java Activation Framework (javax.activation)........................... 17 Java Messaging Service (javax.jms)............................................................................................ 17 Java Transaction API (javax.transaction) .................................................................................. 18 JNDI (javax.naming)..................................................................................................................... 18 JavaIDL........................................................................................................................................... 18 RMI over IIOP (javax.rmi and javax.rmi.CORBA)................................................................... 18 Servlets and JavaServer Pages (javax.servlet & javax.servlet.jsp) ......................................... 19 Development Phases ........................................................................................................................... 19 Plan ................................................................................................................................................. 21 Code ................................................................................................................................................ 23 Build................................................................................................................................................ 24 Test .................................................................................................................................................. 25 Deploy in Your Production Environment................................................................................. 26 Manage ........................................................................................................................................... 27 Chapter 3. J2EE Components J2EE Clients........................................................................................................................................... 29 Web Clients.................................................................................................................................... 30 Standalone Clients ........................................................................................................................ 31 Table of Contents iii
  4. 4. Web Components .................................................................................................................................32 Java Servlets ...................................................................................................................................32 JavaServer Pages ...........................................................................................................................33 Enterprise JavaBeans............................................................................................................................34 Container- and Bean-Managed Entity Beans ............................................................................35 Session Beans .................................................................................................................................37 Enterprise JavaBean Structure.....................................................................................................38 Overview of Deployment Descriptors ..............................................................................................39 The Relationship of Deployment Descriptors to Modules......................................................39 Deployment Descriptor Contents ...............................................................................................41 Working with Deployment Descriptors ....................................................................................43 Chapter 4. Understanding JNDI The JNDI Architecture .........................................................................................................................45 How JNDI Services Work....................................................................................................................47 How Naming Services Resolve Names.............................................................................................48 The Difference Between Naming and Directory Services ..............................................................48 Chapter 5. Understanding Transactions Transaction Basics ................................................................................................................................51 What are Transactional Resource Managers? ...........................................................................52 When Are Transactions Required?.............................................................................................52 Transaction Design Choices................................................................................................................53 Transaction Demarcation and Method Granularity ................................................................54 Implicit and Explicit Transactions ..............................................................................................54 Transaction Types ................................................................................................................................55 Container-Managed Transactions...............................................................................................55 Bean-Managed Transactions .......................................................................................................56 Choosing Transaction Modes .............................................................................................................56 Transaction Mode Settings...........................................................................................................57 Performance Advantage of Deferring Writes ...........................................................................57 Chapter 6. The PowerTier Server J2EE Server Overview..........................................................................................................................61 How the Server Operates .............................................................................................................62 Server-Specific Commands and Tools .......................................................................................62 Types of PowerTier Servers ................................................................................................................63 The Standard PowerTier J2EE Server.........................................................................................63 The Embedded PowerTier Server...............................................................................................64 iv Enterprise Architecture Planning Guide
  5. 5. Chapter 7. The PowerTier Server and Your Database How the Server Uses Database Connections ................................................................................... 65 Configuring Database Connections .................................................................................................. 67 Improving Performance...................................................................................................................... 67 Chapter 8. Planning for Security Assessing the Need for PowerTier Security..................................................................................... 69 Client-Program Security Requirements............................................................................................ 70 Java-Application Clients .............................................................................................................. 70 Java-Applet Clients....................................................................................................................... 71 Java-Servlet Clients....................................................................................................................... 71 Naming-Service Security Requirements........................................................................................... 71 Certificate Authority Security Requirements .................................................................................. 72 Server-Program Security Requirements ........................................................................................... 73 Authentication............................................................................................................................... 73 Administrative API Access ......................................................................................................... 74 Custom Security-Manager Implementations............................................................................ 74 Enterprise Bean Security Requirements ........................................................................................... 74 Chapter 9. PowerTier Enterprise Features Load Balancing ..................................................................................................................................... 77 How Load Balancing Works .............................................................................................................. 78 How the PowerTier Server Publishes Itself with the Naming Service ................................. 81 How the Load-Balancing Service Resolves Names ................................................................. 82 Load-Balancing Optimization..................................................................................................... 83 Understanding Failover Issues .......................................................................................................... 83 The Benefits of Transparent Failover......................................................................................... 84 Failover-Enabled Object Types ................................................................................................... 85 Planning for Failover ........................................................................................................................... 85 Cache Synchronization........................................................................................................................ 87 The Messaging System................................................................................................................. 88 Synchronization Messages .......................................................................................................... 89 Cache Synchronization in Action ............................................................................................... 89 Chapter 10. Recommended Architecture Performance and Scalability Issues ................................................................................................... 93 Runtime Processes ............................................................................................................................... 95 A Deployed PowerTier Application .......................................................................................... 96 Hardware and Network Issues................................................................................................... 97 Table of Contents v
  6. 6. Component Design ..............................................................................................................................97 Entity Beans....................................................................................................................................98 Session Beans .................................................................................................................................99 Servlets and JSPs .........................................................................................................................101 Standalone Clients.......................................................................................................................101 Server Configuration Options ..........................................................................................................102 Index vi Enterprise Architecture Planning Guide
  7. 7. 4 About This Guide The Enterprise Architecture Planning Guide introduces PowerTier for the Java 2 Platform, Enterprise Edition (J2EE). This section provides an overview to this guide in the following topics: n Intended Audience n Notational Conventions n Related Documents n The Online Documentation n Contacting Support Intended Audience The Enterprise Architecture Planning Guide introduces the PowerTier™ product to developers and system architects. This guide assumes that you understand: n the Java™ programming language n your relational database products n relational modeling concepts About This Guide vii
  8. 8. Notational Conventions This document uses the following conventions to distinguish special terms, and to present object model relationships: Typographic Notations This document uses the following typographic conventions to distinguish special kinds of text: Convention Description ps-gen Examples of code, command-line instructions, and user input appear in a fixed-width font. Security Guide Document titles, emphasized words, and first references to specialized terms appear in italics. EditÅCopy Window titles, field names, menu selections, and other elements of a graphical user interface (GUI) appear in a bold font. getClassName() Class names, method names, path and file names, and command (script) names appear in the same bold font when they are mentioned in body text. ClassHome; Variable or user-defined elements appear in an italicized version ps-gen perFile of their base font. CTRL-C Key combinations (or sequences) that you must input from the keyboard appear in UPPERCASE LETTERS. Object Model Notation This document uses the following notational conventions within object models: Relationship Notation zero-to-one to zero-to-one zero-to-one to one-to-one zero-to-one to one-to-many viii Enterprise Architecture Planning Guide
  9. 9. Relationship Notation zero-to-one to zero-to-many one-to-one to zero-to-many composite type (aggregation) relationship indicator Object Model Inheritance This document uses the following format to indicate inheritance within object models: Operating System Conventions The instructions in this document work for both the UNIX and the Windows environments. However, for simplicity, some procedures use only Windows conventions. If you are working in a UNIX environment, please substitute the corresponding UNIX conventions: the “/” (forward slash) separator for path names, and the “:” (colon) separator for environment variables. About This Guide ix
  10. 10. Related Documents This guide presents conceptual information to help you make high level architectural decisions. For information about developing and deploying a PowerTier J2EE application, refer to the following documentation: n Client Development Guide Describes how to create J2EE clients. n Command Center Guide: Configuring and Managing PowerTier Explains how to configure, control, and monitor the PowerTier J2EE server and the PowerTier Servlet Engine using the Command Center. n Deployment Guide Describes the process of deploying J2EE application components to development, test, and production environments. n Installation and Configuration Guide: Windows NT and UNIX Operating Systems Provides instructions for installing and configuring PowerTier for J2EE. n PowerTier Server and EJB Development Guide Provides programming information on EJBs and the PowerTier server APIs. n QuickStart Tutorial Uses a sample application to introduce new users to the PowerTier development process, tools, and environment. n Reference Guide: APIs, Commands, and File Formats Contains reference information about the PowerTier classes, files, and commands. n Security Guide Introduces general security concepts, and describes how to use the PowerTier security features, interfaces, and tools. n Tools Guide: The Rose Add-Ins, Object Builder, and Commands Describes the object modeling tools and the command for building applications. n Web Application Development Guide: The PowerTier Servlet Engine and PowerPage Provides an architectural and functional explanation of the PowerTier Servlet Engine. Explains how to develop and deploy Web applications. x Enterprise Architecture Planning Guide
  11. 11. The Online Documentation This version of PowerTier for J2EE includes a complete online documentation library, in both PDF and HTML format. The PDF versions enable you to print additional copies of the documentation. On UNIX systems, the documentation library comes in a tar file separate from the software. You should create a doc directory in the desired location, perhaps under PERSISTENCE_HOME, and extract the documents there. To use the documentation library, open the file doc/index.htm with your browser. On Windows systems, the PowerTier installation process places the documentation in the doc subdirectory of your PowerTier installation. To use the HTML Help (files ending in .chm), you must have Internet Explorer 4.0 or higher (though it need not be your default browser), and you must install the HTML Help update that comes with your PowerTier installation media. On Windows systems, you can open the ps-doc.chm file and use the Search tab to search across all of the books in the documentation set. To search for a phrase (or a pattern of adjacent words), enclose the phrase in quotes. Contacting Support For additional information on Persistence products, contact your distributor or sales representative. To receive customer support, you must have a current customer- support contract, which details the level of support that your company purchased. If you have a support contract, you can contact Persistence customer support as follows: e-mail: support@persistence.com telephone: 1+ 650.372.3655 fax: 1+ 650.341.8432 Internet http://support.persistence.com About This Guide xi
  12. 12. xii Enterprise Architecture Planning Guide
  13. 13. 1 Introduction 1 This chapter introduces the PowerTier product in the following sections: n The Challenges of Enterprise Development n PowerTier’s End-to-End Development and Deployment Solution n PowerTier’s Product Suite The Challenges of Enterprise Development Whether your organization develops applications to serve employees, external customers, or partners, you likely face challenges common to the development of enterprise applications. In today’s competitive market, business success depends on many factors. It is no longer sufficient to be the first to market. Your application must also provide high performance and reliability, and must be easily manageable. PowerTier for the Java 2 Platform, Enterprise Edition (J2EE) offers you a solution for applications that must meet the following requirements: n provide highly performant Internet or intranet access to back-end data n scale to serve hundreds to thousands of end-users n provide continuous availability n provide remote administration 1
  14. 14. 1 Introduction PowerTier implements the J2EE standard to satisfy your application and business requirements, and simplifies development. The use of J2EE provides the following benefits: n the Java language’s “write once, run everywhere” advantage n a standard that enables interoperability between components from different vendors n an architecture that was designed for enterprise applications that support browser or standalone clients To these advantages that come from use of J2EE, Persistence’s experience in the application server market allows us to add value with the following features: n patented caching technology to speed performance n component code generation (Enterprise JavaBeans and JavaServer Pages) n server clustering to provide load balancing and failover n transaction service extensions to provide better performance PowerTier’s End-to-End Development and Deployment Solution As a licensed J2EE vendor, Persistence distinguishes itself by providing rapid application development and a mature, tested runtime environment. Persistence products have a proven track record in ensuring the successful development and deployment of complex distributed applications. Dozens of Persistence customers have large applications in deployment and are benefiting from PowerTier technology today. Browse our Web site at www.persistence.com to read about their projects. Although many organizations recognize the benefits of standardizing on the J2EE platform, component and enterprise development present challenges to even sophisticated developers. PowerTier provides an end-to-end solution that addresses development and integration across all tiers of your application. Figure 1 illustrates the logical components as they are typically distributed across the three main tiers of a J2EE application: the client tier, the middle tier, and the back-end (information system or database) tier. J2EE containers—Web, EJB, and client—provide the runtime services for components. The runtime architecture of the application determines the physical distribution of the components. 2 Enterprise Architecture Planning Guide
  15. 15. PowerTier’s End-to-End Development and Deployment Solution Figure 1. J2EE Components and Application Tiers The following sections describe how PowerTier for J2EE supports development and deployment across the three main tiers of your application: n Client Tier n Middle Tier n Information System Tier Client Tier PowerTier applications support browser clients, standalone clients, or a combination of both. Requirements for client components can include support for particular browsers, security measures, or conversion of data to XML format. The PowerTier model allows client developers to concentrate on their application-specific requirements. It does so by providing the following features: n For browser clients: rapid prototyping of a Web site with a tool that generates Web components, including HTML pages and JavaServer Pages (JSPs) for accessing and updating persistent data. 3
  16. 16. 1 Introduction n For standalone clients: a JAR file that encapsulates the methods that EJB components expose to clients and a runtime container. n Generated methods that serialize and deserialize entity bean data to and from an XML format. n Interfaces for load balancing and failover of EJB components. Middle Tier In the middle tier, PowerTier simplifies development and deployment by providing: n Mature, stable implementations of a servlet container (which also supports JSPs), an EJB container, and a J2EE server. n A distribution of the Apache Web server for development and testing. n Tools that generate components: Enterprise JavaBeans (EJBs) and JavaServer Pages (JSPs) that map to existing, or to-be created, database tables. JSP generation provides “starter” HTML files that give you a working prototype without your having to write a line of code. n Tools that automate the build, packaging, and deployment processes. n The ability to run the servlet container either independently or collocated with the EJB container. n The Command Center, a Web-based management tool that simplifies the deployment and runtime management of clusters of J2EE servers. n Support for load balancing and failover at different points in your application. Information System Tier On the information system tier, your organization might have legacy applications or databases. The PowerTier J2EE server specializes in persisting entity bean data in one or more relational databases. The server maintains pools of database connections and handles transactions. PowerTier works with the following relational databases (see your Release Notes for a matrix of supported versions): n DB2 n Informix n Microsoft SQL Server n Oracle n Sybase 4 Enterprise Architecture Planning Guide
  17. 17. PowerTier’s Product Suite Note: PowerTier supports all multibyte character sets, but does not support Unicode. PowerTier’s Product Suite Persistence Software offers two standards-based products for the development and deployment of enterprise multi-tier applications: PowerTier for J2EE (the Java 2 Platform, Enterprise Edition) and the CORBA-compliant PowerTier for C++. Both versions contain development tools that accelerate implementation and deployment, and application processes that provide enterprise services and high performance. Persistence’s Dynamai product, sold separately, boosts performance for Web applications. Dynamai is a proxy server that caches your dynamic, as well as static, content. Caching content in this way relieves the load on your Web server and page- generation software, while speeding up customer access to your information. With Dynamai, you can insulate your site against spikes in usage and against denial-of- service attacks. Development licenses give you access to PowerTier development tools and allow you to run the following for testing and debugging: the PowerTier Servlet Engine, the PowerTier J2EE server, the Command Center management tool, and a Web server. Deployment licenses cover the Servlet Engine, the J2EE server, and the Command Center in your production system. Contact a Persistence sales representative for more information on pricing and licensing. Development Tools PowerTier for J2EE simplifies application development, and automates the tasks of compilation and deployment, by providing the following: n Modeling Tools, which enable the rapid development of EJB components that map to your database and prototype Web components that invoke the EJB components. n Data Dictionary Readers (DDRs), which allow you to generate source code from your existing database schema. n A set of commands that automate common development and deployment tasks. 5
  18. 18. 1 Introduction Modeling For model-based development, PowerTier provides two tools: the Object Builder and the PowerTier Add-Ins for Rose: n The Object Builder is a graphical user interface through which you enter information about your object model and database schema, and then generate source code for EJB and Web components. n The PowerTier Add-Ins for Rose also allow you to generate component source code from Rose models. To use the Rose Add-Ins, you must purchase Rose modeling software from Rational Software Corp. or one of its resellers. Figure 2 provides an example of the PowerTier Object Builder graphical user interface, and Figure 3 provides an example of the PowerTier Add-Ins for Rose graphical user interface. Figure 2. The PowerTier Object Builder 6 Enterprise Architecture Planning Guide
  19. 19. PowerTier’s Product Suite Figure 3. The PowerTier Add-Ins for Rose Both tools offer you these productivity advantages: n Patented object-relational mapping technology that reduces development time, and ensures code reliability and efficiency. The modeling tools generate complete source code for container-managed persistent entity beans that map to your database. This eliminates the need for specialized knowledge of SQL or JDBC-/ODBC-specific code. n The generated entity beans contain methods that serialize and deserialize the data to and from an XML format. n Automatic generation of a “starter” Web site: presentation and source files that allow Web clients to access and update relational data through container-managed entity beans. The features that differentiate the two modeling tools make each one well-suited for different types of applications. The Object Builder works best for applications with small sets of data objects, while the Rose Add-Ins support more complex applications. Table 1 summarizes the main feature differences between the two products. 7
  20. 20. 1 Introduction Table 1. Feature Comparison of the Object Builder and Rose Add-Ins Feature Object Builder Rose Add-Ins Provides application-level granularity: the ability No Yes to view and work with multiple classes and relationships simultaneously. Provides object-level granularity: allows you to Yes Yes view the attributes and relationships of one class at a time. Generates code for CMP entity beans. Yes Yes Generates code for session beans. No Yes Allows you to invoke the compiler from the user No Yes interface. Models non-PowerTier-specific classes No Yes Data Dictionary Readers (DDRs) DDRs extract the schema from an existing database to a text file. You can edit the resulting file with the Object Builder or the Rose Add-Ins, to add PowerTier-specific object-oriented features and then generate entity beans that map to your database. PowerTier provides Data Dictionary Readers for Sybase and Oracle databases. Development and Deployment The PowerTier product includes the following command-line tools for development and deployment: n ps-makeejb for compiling and packaging EJB and standalone client components n ps-makeweb for constructing and packaging Web applications n ps-deploy for extracting the contents of J2EE archive files n ps-webadm and ps-webgui for installing and removing Web applications to and from servlet containers 8 Enterprise Architecture Planning Guide
  21. 21. PowerTier’s Product Suite Runtime Processes PowerTier provides a complete suite of runtime processes for the middle tier of your application. The PowerTier J2EE server hosts an EJB container, and optionally, a servlet and JSP container. The distribution includes a JNDI-compliant naming service, and the Apache Web server for development and testing. The PowerTier Command Center allows you to manage individual J2EE servers, or clusters of servers, from a Web-based interface. The following sections further describe the: n J2EE Server n Servlet Engine n Web Server n Command Center n Remote Communication and Naming Services J2EE Server The PowerTier J2EE server provides a set of critical application services for J2EE components by hosting EJB and, optionally, servlet and JSP containers. The multithreaded J2EE server transparently manages multiple client requests to increase concurrency. It handles pools of database connections to increase scalability. By default, the PowerTier server uses a high-performance memory manager. You can disable the default memory manager if you wish to use your own. The EJB container is tightly integrated with the J2EE server. It supports life-cycle services and transactions for enterprise beans. PowerTier’s patented caching technology enables it to support high volumes of requests to EJB components from hundreds or thousands of clients, with sub-second response times. Uniquely, the PowerTier J2EE server stores frequently read data in its local cache, making the data readily available to multiple clients. This minimizes communication with the back-end database, provides better performance, and maximizes the potential of limited database resources. Both the PowerTier Servlet Engine and the PowerTier J2EE server provide enterprise services such as load balancing and failover. This robust and flexible architecture allows you to choose where you want to implement these critical services to best support your application. For example, some applications may benefit the most from load balancing between the Web server and the Servlet Engine, while others may need to load balance between the Servlet Engine and the J2EE server. 9
  22. 22. 1 Introduction If your application requires load balancing or failover of EJB objects, the PowerTier cache synchronization service supports failover of stateful objects within a server cluster. The cache synchronization service includes: n Out-of-the-box support for three messaging systems: JBroker, SpiritWave, and TIBCO’s TIB/Rendezvous (available in C++ or Java versions). JBroker and SpiritWave ship with PowerTier. You must purchase TIB/Rendezvous separately. n Support for custom integrations with other messaging systems. By extending the framework and implementing custom methods, you can support any messaging system. Servlet Engine The PowerTier Servlet Engine has two parts, a distributable servlet container and a Web server plug-in. The Web server plug-in directs HTTP requests for servlets and JavaServer pages to the servlet container. The distributable servlet container includes a built-in JSP engine, and it allows JSPs and servlets to access EJBs, a database, or other resources, as needed. The servlet container runs either as a standalone process or collocated in the same process as your PowerTier J2EE server. In either configuration, the servlet container communicates with the Web server through the Web server plug-in. Figure 4. PowerTier Server with Collocated Servlet Container Web Server PowerTier for J2EE supplies an Apache Web server for development and testing purposes. The PowerTier installation configures the Servlet Engine plug-in for the Apache Web server. The Web server provides the part of the Web container that allows 10 Enterprise Architecture Planning Guide
  23. 23. PowerTier’s Product Suite Web-based clients of J2EE applications to invoke Web components which access and update relational data using servlets or JSPs. You can also configure the PowerTier Servlet Engine to run with Netscape/iPlanet or IIS Web servers. Command Center The Command Center gives you the ability to configure and control individual PowerTier J2EE servers (and, optionally, clusters of servers to provide load balancing and failover). You access the Command Center with a Web browser and use it to control local and remote PowerTier servers. With the Command Center, you can start, stop, or pause—as well as add or remove—servers or clusters across the network. Remote Communication and Naming Services Remote communication in a J2EE application involves 1) remote method invocations between distributed components and 2) the actual communication connections between processes. The runtime processes involved vary according to the needs of your application. Remote Invocation For the remote invocations, PowerTier for J2EE includes JBroker, a CORBA (Common Object Request Broker Architecture) ORB (object request broker). When you build your components using PowerTier tools, they invoke JBroker’s RMI compiler to generate the underlying RMI-IIOP code. EJB components and client components use these communication services transparently as provided by their respective EJB and client containers. Note: JBroker’s jorbd is not necessary to use RMI-IIOP. The jorbd process implements naming, server activation, and authentication services. You are not required to run jorbd in your application. Communication Connections Communication connections between distributed processes can be: n IIOP (synchronous) between standalone clients and the J2EE server, between servlets and EJBs, or between EJBs in one server and another server. 11
  24. 24. 1 Introduction n HTTP (synchronous) between Web clients and the Web server and from the Web server plug-in to the servlet and JSP engine n Java Messaging Service (JMS) (asynchronous) between JMS clients, which can be any component or process in your application. The J2EE-compliant way of locating remote object references to establish RMI-IIOP connections is through a JNDI naming service. By default, the PowerTier J2EE server uses JBroker’s COSNaming (Common Object Services Naming) service. COSNaming is the Object Management Group’s standard for CORBA naming services and is also JNDI-compliant. PowerTier also supports other JNDI-compliant naming and directory services, such as LDAP (lightweight directory access protocol), which may provide more enterprise-level functionality. PowerTier bundles the Standard version of SpiritSoft’s JMS-compliant SpiritWave JMQ product. If you require enterprise-level scalability and fault-tolerance, you can upgrade from JMQ Standard to JMQ Professional message transport. To do so, you must first obtain a JMQ Professional license key directly from SpiritSoft. Related Information See the following sources for related information: Subject Location Object Builder and Rose Add-Ins Tools Guide PowerTier EJB Server PowerTier Server and EJB Development Guide PowerTier Servlet Engine Web Application Development Guide PowerTier Command Center Command Center Guide Developing standalone J2EE clients Client Development Guide Dynamai Ask your sales representative or visit www.persistence.com The J2EE API Sun’s J2EE documentation COSNaming JBroker’s documentation JBroker’s documentation in the doc directory of your PowerTier installation and “Understanding JNDI” on page 45 12 Enterprise Architecture Planning Guide
  25. 25. 2 J2EE Development 2 This chapter provides an overview of J2EE application development and PowerTier- specific development in the following sections: n J2EE and Enterprise Applications n The J2EE APIs n Development Phases J2EE and Enterprise Applications Sun Microsystems, Inc.’s J2EE platform reduces the complexity of developing multi- tiered applications for Internet or intranet applications. Whether your organization requires business-to-business, business-to-customer, or business-to-employee interaction, J2EE specifies components and services that support your complete infrastructure, from the user interface to the back end. The J2EE application architecture divides the runtime portion of enterprise applications into logical “tiers,” containing presentation, business logic, and data. On each of these tiers, “components”—such as EJBs, JSPs, servlets, applets, and standalone clients—encapsulate your critical data, provide application-specific logic, and present a user interface. Vendor-supplied “containers” provide the J2EE- mandated services to support the components. J2EE currently specifies the following containers: n Enterprise JavaBean (EJB) container n Web container (for JSPs, servlets, and HTML pages) 13
  26. 26. 2 J2EE Development n Applet container n Client container Clients can include browsers for a Web-based application, GUI standalone clients, or J2EE clients on any type of networked device, such as a PDA. Web servers, servlet engines, and transactional J2EE servers host JSPs, servlets, HTML pages, and EJB components. An information system might include relational databases or legacy applications. Vendors implement the APIs defined by the J2EE platform to provide the following services for your application: n Naming and Directory (JNDI) n Messaging (JMS) n Transactions (JTA) n Remote communication (RMI over JRMP or IIOP) n Mail (JavaMail) n Direct database connectivity (JDBC) Since the distributed pieces of a J2EE application can be deployed on different hardware platforms and physical machines, this architecture requires support for remote communication between processes. Remote communication includes the following aspects: n A naming service—a way of locating another object independent of its physical location. Clients and remote servers locate each other using a JNDI-compliant naming service. n A communication protocol that dictates the format of data that is passed over the network. Similar to CORBA applications, J2EE applications employ standard network communication protocols, such as HTTP, HTTPS, JRMP, or IIOP. n A programming API that allows applications to invoke remote components. The Remote Method Invocation (RMI) API spares developers the need to explicitly code the underlying communication layer. RMI supports two communication protocols: JRMP and IIOP. These communication protocols are both synchronous: the thread sending the request typically blocks until it receives a reply. n A messaging system that transports data between distributed applications. JMS supports asynchronous messaging: the sender of a message does not wait until the recipient responds before performing further work. PowerTier ships SpiritSoft’s Standard SpiritWave JMQ messaging system. To provide access to J2EE services from outside of a firewall, you would typically use browser clients that send HTTP and HTTPs requests. Browser clients would normally access Web components, which in turn, might access EJB components. 14 Enterprise Architecture Planning Guide
  27. 27. J2EE and Enterprise Applications Clients inside of a firewall would likely be standalone Java or CORBA clients. The following figure illustrates the pieces involved in remote communication between a standalone Java or CORBA client making invocations on EJB components in a PowerTier J2EE server. The interactions occur in this general order: 1. The server starts up and publishes its available EJB objects in the naming service. 2. The client initializes a context object that allows it to access the remote naming service—the underlying code uses IIOP as the communication protocol. 3. The client looks up an EJB object of interest and the naming service returns an object reference to the client. 4. The client can then make a direct invocation of that object. Figure 5. Remote Communication In summary, the J2EE platform offers many benefits for enterprise development: n The Java language presents a simple, yet powerful, programming model. n Java’s “write once, run everywhere” philosophy simplifies deployment on heterogeneous platforms. n The J2EE specifications set standards for vendors, which both ensure that they provide critical services and give you a basis for comparison. 15
  28. 28. 2 J2EE Development n Vendors implement complex services that require specialized domain knowledge, while you concentrate on your area of expertise, the business requirements of your application. n The J2EE architecture provides a model for enterprise applications that gives you a tested model upon which to build. The J2EE APIs Sun Microsystem’s Java 2 Enterprise Edition (J2EE) defines standard extensions to the Java Development Kit (JDK) that simplify the development of sophisticated, enterprise-scale EJB applications. Persistence Software, Inc. is a licensed vendor of J2EE solutions. The J2EE both: n describes a standard for vendors who implement the services, and n defines a consistent set of APIs that vendors expose to application developers. A PowerTier application can take advantage of the following J2EE services. The associated Java packages are listed in parentheses. n Enterprise JavaBeans (javax.ejb) n JDBC (javax.sql) n JavaMail (javax.mail) and Java Activation Framework (javax.activation) n Java Messaging Service (javax.jms) n Java Transaction API (javax.transaction) n JNDI (javax.naming) n RMI over IIOP (javax.rmi and javax.rmi.CORBA) n Servlets and JavaServer Pages (javax.servlet & javax.servlet.jsp) Enterprise JavaBeans (javax.ejb) The EJB specification defines the behavior of enterprise beans, and the services that an J2EE server and container must provide for those beans. PowerTier tools generate entity beans and simplify development and deployment tasks. The PowerTier server and container provide system-level services for enterprise beans. 16 Enterprise Architecture Planning Guide
  29. 29. The J2EE APIs Although the EJB technology is relatively young, PowerTier products leverage Persistence Software, Inc.’s extensive experience in the C++ application server market. PowerTier delivers a proven solution that incorporates Persistence’s patented database mapping and caching technologies. JDBC (javax.sql) JDBC is J2EE’s standard Java API for database communication. The JDBC API contains methods for establishing database connections, sending SQL statements, and processing the results. JDBC provides connectivity to virtually any relational database. In a PowerTier application, several types of components can use JDBC: n session beans n bean-managed persistent (BMP) beans n CMP 1.1 beans n servlets and JSPs JavaMail (javax.mail) and Java Activation Framework (javax.activation) The JavaMail 1.2 API provides a set of abstract classes for implementing a mail system. The platform-independent and protocol-independent framework allows vendors to build Java technology-based mail and messaging applications. The Java Activation Framework (JAF) is required for using JavaMail. PowerTier supports obtaining resource manager connection factories for JavaMail sessions through the deployment descriptor. The PowerTier containers and PowerTier-specific deployment descriptors support use of a JavaMail system with your PowerTier application. Java Messaging Service (javax.jms) The Java Messaging Service (JMS) API provides a framework for asynchronous communication between components in your enterprise application. PowerTier ships a development version of SpiritSoft’s SpiritWave, which provides an implementation of JMS. This single-daemon version allows you to develop and test your Java messages. You can easily upgrade to the Professional version of SpiritWave, should your application require the enterprise features. 17
  30. 30. 2 J2EE Development Java Transaction API (javax.transaction) PowerTier implements a transaction service that supports the Java Transaction API (JTA). The PowerTier container exposes the required javax.transaction.UserTransaction interface to enterprise beans and their clients. Your custom code can use the methods exposed by the javax.transaction package as well as PowerTier extensions that provide performance enhancements. JNDI (javax.naming) The Java Naming and Directory Interface (JNDI) specification defines a common naming and directory API. JavaSoft partially implements JNDI, and service providers implement the rest of the specification. In a J2EE application, any component can use JNDI calls to locate services and other components. Sun has provided specifications for vendors of LDAP, DNS, COS naming, and DSML naming services to expose JNDI. PowerTier comes bundled with JBroker’s COS naming-compliant service and provides a load-balancing service. Both of these services implement the JNDI service provider’s interface, javax.naming.spi. JavaIDL JavaIDL is an interface definition language that allows J2EE application components to invoke external CORBA objects using the IIOP protocol. These CORBA objects may be written in any language and typically run outside the J2EE environment. RMI over IIOP (javax.rmi and javax.rmi.CORBA) The Remote Method Invocation (RMI) standard allows Java objects running in one JVM to invoke methods on objects running in a remote JVM. RMI creates a stub for the remote object in the client’s address space. This local stub acts as a proxy for the object located on the server. RMI over IIOP integrates RMI with Java IDL (Interface Definition Language), allowing you to write Java code that can communicate with any CORBA (Common Object Request Broker Architecture) application. PowerTier development tools generate the remote communication layer for your enterprise beans. JBroker, the CORBA- compliant object request broker bundled with PowerTier, uses the IIOP network protocol to handle remote communication between clients and the PowerTier server. 18 Enterprise Architecture Planning Guide
  31. 31. Development Phases Servlets and JavaServer Pages (javax.servlet & javax.servlet.jsp) Servlets are Java programs that run on the middle tier of your application. They respond to HTTP and HTTPS requests from Web clients by performing server-side processing and dynamically generating the results that will be passed back to the client. The JavaServer Pages (JSP) API allows you to embed Java code in a static HTML page. The PowerTier for J2EE ships the Apache Web Server and PowerTier Servlet Engine, which runs both servlets and JSPs. The PowerTier Servlet Engine compiles the Java code into a servlet, but when it generates the resulting page, it does so according to the HTML formatting of the JSP. The PowerTier Object Builder generates a starter Web site. The generated code includes JSPs that allow HTML clients to access and update relational data. You are also free to write your own servlets or JSPs. Development Phases J2EE application development resembles the usual software development phases. Figure 6 illustrates these phases. Each phase can include processes tailored to your organization and specific J2EE development tasks. The following sections describe how PowerTier tools and executables fit into these development phases. 19
  32. 32. 2 J2EE Development Figure 6. Software Development Phases 20 Enterprise Architecture Planning Guide
  33. 33. Development Phases Development “Roles” The J2EE specification identifies development roles to simplify the process of developing complex, distributed applications. These roles allow the specification to assign responsibility for all development tasks, and to show where development tasks can be divided among individuals or teams with different skills and backgrounds. Your development organization need not mirror J2EE development roles, but understanding their purpose helps you adapt the J2EE development process to fit your organization’s structure. As J2EE specifications develop and mature, Sun is refining the role names and their definitions. To avoid confusion, the PowerTier documentation set refers to J2EE development roles only in cases where these terms seem necessary to clarify the division of development tasks. The following sections describe J2EE tasks and PowerTier-specific contributions during each phase of development: n Plan n Code n Build n Test n Deploy in Your Production Environment n Manage Plan In most organizations, planning includes the process of gathering and prioritizing application requirements. Requirements documents often specify the characteristics of the resulting application, while functional specifications and design documents outline the visible interfaces and underlying implementation, respectively. This section covers the level of planning and design that feed into requirements, functional specifications, and design documents. The planning phase should include analysis of the best way to take advantage of PowerTier strengths in the context of your application. The final chapters in this guide outline a “recommended” architecture. Assuming a lack of application-specific or hardware constraints, the recommended architecture would allow your PowerTier application to perform and scale to its potential. 21
  34. 34. 2 J2EE Development Planning for a J2EE application includes both logical and physical architectural choices. At an abstract level, you can divide your requirements into logical tiers: presentation, business logic, and underlying data. These logical tiers of your application might cross the boundaries of the physical tiers of your application. n Presentation considerations include the look and feel of the interface. Your users’ requirements dictate whether you will support browser clients, standalone clients, or a combination of both. n Business logic resides in components: Client-side components include applets and J2EE clients. Server-side components include Web and EJB components. You need to decide how to distribute the business logic among these components. If your application includes browser clients, you need to make choices on how to separate presentation from business logic—servlets versus JSPs, and client-demarcated transactions versus controlling transactions in the middle tier. In EJB components, session beans handle business logic while entity beans encapsulate underlying data. n Underlying data: Assuming that you use an existing relational database, will the application access existing tables? If so, are there any constraints on the way you access these? Will the application create the data, or will the application use a combination of existing and newly-created data? You will encapsulate this data in entity beans for access by your application. Once you understand the logical relationships, and determine your components, you can map these to the physical architecture—the runtime processes you will deploy, such as Web servers, Servlet and JSP engines, EJB application servers, DB servers—and the machines and network on which they will run. You need to consider how the new application needs to interact with your existing infrastructure: n How will the application interface with existing Web servers, naming services, security, and other runtime processes? n Will clients access J2EE services from inside or outside the firewall, or both? PowerTier for J2EE offers you the following choices for your physical architecture: n Will you run the PowerTier Servlet Engine and the J2EE server in the same process or separately? n Will you run clusters of servers to provide load balancing and failover? n What level of security will you provide? For complex architectures, CASE tools such as Rational Corporation’s Rose 2000 allow you to model both the logical and physical relationships in your application. In addition, PowerTier provides Add-Ins for Rose that allow you to generate code from a 22 Enterprise Architecture Planning Guide
  35. 35. Development Phases Rose model. The type of code you can generate from the PowerTier Add-Ins for Rose includes: CMP entity beans that map to your database, and JSPs and HTML files that allow you to call these CMP entity beans from a browser client. Code The J2EE paradigm shifts responsibility for providing application software infrastructure away from developers to J2EE vendors. Deployment descriptors support this paradigm by allowing you to change the runtime behavior of containers and components using configuration files and tools—no coding is required. The specification divides component development responsibilities between component creators, application assemblers, and deployers. The goal is to allow a third-party vendor, or development department within an organization, to code and build components without knowing details about the runtime system in which the components will be deployed. You concentrate on your application’s business requirements, and decide whether you want to implement or purchase components to meet these requirements. Table 2 lists J2EE components and describes the coding efforts required by your organization to use these components in a PowerTier for J2EE application. Table 2. J2EE Application Components Component Requirements Browser client You are free to add HTML pages, JSPs, and servlets to your application. Standalone client PowerTier tools generate a client JAR file that publishes the PowerTier-generated CMP entity bean interfaces that are available to clients. In addition, PowerTier provides a client package that allows clients to use the PowerTier load- balancing and failover services. JSPs PowerTier tools generate the HTML pages and JSPs necessary to invoke PowerTier- generated CMP entity beans. You can use these as starting points for a Web application. You are free to add other JSPs and servlets to your application. 23
  36. 36. 2 J2EE Development Table 2. J2EE Application Components(Continued) Component Requirements Servlets You are free to add servlets to your application. Entity Beans PowerTier tools generate CMP entity beans that map to your database. The generated beans allow you to add custom methods. You can also hand-code BMP and CMP1.1 entity beans. Session Beans You need to hand-code session beans. Each phase of component development ends with component packaging, which bundles the implementation code and a component-level deployment descriptor into a module. Web components are packaged in a Web Archive (WAR) module, while a Java Archive (JAR) module packages EJB and client components. The J2EE 1.2 specification introduces an application-level EAR file that contains the JAR and WAR modules that make up a logical application. However, it states that modules should be deployable as stand-alone units. A minimal EAR includes an application-level deployment descriptor and one or more modules. The EAR allows for inclusion of runtime libraries and documentation. Each type of module has a specific XML-format deployment descriptor and vendors are allowed to specify their own additional requirements. The XML deployment descriptor contains configuration information and the Application Naming Environment (ANE). The ANE gives components access to other components and to J2EE platform resources such as transaction management, JDBC connections, and JMS. Build PowerTier provides a variety of tools for building and packaging components. The build process for J2EE Web and EJB components includes: n For EJB components only: RMI compilation to create container-adaptor code—the generated stubs and skeletons that handle remote communication. n Java compilation to turn .java source files into compiled .class files. n Creation of deployment descriptors that define runtime behavior. n Setting the values in deployment descriptors to the appropriate value for this phase of development. 24 Enterprise Architecture Planning Guide
  37. 37. Development Phases n Packaging of compiled EJB classes and deployment descriptors into a Java archive (JAR) file and packaging Web components and their deployment descriptors into a Web archive (WAR) file. n The servlet container compiles Web components, JSPs and servlets, the first time they are requested. After the initial compilation, they are only recompiled if the source files have changed (although you can change this behavior through configuration). Test A comprehensive test plan for a J2EE application should include unit, integration, and stress tests. Unit testing involves verifying that each component produces the expected behavior. Integration testing ensures that components work well together and that the application is configured correctly to run in a production system. Stress testing includes running the application under load and verifying that it can handle failures gracefully. You can perform unit testing by running all tiers of your application on a single machine. You will get the best results for integration and stress testing if you are able to closely simulate the production environment and the load of requests that you expect in production. Stress testing reveals weaknesses and allows you to tune configuration to provide the best performance in your environment. Integration and stress tests might require you to deploy the tiers of your application across multiple hosts in your network. Single Machine The PowerTier development installation includes all of the executables that you need to test a J2EE application on a single machine: a Web server, the PowerTier Servlet Engine, and the PowerTier J2EE server. In addition, you need a database client installed on your machine and access to a database. PowerTier development tools help you test on a single machine. The Profile Wizard helps you verify that your environment is configured properly to develop and test on your local machine. The ps-makeejb command produces a simple J2EE server configuration file. To test Web clients, you also need to package your Web components in a WAR file and configure the Servlet Engine plug-in for the Web server. The installation provides tools and sample configuration files for Servlet Engine configuration. 25
  38. 38. 2 J2EE Development Multiple Machines To run a PowerTier J2EE application on multiple machines, you need to have a common naming service instance to which the servers register available objects and from which clients request lookups. Web clients must be able to connect to the Web server. During testing, you may want to set up a Web server for testing that listens on a port number that differs from that used by your production Web server. The Command Center provides a browser interface for managing PowerTier J2EE servers remotely. The Command Center simplifies the process of: n Configuring servers and clusters of servers n Starting and stopping servers and clusters of servers n Monitoring servers and clusters of servers To use the Command Center to configure and deploy servers, you must first install the appropriate PowerTier executables on the remote hosts and run ps-agent, the bootstrap command that handles communication between the Command Center and the server. Deploy in Your Production Environment Test results should identify optimal production configuration settings for your application. You should keep a record of this configuration and provide it to those who will be responsible for managing and monitoring your application. The person managing deployment for production should only need to modify values that identify resources—under most circumstances, they should not modify the behavior of the application. If your application includes security, the following security tasks apply during the deployment phase of your project: n Create and Distribute Certificates n Configure the Server for Security n Protect Enterprise Beans n Provide Client-Program Security 26 Enterprise Architecture Planning Guide
  39. 39. Development Phases Manage The tasks involved in managing your J2EE application can vary widely, depending on your implementation. PowerTier for J2EE provides the following processes and tools for application management: n The Command Center allows system administrators to manage and monitor PowerTier J2EE servers remotely. n The PowerTier Servlet Engine provides tools to install Web applications and to manage the servlet container—when the servlet container is run separately from the J2EE server. n If your application uses security, a system administrator can monitor the security audit log and respond to security problems. Related Information See the following sources for related information: Subject Location Object Builder and Rose Add-Ins Tools Guide Development and Deployment tools Tools Guide, Deployment Guide, and Reference Guide PowerTier EJB Server PowerTier Server and EJB Development Guide PowerTier Servlet Engine Web Application Development Guide PowerTier Command Center Command Center Guide The J2EE API Sun’s J2EE documentation COSNaming JBroker’s documentation JBroker’s documentation in the doc directory of your PowerTier installation. PowerTier Security Security Guide 27
  40. 40. 2 J2EE Development 28 Enterprise Architecture Planning Guide
  41. 41. 3 J2EE Components 3 In a J2EE application, components contain the application-specific logic. To provide easy access for components to other remote components and J2EE resources, the deployment descriptor provides a level of indirection—allowing you to code your components without being aware of the details of the production environment. Deployment descriptors also allow you to change some component behavior without modifying code. The following sections introduce J2EE components and deployment descriptors: n J2EE Clients n Web Components n Enterprise JavaBeans n Overview of Deployment Descriptors J2EE Clients Client components provide the interface through which the user interacts with a J2EE application. The designation of “J2EE client” reflects an expected interaction with the middle tier(s) of an enterprise application. This interaction usually includes requests to Web or EJB components. The containers and components on the middle tier respond to these requests and return the results to the client components which, in turn, present them to the user. A J2EE client can: n Connect to middle-tier components across the World Wide Web, or from inside an enterprise’s intranet. n Run on hardware ranging from powerful desktop machines to tiny wearable assistants. 29
  42. 42. 3 J2EE Components n Provide a browser-based or standalone interface. Application and system requirements often limit the extent of processing that takes place within the client components themselves. The following sections describe the differences between: n Web Clients n Standalone Clients Web Clients Web clients use browser-based interfaces. Browsers use HTML and HTTP, and might involve the use of servlets, JSPs, or applets. HTML Browsers use HTML (hypertext markup language) for the display of communications between clients and servers. HTML: n uses embedded tags for formatting n requires no compilation (it is interpreted, not compiled) n is easy to learn and simple to use Despite HTML’s simplicity, some of the simpler browsers, such as PDAs (personal digital assistants), might not support more advanced HTML features. HTTP HTTP (hypertext transfer protocol) is used as a client-server protocol on the World Wide Web for the exchange of HTML documents. HTTP provides easy access, even outside of firewalls. However, HTTP alone might not provide the required level of security for the transmission of sensitive or critical enterprise information. Servlets or JSPs Web clients can request services from the middle tier by using servlets or JSPs (JavaServer Pages): 30 Enterprise Architecture Planning Guide
  43. 43. J2EE Clients n A servlet is a small server-side application that extends the functionality of a Web server. Servlets receive a request from a client, dynamically generate the response, and then send the response (in the form of an HTTP or XML document) to the client. n JSP technology provides an extensible way to generate dynamic content for a Web client. A JSP page is a text-based document that describes how to process a request and create a response. The first time the JSP engine receives a request for a JavaServer page, it parses the embedded code into a Java source file, and then compiles the source file into a servlet class. The servlet container then loads and runs the servlet class file like any other servlet, sending the output back to the client browser. Applets In addition, a Web client may use applets. Applets are Java-based GUI (graphical user interface) components that typically execute in a Web browser, although they can execute in a variety of other applications or devices. Browser-based applet clients usually communicate using HTTP. Applets may also communicate over a network using serialized objects or some other proprietary protocol. Applets download and install quickly. Standalone Clients In contrast to Web clients, J2EE standalone clients require the development of a UI (user interface), compilation of client code, and configuration of client-server communications. Standalone clients have access to a variety of services, including but not limited to: n RMI-IIOP n JNDI RMI-IIOP J2EE standalone clients interact directly with EJB components, using RMI-IIOP (remote method invocation over internet inter-ORB protocol) to communicate with the EJB server. n RMI is a Java communications package for performing distributed computing. n IIOP is the standard internet protocol for COBRA (Common Object Request Broker Architecture). 31
  44. 44. 3 J2EE Components By joining the two, RMI-IIOP provides a language-independent bridge between Java clients, Java servers, and COBRA implementations. JNDI JNDI (Java Naming and Directory Interface) is a middle-tier service used for directory lookups. It is a system that allows Java-based clients to interact with a variety of naming and directory services. n JNDI provides a client and server API that allows Java code to perform naming and directory operations. n Vendors of other directory services, such as LDAP or COSNaming services, provide JNDI-compliant services that plug into JNDI’s service-provider interface, allowing them to operate with JNDI. Web Components In the J2EE architecture, Web components provide server-side processing for Web clients. The following sections describe the two types of Web components: n Java Servlets n JavaServer Pages Java Servlets Java servlets are small, server-side Java applications that extend Web server functionality in the same way that applets extend browser functionality. Servlets excel in providing content that requires intensive processing or manipulation of data. Similar to CGI scripts, servlets generate Web pages on-the-fly, using form input or other parameters. For example, a financial trading Web site might allow you to estimate the profit you would make by selling a particular stock. A form would contain fields where you enter the number of shares you want to sell and your income tax bracket. When you submit this information, the browser sends the request to the Web server. The Web server submits your variable information to the servlet container. The servlet container 32 Enterprise Architecture Planning Guide
  45. 45. Web Components invokes the servlet, which obtains the current price of the stock from a database or ticker feed, performs the calculations, and generates the answer. The container responds to the Web server, which in return, supplies the results to the browser. Servlets implement the Java API defined in the J2EE Servlet 2.2 specification. Adhering to this standard allows them to interoperate seamlessly in enterprise applications where they can invoke other Java APIs. As Java programs, they are portable across platforms and Web servers. This gives servlets an advantage over CGI scripts. Although you can write CGI scripts in many programming languages, they are not portable across platforms. Servlets also remain resident in memory. When a client first requests a servlet, the Web server passes that request to the servlet container, which initiates and loads the servlet. The loaded servlet then handles subsequent requests. Since they can be multi- threaded, servlets can also handle concurrent requests simultaneously. If needed, you can deploy servlets to use a single-threaded model. These features allow servlets to provide more scalability and better performance than CGI scripts. JavaServer Pages JavaServer Pages (JSPs) extend the servlet API to provide a separation of presentation and business logic. Similar to servlets, JSPs allow you to implement business logic on the server. Use of JSPs further simplifies Web application development and maintenance because they allow you to change the appearance of the generated page without changing any code. At first glance, a JSP looks like a standard HTML document. HTML provides the basic framework, while reserved elements of the page contain embedded Java code. The .jsp file name extension tells the Web server to direct the page request to a JSP engine.The JSP engine compiles the Java code on-the-fly, to produce dynamic HTML content. The first time the JSP engine receives a request for a JavaServer page, it parses the embedded code into a Java source file, and compiles the source file into a servlet class. The servlet container then loads and runs the servlet class file like any other servlet, sending the output back to the client browser. Subsequent requests for the same JSP can use the same compiled servlet. If the JSP engine detects that the class file is older than the JSP you request (or if the class file no longer exists), it recompiles based on the new JSP. You can also configure JSPs to preload, so the servlet container parses and compiles the JSP at startup. JavaServer Pages are similar to Microsoft’s Active Server Pages (ASPs). Although Active Server Pages also separate presentation from business logic, ASPs are tied to Microsoft’s Active Platform and therefore lack the platform-independence of JSPs. 33
  46. 46. 3 J2EE Components Enterprise JavaBeans Enterprise JavaBeans are J2EE components that run inside an EJB container. The PowerTier J2EE server hosts an EJB container. Together, EJB containers and J2EE servers provide all of the necessary underlying services to support the beans—including remote communication and database connections. Enterprise JavaBeans come in two types: entity and session beans. In a J2EE application, entity beans represent persistent data, and session beans represent business processes. Table 3 compares characteristics of entity and session beans. Table 3. Comparison of Entity and Session Beans Entity Beans Session Beans Represent persistent data, which survives Short-lived, stateful or stateless objects, client, server, or database exits. which do not survive client or server exits. Clients share instances. Each instance represents a specific client (one instance per client); client calls are serialized. Support transactions. Can initiate transactions, or can act as a client of a transactional entity bean. A primary key object uniquely identifies A session bean’s state can be stored and each instance. later retrieved. While the J2EE architecture relieves you of providing the low-level infrastructure required for a distributed application, PowerTier for J2EE goes further, by generating CMP (container-managed persistent) entity beans that map to your database, and by optionally generating JavaServer Pages that allow you to access CMP beans from HTML clients. When you take advantage of this feature, you are responsible only for writing any domain-specific logic. Both entity and session beans conform to the J2EE declarative programming model: n During development or deployment, you declare naming, bean transaction, and security characteristics. n At deployment time, PowerTier tools wrap the bean with the necessary runtime services. 34 Enterprise Architecture Planning Guide
  47. 47. Enterprise JavaBeans n At runtime, the server intercepts all calls to Enterprise JavaBeans and provides the transactional, threading, and synchronization security behavior required before the method invocation. The sections that follow describe the different types of Enterprise JavaBeans in more detail: n Container- and Bean-Managed Entity Beans n Session Beans n Enterprise JavaBean Structure Container- and Bean-Managed Entity Beans The EJB specification allows for two ways of implementing entity beans: n Container-Managed Persistence (CMP), where the data access logic resides in the container and in the container-adapter code of the entity bean. n Bean-Managed Persistence (BMP), where the data access logic resides in the bean’s code. PowerTier for J2EE supports two kinds of CMP entity beans, PowerTier CMP beans, and CMP 1.1 beans. PowerTier CMP beans are generated by PowerTier tools, based on an object model that you create using either the Object Builder or the PowerTier Add- Ins for Rose. The source files for CMP 1.1 beans, on the other hand, are not generated by PowerTier tools; you must code them. These beans are fully compatible with the EJB 1.1 specification, and can be deployed in any EJB-compliant container. PowerTier also supports BMP entity beans. Each type of bean has its own advantages and limitations, as described in the following paragraphs. PowerTier CMP Entity Beans PowerTier tools generate all the code for CMP entity beans that map to your database. This code generation relieves you from a tremendous amount of development and testing effort. Since the external resources required by the bean are specified in configuration files that can be modified during deployment, CMP entity beans are independent of the data source. For instance, you could create an “employee” entity bean and use it with any of the PowerTier-supported databases without changing the bean. If you need to change the database schema, you can regenerate your code without overwriting any of your custom business logic. 35
  48. 48. 3 J2EE Components PowerTier CMP beans are also the most performant of the three types of entity beans. Database calls are handled through optimized native methods, rather than through JDBC, and concurrent access is supported through the activation and synchronization of multiple instances of a bean, rather than through the serialization of requests. The one limitation to keep in mind is that these beans will only run in the PowerTier J2EE server. CMP 1.1 Entity Beans CMP 1.1 beans resemble PowerTier CMP beans, in that the container manages the moving of data between the bean instance and the database. Like PowerTier CMP beans, these beans are also independent of the data source. Moreover, they are fully compliant with the EJB 1.1 specification, which means that they will run in any EJB 1.1- compliant container. If you are writing entity beans for resale, or using entity beans purchased from a third party, these are the beans you are most likely to use. If you know that your beans will be deployed in the PowerTier environment, however, PowerTier CMP beans are a better choice, since CMP 1.1 beans do not run as efficiently. Another disadvantage is that the source code for CMP 1.1 beans—comprising the home interface, remote interface, bean class, and primary key class—is not generated by PowerTier tools: although the PowerTier container will manage persistence for your beans, saving you the labor of writing JDBC calls, you must create the source files yourself. BMP Entity Beans BMP entity beans are neither the most performant beans, nor the easiest to write, but they have their place in the EJB architecture. Although all EJB 1.1-complaint containers must support container-managed persistence, the specification does not define the mechanism by which the container provides this service. If you are writing an entity bean that will be deployed in a container whose persistence mechanism is inadequate for your needs, you will want to consider BMP entity beans. Likewise, if your data source is an existing application, rather than a database, BMP beans might be required, since you will probably need to use vendor-specific protocols for exchanging data, rather than SQL code. With BMP beans, in addition to creating the source files, you or a third-party bean provider must code each bean’s database access calls. The advantage of coding data access in the bean is that it ensures portability between J2EE servers and containers. You should be able to deploy a BMP entity bean in any container. But the disadvantage, besides the time required to develop the beans, is that if you need to change the database schema or the type of database, you will likely need to modify the BMP code. 36 Enterprise Architecture Planning Guide

×