Front cover Draft Document for Review April 11, 2002 4:47 pm SG24-6559-00 WebSphere J2EE Application Development for IBM ^ iSeries Servers Build and deploy J2EE compliant applications for WebSphere 4.0 Use Application Developer to build iSeries servlets, JSPs and EJBs Learn how to interface to legacy applications Bob Maatta Luis Aused Cliff Liang Biswanath Panigrahi Lowell Thomason Fernando Zuliani ibm.com/redbooks Draft Document for Review April 11, 2002 4:47 pm 6559edno.fm International Technical Support Organization Developing iSeries J2EE Applications for WebSphere 4.0 May 2002 SG24-6559-00 6559edno.fm Draft Document for Review April 11, 2002 4:47 pm Take Note! Before using this information and the product it supports, be sure to read the general information in “Special notices” on page xi First Edition (May 2002) This edition applies to Version 4, Release of WebSphere Application Server Advanced Edition for iSeries, Program Number 5733-WA4 and Version 4, Release of WebSphere Application Server Advanced Single Server Edition for iSeries, Program Number 5733-WS4 for use with the OS/400 V5R1 This document created or updated on April 11, 2002 Comments may be addressed to: IBM Corporation, International Technical Support Organization Dept JLU Building 107-2 3605 Highway 52N Rochester, Minnesota 55901-7829 When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you © Copyright International Business Machines Corporation 2002 All rights reserved Note to U.S Government Users - Documentation related to restricted rights - Use, duplication or disclosure is subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp Draft Document for Review April 11, 2002 4:47 pm 6559TOC.fm Contents Special notices xi IBM trademarks xii Preface xiii The team that wrote this Redbook xiii Special notice xv Comments welcome .xv Chapter Introduction to J2EE 1.1 Java 2, Enterprise Edition (J2EE) 1.1.1 J2EE platform technologies 1.1.2 J2EE 1.2 required standard extension APIs 1.1.3 J2EE package levels in WebSphere 1.2 J2EE containers 1.3 J2EE components 1.3.1 Client-Side components 1.3.2 Server-side components - servlets 1.3.3 JavaServer Pages (JSPs) - separating presentation logic 1.3.4 Server-side components - EJBs 1.4 J2EE services 10 1.4.1 Java Naming Directory Interface (JNDI) 10 1.4.2 Java Database Connectivity (JDBC) 10 1.4.3 Security 11 1.4.4 Transactions (JTA and JTS) 12 1.4.5 JavaBean Activation Framework (JAF) 13 1.5 J2EE communication 13 1.5.1 Remote Method Invocation (RMI/IIOP) 14 1.5.2 Java Messaging Service (JMS) 14 1.5.3 Java Mail 14 1.6 J2EE packaging and deployment 15 1.6.1 J2EE deployment descriptor 16 1.7 J2EE platform roles 17 1.8 J2EE additional resources 19 Chapter Servlet and JSP development using VisualAge for Java 2.1 Servlet support in WebSphere Advanced Edition 4.0 2.1.1 IBM development environments for WebSphere applications 2.2 Introduction to servlets 2.2.1 Simple servlet example 2.3 Setting up VisualAge for Java to develop and test servlets 2.3.1 Loading the required features 2.3.2 Using the WebSphere Test Environment 2.3.3 Testing the servlet under VisualAge for Java Enterprise Edition 4.0 2.3.4 Exporting the class files to a jar File 2.4 Using JDBC to access an iSeries database 2.4.1 The architecture of the sample application 2.4.2 JDBCCatalogSupport class 2.4.3 JDBCItemCatalog class © Copyright IBM Corp 2002 21 22 22 23 25 26 27 27 28 29 30 31 32 32 v 6559TOC.fm Draft Document for Review April 11, 2002 4:47 pm 2.4.4 Testing the application in the scrapbook 2.4.5 ItemServlet class 2.4.6 Running the ItemServlet inside VisualAge for Java 2.4.7 Export the servlet from VisualAge for Java 2.5 Database connection pools 2.5.1 DataSource version 2.5.2 Running the ItemPoolServlet inside VisualAge for Java 2.5.3 Export the ItemPoolServlet servlet from VisualAge for Java 2.6 JSP support in WebSphere Version 4.0 2.6.1 JSP life cycle 2.6.2 JSP design 2.6.3 Sample example 2.6.4 Running the CallJSP servlet inside VisualAge for Java 2.6.5 Export the CallJSP servlet from VisualAge for Java 2.7 Session Management 2.7.1 Session Tracking Solutions 2.7.2 HttpSession interface 2.7.3 ItemSessionServlet example 2.7.4 Running the ItemSessionServlet servlet inside VisualAge for Java 2.7.5 Export the ItemSessionServlet from VisualAge for Java 35 37 40 42 42 42 50 53 53 54 56 57 59 61 61 62 65 67 74 77 Chapter WebSphere V4.0 Assembly and Deployment Tools 79 3.1 WebSphere 4.0 application packaging overview 80 3.2 Application Assembly Tool (AAT) overview 81 3.3 Application packaging and deploying scenario 83 3.3.1 Packaging MyHelloWorldServlet 83 3.3.2 Installing the MyHello web module under Single Server 87 3.3.3 Packaging ItemServlet 92 3.3.4 Installing the ItemServlet web module on Single Server 96 3.3.5 Running ItemServlet from an HTML file 98 3.3.6 Packaging ItemPoolServlet 103 3.3.7 Installing the ItemPool web module on Single Server 103 3.3.8 Packaging and deploying CallJSP 104 3.3.9 Packaging and deploying ItemSessionServlet 105 3.3.10 Installing the OrderEntry application on Advanced Edition 105 3.3.11 Packaging the MyHelloWorldApp enterprise application 110 3.3.12 Installing the MyHelloWorldApp application on Advanced Edition 123 3.3.13 Testing the MyHelloWorldApp application 125 3.3.14 Packaging the OrderEntryApp enterprise application 127 3.3.15 Installing the OrderEntryApp application on Advanced Edition 141 3.3.16 Testing the OrderEntryApp application 144 Chapter Introduction to WebSphere Studio Application Developer 4.1 WebSphere Studio Application Developer overview 4.2 Getting started with Application Developer 4.2.1 Navigating in Application Developer 4.2.2 Importing resources 4.2.3 Customizing Application Developer 4.3 Working with Java code 4.3.1 Adding new methods 4.3.2 Compiling Java code 4.3.3 Running Java code 4.3.4 Exporting Java code vi Developing iSeries J2EE Applications for WebSphere 4.0 149 150 153 153 156 159 171 171 173 174 178 Draft Document for Review April 11, 2002 4:47 pm 6559TOC.fm 4.4 Conclusion 179 Chapter Building Java Servlets and JSPs with WebSphere Studio Application Developer 5.1 Migrating code from VisualAge for Java 5.2 Migrating the OrderEntry war file 5.2.1 Importing a WAR file 5.2.2 Building the project and modifying the project’s properties 5.2.3 Exploring the enterprise application structure in Application Developer 5.2.4 Testing the servlets 5.3 Developing a new application with Application Developer 5.3.1 New Order Entry application logic 5.3.2 Building the application 5.3.3 Building the OrderEntry application with Application Developer 5.4 Conclusion 181 182 183 183 186 189 192 202 203 206 207 220 Chapter Introduction to Enterprise JavaBeans 6.1 The Enterprise JavaBeans (EJB) specification 6.2 Enterprise JavaBeans architecture definition 6.3 How EJB technology fits into the Java architecture 6.4 Why EJB is important 6.5 Leveraging Java and EJB technology 6.6 EJB architectural overview 6.6.1 The EJB server 6.6.2 Types of components 6.6.3 Component content 6.7 EJB roles 6.7.1 Enterprise JavaBean provider 6.7.2 Application assembler 6.7.3 Application deployer 6.7.4 Server provider 6.7.5 Container provider 6.8 Using EJB technology on the iSeries server 6.8.1 Overview of Java for the iSeries server 6.8.2 EJB technology on the iSeries server 6.9 EJB interoperability with other distributed architectures 6.9.1 CORBA 6.9.2 Component Object Model (COM) 6.9.3 IBM WebSphere Business Components 6.10 Conclusion 221 222 222 223 224 224 225 226 228 229 230 230 231 232 232 232 232 233 234 234 234 234 235 235 Chapter Overview of the Order Entry application 7.1 Overview of the Order Entry application 7.1.1 The ABC Company 7.1.2 The ABC Company database 7.1.3 A customer transaction 7.1.4 Application flow 7.1.5 Customer transaction flow 7.1.6 Database table structure 7.1.7 Order Entry application database layout 7.1.8 Database terminology 237 238 238 238 238 239 240 245 245 248 Chapter iSeries EJB application development scenario 251 8.1 Order Entry application architecture with objects 252 Contents vii 6559TOC.fm viii Draft Document for Review April 11, 2002 4:47 pm 8.2 Business data: Entity Enterprise JavaBeans 8.2.1 Database access: Using a connection pool 8.2.2 Persistence: Container or bean managed 8.2.3 Container-managed persistence 8.2.4 Bean-managed persistence 8.3 Business processes: Session Enterprise JavaBeans 8.3.1 Three-tier versus two-tier architecture 8.3.2 Stateless or stateful beans 8.3.3 Order Entry example 8.3.4 Stateless session bean: OrderPlacement 8.3.5 Stateful session bean: OrderEntryClerk 8.4 Conclusion 254 254 256 256 257 257 258 258 258 259 263 268 Chapter Developing EJBs with Application Developer 9.1 Bottom-up mapping 9.1.1 Create an EJB Project 9.1.2 Importing a schema 9.1.3 Creating the entity EJB from the imported schema 9.1.4 Defining getter methods as read-only 9.1.5 Deploying the Stock bean in the WebSphere test environment 9.2 Top-down mapping 9.2.1 Adding methods to the Stock bean 9.2.2 Mapping the stock bean 9.2.3 Deploying the stock bean and testing 9.3 Meet-in-the-middle mapping 9.3.1 Creating the stock enterprise bean 9.3.2 Add the methods 9.3.3 Mapping the stock bean 9.3.4 Deploying and testing the Enterprise Bean 9.4 Developing a bean managed persistence (BMP) entity bean 9.4.1 Testing the BMP bean 9.5 Conclusion 271 272 272 272 278 282 283 294 298 299 303 303 303 306 308 312 313 320 320 Chapter 10 Building Java applications with Enterprise JavaBeans 10.1 Developing the HelloWorld EJB application 10.1.1 Creating the HelloWorld bean in Application Developer 10.1.2 Creating a servlet which uses the EJB 10.1.3 Creating a Java client application which uses the EJB 10.2 Building Java applications with Application Developer 10.2.1 The ItemsDb class 10.2.2 Using the ItemsDb class 10.3 Building servlets 10.4 Migration from version 1.0 to version 1.1 EJB’s 10.5 Installing the OrderEntry application on the server 10.5.1 Generating the OrderEntry Enterprise Application 10.5.2 Deploying 10.6 Conclusion 323 324 324 330 336 340 340 347 349 352 353 353 355 357 Chapter 11 Interfacing to legacy applications 11.1 Interfacing to legacy applications 11.2 Modifying the RPG application 11.2.1 Processing the submitted order 11.3 Enhancing the Java Application 11.3.1 Changing the CartServlet servlet 359 360 360 360 362 362 Developing iSeries J2EE Applications for WebSphere 4.0 6559TOC.fm Draft Document for Review April 11, 2002 4:47 pm 11.3.2 Changing the ItemsDb class 11.3.3 Changing the OrderPlacement session bean 11.4 Using data queues to interface to legacy applications 11.4.1 Interfacing to data queues from EJBs 11.4.2 The writeDataQueue method 11.5 Using MQSeries to interface to legacy applications 11.5.1 The MQCon class 11.5.2 Including MQSeries in the OrderEntry application 11.5.3 Changing the ItemsDb class 11.5.4 Changing the OrderPlacement session bean 11.6 Using XML to interact with applications 11.6.1 Using XML 11.7 Conclusion 365 365 371 371 372 374 375 378 381 381 387 387 398 Chapter 12 The Command Package 12.1 The IBM Application Framework for e-business 12.2 Distributed Java applications 12.3 The Command package 12.3.1 The Command interface 12.3.2 Facilities for creating commands 12.4 Creating a command 12.4.1 Benefits of the Command package framework 12.4.2 Using the EJBCommandTarget class 12.4.3 Creating the GetCustomerCmdEJB command 12.4.4 Using the GetCustomerCmdEJB command 12.5 Creating your own command targets 12.5.1 Constructing the GetCustomerCmd command and its target 12.5.2 The OrderPlacementCmd command 12.6 Applying the Model-View-Controller architecture 12.6.1 Re-designing the Order Entry application using the MVC architecture 12.7 Conclusion 399 400 401 401 402 403 404 404 405 405 409 412 412 418 420 420 428 Abbreviations and acronyms 431 Appendix A Additional material Locating the Web material Using the Web material System requirements for downloading the Web material How to use the Web material 433 433 433 433 434 Related publications IBM Redbooks Other resources Referenced Web sites How to get IBM Redbooks IBM Redbooks collections 435 435 435 435 436 436 Index 437 Contents ix 6559TOC.fm x Developing iSeries J2EE Applications for WebSphere 4.0 Draft Document for Review April 11, 2002 4:47 pm ... implementation It is the IBM strategic web application server and a key iSeries product for enabling e-business applications The iSeries server and WebSphere Application Server are a perfect match for hosting... several applications for the iSeries server, including a Data Warehouse application for an Insurance company In the last two years he developed several e-business applications for WebSphere on the. .. Application Server Advanced Edition product See the PUBLICATIONS section of the IBM Programming Announcement for the IBM WebSphere Application Server Standard Edition product for more information