O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WebSphere Version 4 Application Development Handbook

Book Description

  • Complete guide for WebSphere application development

  • How to make the best use of available tools

  • Product experts reveal their secrets

  • Complete guide for WebSphere application development

  • How to make the best use of available tools

  • Product experts reveal their secrets

This IBM Redbook provides detailed information on how to develop Web applications for IBM WebSphere Application Server Version 4 using a variety of application development tools.

The target audience for this book includes team leaders and developers, who are setting up a new J2EE development project using WebSphere Application Server and related tools. It also includes developers with experience of earlier versions of the WebSphere products, who are looking to migrate to the Version 4 environment.

This book is split into four parts, starting with an introduction, which is followed by parts presenting topics relating to the high-level development activities of analysis and design, code, and unit test. A common theme running through all parts of the book is the use of tooling and automation to improve productivity and streamline the development process.

In Part 1 we introduce the WebSphere programming model, the application development tools, and the example application we use in our discussions.

In Part 2 we cover the analysis and design process, from requirements modeling through object modeling and code generation to the usage of frameworks.

In Part 3 we cover coding and building an application using the Java 2 Software Development Kit, WebSphere Studio Version 4, and VisualAge for Java Version 4. We touch on Software Configuration Management using Rational ClearCase and provide coding guidelines for WebSphere applications. We also cover coding using frameworks, such as Jakarta Struts and WebSphere Business Components.

In Part 4 we cover application testing from simple unit testing through application assembly and deployment to debugging and tracing. We also investigate how unit testing can be automated using JUnit.

In our examples we often refer to the PiggyBank application. This is a very simple J2EE application we created to help illustrate the use of the tools, concepts and principles we describe throughout the book.

Table of Contents

  1. Copyright
  2. Preface
    1. The team that wrote this redbook
    2. Special notice
    3. IBM trademarks
    4. Comments welcome
  3. 1. Introduction
    1. 1. WebSphere programming model
      1. Characteristics of the programming model
      2. Architectures supported by WebSphere
        1. Web-based client/server applications
        2. Distributed object-based applications
        3. Web-enabled distributed object applications
        4. Features of a programming model driven design
      3. Application components
        1. Browser-hosted components
          1. HTML
            1. Role in the architecture
          2. DHTML and JavaScript
            1. Role in the architecture
          3. Framesets and named windows
            1. Role in the architecture
          4. XML, DTD and XSL
            1. Role in the architecture
        2. Web application server hosted components
          1. Servlets
            1. Role in the architecture
          2. JavaServer Pages
            1. Role in the architecture
          3. Data structure JavaBeans (data beans)
            1. Role in the architecture
          4. Business logic access beans
            1. Role in the architecture
        3. Distributed object server-hosted components
          1. Stateless session EJBs
            1. Role in the architecture
          2. Stateful session EJBs
            1. Role in the architecture
          3. Session EJBs with session synchronization
            1. Role in the architecture
          4. Container-managed persistence entity EJBs
            1. Role in the architecture
          5. Bean-managed persistence entity EJBs
            1. Role in the architecture
      4. Control flow mechanisms
        1. Browser component initiated control flow
          1. HTTP GETs
            1. Role in the architecture
          2. HTTP POST (and other method types except for GET)
            1. Role in the architecture
        2. Web application server component initiated control flow
          1. RequestDispatcher forward
            1. Role in the architecture
          2. RequestDispatcher include
            1. Role in the architecture
          3. HttpServletResponse sendRedirect
            1. Role in the architecture
      5. Data flow sources
        1. Browser-maintained data flow sources
          1. URL query string
            1. Role in the architecture
          2. POST data
            1. Role in the architecture
          3. Cookies
            1. Role in the architecture
        2. Web application server maintained data flow sources
          1. HttpServletRequest attributes
            1. Role in the architecture
          2. HttpSession state
            1. Role in the architecture
          3. Servlet context cache
            1. Role in the architecture
        3. Enterprise server-maintained data sources
          1. Java Naming and Directory Interface (JNDI)
            1. Role in the architecture
          2. JDBC
            1. Role in the architecture
      6. Chapter summary
        1. Summary of programming model aspects
        2. Meeting the challenges
    2. 2. Tools overview
      1. IBM tools
        1. WebSphere Application Server Version 4.0
          1. Java 2 Enterprise Edition support
          2. Web services support
          3. New tools
          4. New single server version
          5. Differences between the AE and AEs versions
          6. Improved performance
        2. WebSphere Studio Version 4.0
        3. VisualAge for Java Version 4.0
        4. WebSphere Business Components Composer
      2. Third party tools
        1. Rational Rose
        2. Rational ClearCase
        3. Jakarta Ant
        4. Jakarta Log4J
        5. Jakarta Struts
        6. JUnit
    3. 3. About the PiggyBank application
      1. Introducing the PiggyBank application
        1. What is a piggy bank?
      2. Functional overview
        1. Standalone client
        2. Web client
        3. Security functionality
      3. Application architecture
      4. Application modules
        1. Common code
        2. EJBs
        3. Use cases
        4. Standalone client
        5. Web client
      5. Application implementation
      6. Application delivery
  4. 2. Analysis and design
    1. 4. Overview of development activities
      1. Analysis and design activities
      2. Assembling a development team
        1. Further reading
      3. Development roles
      4. Patterns
        1. Model-view-controller pattern
        2. Command pattern
    2. 5. Requirements modeling
      1. Use case analysis
        1. PiggyBank use cases
          1. Transfer money
          2. Cash a cheque
          3. Display balance
        2. PiggyBank use case diagram in Rational Rose
        3. Use case descriptions in VisualAge for Java
      2. Use case realization
        1. The basic approach
        2. Servlet mapping
        3. MVC pattern
        4. Facade pattern
        5. Servlet multiplexing
        6. Command pattern
        7. Display commands
        8. The value of commands
        9. Command granularity
        10. Using session beans
        11. Relationship between command beans and EJB session beans
        12. Caching
      3. External systems integration
        1. Representing external use cases
        2. Realizing proxy use cases
        3. Representing agents in VisualAge for Java
      4. Designing the user interface
        1. Screen composition
        2. Navigation
        3. Use case commands
        4. Intermediate commands
    3. 6. Modeling and code generation
      1. Code generation
        1. Round tripping
      2. Setting the default language for Rose
      3. Code generation and reverse engineering
        1. Code generation
        2. Reverse engineering
          1. Class paths and reverse engineering
      4. Integration with VisualAge for Java
        1. VisualAge for Java Rational Rose bridge
          1. Installing the Rose bridge
            1. Export Version 4.0 registry entries
            2. Edit exported file
            3. Import edited file
            4. Install Rose
            5. Delete imported version 3.5 settings
          2. Configuring the Rose bridge
          3. Starting the Rose plugin in VisualAge for Java
          4. Generating code into VisualAge for Java
          5. Reverse engineering code from VisualAge for Java
        2. XMI toolkit
        3. Plain Java files
      5. Designing EJBs with Rational Rose
        1. Creating an EJB with Rose
          1. Creating a package
          2. Create a class diagram
          3. Create the EJB
          4. Adding CMP fields to the EJB
          5. Adding fields to the primary key class
          6. Adding a finder method to the EJB
          7. Adding business methods to the EJB
        2. Generating EJB code
        3. Importing an EJB from Rose into VisualAge for Java
    4. 7. Designing with frameworks
      1. Introduction
      2. Starting with a framework
        1. What is a framework?
        2. Frameworks drawbacks
        3. Framework adoption
        4. Integration with the tools
      3. Jakarta Struts
        1. When to use Struts
        2. Servlet controller
        3. Action objects
        4. Form beans
        5. Custom tags
        6. Internationalization
        7. Code dependencies
        8. Downsides
        9. Development
      4. WebSphere Business Components Composer
        1. When to use WSBCC
        2. Deployment and maintenance
        3. Architecture
        4. WSBCC elements
          1. Operation
          2. Context
          3. Services
          4. Data elements
            1. Typed data elements
          5. Formats
        5. Development
  5. 3. Coding the application
    1. 8. Setting up a development environment
      1. Planning for development
        1. Defining the deliverables
        2. Choosing your tools
        3. Automation opportunities
    2. 9. Development using the Java 2 Software Development Kit
      1. Organizing the project directory structure
      2. Using the Java 2 SDK to build the application
        1. Tools in the Java 2 SDK
        2. Setting up the environment
        3. Compiling the source code
          1. Code dependencies
          2. Compiler options
          3. Running the compiler
        4. Creating the common JAR file
        5. Creating the EJB JAR file
        6. Creating the use case JAR file
        7. Creating the WAR file
        8. Creating the client JAR file
        9. Generating documentation
          1. javadoc options
          2. Running javadoc
          3. Viewing the generated documentation
      3. Using Ant to build a WebSphere application
        1. What is Ant?
        2. Installing and configuring Ant
        3. Ant build files
        4. Built-in tasks
        5. Creating build files for the PiggyBank application
        6. Master build file
          1. Setting global properties
          2. Build targets
            1. Initialization target
            2. Compilation and packaging targets
            3. Cleanup targets
            4. Documentation target
        7. Building the common code
          1. Compiling the common code
          2. Packaging the common code
          3. Cleaning up common code files
        8. Building the EJBs
          1. Compiling the EJBs
          2. Packaging the EJBs
          3. Packaging EJBs and generating deployed code
          4. Cleaning up EJB files
        9. Building the use cases
        10. Building the standalone client application
          1. Compiling the client code
          2. Packaging the client code
          3. Cleaning up client files
        11. Building the Web application
          1. Compiling the Web application code
          2. Packaging the Web application
          3. Cleaning up Web application files
        12. Further automation opportunities using Ant
          1. Automatic builds
      4. Working with meta-data
        1. Meta-data in WebSphere
        2. J2EE deployment descriptors
        3. WebSphere deployment information
        4. Manifest information
        5. Creating and editing meta-data files
          1. Extracting deployment descriptors
          2. Automation using Ant
            1. Packaging the EAR file
            2. Editing the EAR file
            3. Installing the EAR file
    3. 10. Development using WebSphere Studio
      1. Developing Web applications with WebSphere Studio
        1. WebSphere Studio components
        2. New features in WebSphere Studio Version 4.0
      2. Structuring the project in Studio
        1. Publishing stages and publishing targets
        2. Custom file status
        3. Working in a team environment with Studio
        4. Custom tag libraries
      3. Integration with VisualAge for Java
        1. Setup
        2. Interfacing with VisualAge for Java from Studio
        3. Interfacing with Studio from VisualAge for Java
      4. Integration with other development tools
      5. Creating and publishing WAR files
        1. Creating the WAR file
      6. Web services wizards
        1. Web services creation wizard
          1. Example
        2. Web services consumption wizard
    4. 11. Development using VisualAge for Java
      1. The integrated development environment (IDE)
        1. Configuring the projects and packages
          1. Solution
        2. Generating documentation in VisualAge for Java
      2. Working in a team environment
      3. Developing Web applications with VisualAge for Java
        1. Developing servlets
          1. Hand-coding servlets
          2. Servlet SmartGuide
          3. Importing servlets from WebSphere Studio
        2. Developing JSPs
        3. Developing EJBs in VisualAge for Java
          1. EJB development environment
          2. EJB 1.1 specification
          3. Migrating 1.0 EJBs to 1.1 EJBs for WebSphere 4.0
          4. Developing 1.1 EJBs in VisualAge for Java
          5. EJB development and deployment options
      4. WebSphere Test Environment
        1. Configuration
          1. Configuring a Web application
        2. WebSphere Test Environment Control Center
        3. Servlet Engine
          1. JSP processing
        4. Persistent Name Server
        5. Using DataSource objects with the WTE
        6. JSP execution monitor
      5. Exporting the code
        1. Exporting the EJB code
          1. Exporting EJBs to a 1.1 JAR file
        2. EJB deployment tool
      6. Debugging in VisualAge for Java
    5. 12. Development with frameworks
      1. Jakarta Struts
        1. Using Struts in your development environment
          1. Importing Struts into VisualAge for Java
          2. Setting up WebSphere Studio for Struts
          3. Populating the Studio project
          4. Setting up the WebSphere Test Environment for Struts
            1. Generating the WTE webapp file from a web.xml file
          5. Building the Struts version of the application using Ant
            1. Updating the global properties file
            2. Updating the Web application class path
            3. Adding Struts components to the WAR file
            4. Updating the PiggyBank Web content
        2. Struts configuration file
        3. Building a Struts form
        4. Building a Struts action
          1. LoginAction perform method
          2. Defining the action mapping
        5. Form validation
        6. Message facility
        7. Internationalization
          1. Translating messages
          2. Selecting a language
        8. Struts conclusions
      2. WebSphere Business Components Composer
        1. Importing WSBCC into VisualAge for Java
        2. WebSphere Studio setup
        3. WTE setup
        4. Automatic server startup
          1. initialize method
          2. init method
          3. service method
          4. Configuration
        5. Building WSBCC operations
        6. Extending XML externalization
        7. Login
        8. Legacy example
        9. Writing a WSBCC service
        10. Generic WSBCC operations
        11. Dealing with contexts
        12. Defining formats
        13. Presentation
      3. What we have achieved in this chapter
    6. 13. Guidelines for coding WebSphere applications
      1. Using JNDI
        1. Obtaining an InitialContext
        2. Local and global JNDI namespaces
        3. Caching JNDI lookup results
      2. Message logging
        1. Why do we need a logging framework?
        2. What do we need from a logging framework?
        3. PiggyBank log wrapper
          1. Designing the log wrapper
          2. Writing code to use the log wrapper
          3. Initializing the log wrapper
          4. Logging messages
          5. Automation opportunities
        4. Choosing a framework
          1. Writing your own framework
        5. Using the WebSphere JRas facility
          1. Implementing the log wrapper using the JRas facility
            1. JRas message categories
            2. Writing the wrapper class
            3. Log wrapper constructor
            4. Initializing JRas
            5. Logging simple messages
            6. Logging messages with exceptions
            7. Checking if debug and information messages are enabled
            8. Building and deploying the log wrapper
          2. Controlling application logging with the JRas facility
            1. Logging using the administrator’s console
            2. Logging using the command line
        6. Using Log4J
          1. Installing Log4J
          2. Implementing the log wrapper using Log4J
            1. Log4J message types
          3. Writing the wrapper class
            1. Log wrapper constructor
            2. Initializing Log4J
            3. Logging simple messages
            4. Logging messages with exceptions
            5. Checking if debug and information messages are enabled
            6. Building and deploying the log wrapper
          4. Controlling application logging with Log4J
        7. Logging conclusions
      3. Coding for performance
        1. General performance tips
          1. Database connection pooling
          2. Using System.out
          3. String concatenation
        2. JSP and servlet performance tips
          1. Storing objects in HTTP sessions
          2. Using HTTP sessions in JSPs
          3. Servlet multi-threading
        3. EJB performance tips
          1. Accessing EJBs from client code
          2. Entity EJB read-only methods
          3. Isolation levels
      4. Managing application versions
        1. Specifying the application name
        2. Partitioning Web applications in the URI namespace
          1. Partitioning using virtual hosts
            1. Defining host aliases
            2. Defining WebSphere virtual hosts
            3. Specifying binding information
            4. Specifying binding information using the installation wizard
            5. Specifying binding information using the assembly tool
          2. Partitioning using the Web application context root
        3. Partitioning EJBs in the JNDI namespace
        4. Partitioning access to database and other resources
        5. Automation opportunities
          1. Creating ready-bound modules
          2. Scripting installation of application versions
    7. 14. Software Configuration Management
      1. Introduction
      2. Reference
  6. 4. Unit testing the application
    1. 15. Assembling the application
      1. Application Assembly Tool (AAT)
        1. Starting the Application Assembly Tool
          1. From the command line
          2. From the WAS Administrative Console (AE only)
        2. Using the interface
        3. Creating a Web module
          1. Using the Web module creation wizard
          2. Creating a Web module without the wizard
        4. Creating an EJB module
          1. Setting up the configuration data
          2. Working with EJB 1.1 JAR files
          3. Working with EJB 1.0 JAR files
          4. Generating deployed code
          5. Using the EJB module creation wizard
        5. Creating an application client module
          1. Assembling the module
          2. Application client creation wizard
        6. Assembling the complete application: the EAR file
          1. Assembling options for enterprise applications
          2. Using the enterprise application wizard
      2. EJB deployment tool
        1. What does the EJB deployment tool do?
        2. When is the EJB deployment tool executed?
        3. Why would I want to run the EJB deployment tool myself?
        4. Customizing CMP persistence mapping
          1. Schema file
          2. Map file
        5. Migrating and validating EJB JAR files
          1. Validating EJB code
          2. Converting serialized deployment descriptors
          3. Migrating CMP beans
    2. 16. Deploying to the test environment
      1. EARExpander command line tool
      2. SEAppInstall command line tool
      3. Single Server Edition: the browser-based console
        1. Starting the application server
        2. Launching the administrative console in a browser
        3. Administering applications though the console
          1. Installing applications
          2. Changing configuration settings
          3. Setting up resources
          4. Uninstalling applications
        4. Stopping the AEs application server
      4. Advanced Edition: the stand-alone console
        1. Start and stop
        2. Starting the console
        3. Installing new applications
          1. Using the application installation wizard
        4. Uninstalling applications
        5. Setting up resources
      5. Web server plugin
        1. The HTTP transport plugin
          1. Single Server Edition
          2. Advanced Edition
        2. Command line plugin generation
          1. Single Server Edition
          2. Advanced Edition
      6. Application client resource configuration tool
      7. Other tools in the Advanced Edition
        1. XMLConfig
          1. XMLConfig syntax
        2. WSCP
      8. Performing a unit test: executing the application
        1. Launching the Web application
        2. Launching the client application with the launchClient tool
    3. 17. Debugging the application
      1. Debugging with VisualAge for Java Version 4.0
        1. Working with breakpoints
        2. Exceptions
        3. Debugging external classes
        4. Inspecting data
        5. Debugging code snippets
      2. Debugging with the Distributed Debugger and OLT
        1. Enabling debugging support in WebSphere Application Server
          1. Virtual machine debug options
        2. Enabling support in Advanced Edition
          1. Enabling OLT
          2. Enabling the Distributed Debugger
          3. Setting virtual machine options
        3. Enabling support in Advanced Edition, Single Server
        4. Using Object Level Trace
          1. Configuring OLT
          2. Reading tracing information
          3. Tracing local and remote applications
          4. Setting breakpoints
        5. Using the Distributed Debugger
          1. Starting the debugger
          2. The graphical interface
            1. Source pane
            2. Breakpoints pane
            3. Packages pane
            4. Stacks pane
            5. Monitors pane
          3. Attaching the debugger to the JVM
            1. Attaching to a different machine
          4. Debugging Web applications with the debugger
            1. Working with breakpoints
            2. Exceptions
            3. Inspecting data
          5. Debugging standalone applications with the debugger
        6. Debugging WebSphere Studio code
      3. A special case: how to debug a JSP
        1. Debugging JSPs in VisualAge for Java
          1. Debug a JSP without importing the code to VisualAge for Java
            1. Halt at the beginning of the service method
            2. Enable JSP source debugging
          2. Debug a JSP by importing the code
          3. JSP execution monitor
        2. Debugging Studio JSPs: the Distributed Debugger
        3. Debugging JSPs in WebSphere Application Server
    4. 18. Automating unit testing using JUnit
      1. Unit testing
        1. What is unit testing?
        2. Why unit testing?
        3. Benefits of a unit testing framework
      2. JUnit
        1. Installing JUnit
          1. Installing JUnit in VisualAge for Java
        2. Organizing our tests
          1. Test suites
        3. Test case for a simple Java class
          1. Expected behavior
            1. Choosing what tests to write
          2. Writing the test case class
            1. Set-up and tear-down
            2. Testing iteration
            3. Testing reset
            4. Testing the default constructor
            5. Testing iteration without an initial getNext
          3. Building the tests
          4. Running the tests
            1. Running the text-based test runner
            2. Running the Swing-based test runner
            3. Failed tests
          5. Adding the test case to a test suite
            1. Writing the AllTests class
            2. Running the test suite
            3. Creating the hierarchy
        4. Test case for an EJB
          1. Writing the test case
            1. Running as an EJB client
            2. Set-up and tear-down
            3. Writing the test methods
            4. Updating the test suite hierarchy
          2. Building the tests
          3. Packaging the tests
          4. Running the tests
        5. Automating unit testing using Ant
          1. Building the tests
            1. Creating the directory structure
            2. Creating the build file
            3. Updating the master build file
          2. Running the tests
            1. Starting and stopping WebSphere Application Server
            2. Running the tests
      3. Conclusions
  7. 5. Appendixes
    1. A. Additional material
      1. Locating the Web material
      2. Using the Web material
        1. System requirements for downloading the Web material
        2. How to use the Web material
        3. Installing and running the PiggyBank application
        4. Importing the sample code into VisualAge for Java
        5. Using the Ant samples
    2. Related publications
      1. IBM Redbooks
        1. Other resources
      2. Referenced Web sites
      3. How to get IBM Redbooks
        1. IBM Redbooks collections
    3. Special notices
    4. Abbreviations and acronyms
  8. Back cover