You are previewing Expert One-on-One™ J2EE™ Development without EJB™.
O'Reilly logo
Expert One-on-One™ J2EE™ Development without EJB™

Book Description

What is this book about?

Expert One-on-One J2EE Development without EJB shows Java developers and architects how to build robust J2EE applications without having to use Enterprise JavaBeans (EJB). This practical, code-intensive guide provides best practices for using simpler and more effective methods and tools, including JavaServer pages, servlets, and lightweight frameworks.

What does this book cover?

The book begins by examining the limits of EJB technology -- what it does well and not so well. Then the authors guide you through alternatives to EJB that you can use to create higher quality applications faster and at lower cost -- both agile methods as well as new classes of tools that have evolved over the past few years.

They then dive into the details, showing solutions based on the lightweight framework they pioneered on SourceForge -- one of the most innovative open source communities. They demonstrate how to leverage practical techniques and tools, including the popular open source Spring Framework and Hibernate. This book also guides you through productive solutions to core problems, such as transaction management, persistence, remoting, and Web tier design. You will examine how these alternatives affect testing, performance, and scalability, and discover how lightweight architectures can slash time and effort on many projects.

What will you learn from this book?

Here are some details on what you'll find in this book:

  • How to find the simplest and most maintainable architecture for your application

  • Effective transaction management without EJB

  • How to solve common problems in enterprise software development using AOP and Inversion of Control

  • Web tier design and the place of the Web tier in a well-designed J2EE application

  • Effective data access techniques for J2EE applications with JDBC, Hibernate, and JDO

  • How to leverage open source products to improve productivity and reduce custom coding

  • How to design for optimal performance and scalability

Table of Contents

  1. Copyright
  2. About the Authors
  3. Credits
  4. Introduction
    1. Who This Book Is For
    2. Aims of This Book
    3. What This Book Covers
    4. Assumed Knowledge
    5. Recommended Reading
    6. What You Need to Use This Book
    7. The Sample Application
    8. Conventions
    9. Errata
    10. p2p.wrox.com
  5. 1. Why "J2EE Without EJB"?
    1. 1.1. EJB Under the Spotlight
    2. 1.2. What's Left of J2EE?
    3. 1.3. J2EE at a Crossroads
    4. 1.4. The Way Forward
      1. 1.4.1. Themes
        1. 1.4.1.1. Simplicity
        2. 1.4.1.2. Productivity
        3. 1.4.1.3. OO
        4. 1.4.1.4. Primacy of Requirements
        5. 1.4.1.5. Empirical Process
        6. 1.4.1.6. Testability
      2. 1.4.2. Lightweight Frameworks and Containers
        1. 1.4.2.1. The Spring Framework
    5. 1.5. Should We Ever Use EJB?
    6. 1.6. Summary
  6. 2. Goals
    1. 2.1. Productivity
      1. 2.1.1. The Problem
      2. 2.1.2. The Traditional J2EE Approach to Productivity Issues
      3. 2.1.3. Better Solutions for Higher Productivity
        1. 2.1.3.1. Architecture
          1. 2.1.3.1.1. Avoid Unnecessary Architectural Complexity
          2. 2.1.3.1.2. Avoid Unnecessary Use of EJB
          3. 2.1.3.1.3. Use Abstraction Layers to Hide Low-level API Complexity
          4. 2.1.3.1.4. O/R Mapping
          5. 2.1.3.1.5. Use a Good Application Framework
        2. 2.1.3.2. Focus and Methodology
          1. 2.1.3.2.1. Know What Problems to Solve
          2. 2.1.3.2.2. Use Reference Architectures and Templates
          3. 2.1.3.2.3. Use an Agile Development Process
        3. 2.1.3.3. Use Appropriate Tools
    2. 2.2. OO
    3. 2.3. The Importance of Business Requirements
    4. 2.4. The Importance of an Empirical Process
    5. 2.5. Summary
  7. 3. Architectures
    1. 3.1. Architectural Building Blocks
      1. 3.1.1. The Business Services Layer
        1. 3.1.1.1. Stateless or Stateful?
        2. 3.1.1.2. Popular Service Layers
          1. 3.1.1.2.1. Session EJBs
          2. 3.1.1.2.2. Stateless Session Beans with Remote Interfaces
          3. 3.1.1.2.3. Stateless Session Beans with Local Interfaces
          4. 3.1.1.2.4. Common Issues with EJB Service Layers
          5. 3.1.1.2.5. .NET "Serviced Components"
          6. 3.1.1.2.6. MVC Web Actions
          7. 3.1.1.2.7. Service Layer Running in a Lightweight Container
          8. 3.1.1.2.8. Service Layers Compared
      2. 3.1.2. Exposing Business Objects to the World
        1. 3.1.2.1. Limitations of What Can Be Exposed
        2. 3.1.2.2. Web UI
          1. 3.1.2.2.1. The Benefits of Co-location
          2. 3.1.2.2.2. The Importance of Logical Separation
        3. 3.1.2.3. Supporting Remote Clients
      3. 3.1.3. Data Access Layer, or EIS Tier
        1. 3.1.3.1. Technology Choices for Accessing Relational Data
        2. 3.1.3.2. Accessing Legacy Systems
    2. 3.2. J2EE Architectures
      1. 3.2.1. EJB Architectures
        1. 3.2.1.1. "Classic" J2EE Architecture
          1. 3.2.1.1.1. Strengths
          2. 3.2.1.1.2. Weaknesses
        2. 3.2.1.2. Local EJB Architecture
          1. 3.2.1.2.1. Strengths
          2. 3.2.1.2.2. Weaknesses
        3. 3.2.1.3. Variations on EJB Architectures
        4. 3.2.1.4. Implementation Issues Common to EJB Architectures
      2. 3.2.2. Non-EJB Architectures
        1. 3.2.2.1. Ad hoc J2EE Architecture without EJB
          1. 3.2.2.1.1. Strengths
          2. 3.2.2.1.2. Weaknesses
        2. 3.2.2.2. The "Lightweight Container" Architecture
          1. 3.2.2.2.1. Strengths
          2. 3.2.2.2.2. Weaknesses
        3. 3.2.2.3. Implementation Issues
    3. 3.3. J2EE Architectures in Practice
      1. 3.3.1. "Classic" J2EE Remote EJB Architectures
        1. 3.3.1.1. Original Java Pet Store
        2. 3.3.1.2. OTN J2EE Virtual Shopping Mall
      2. 3.3.2. Local EJB Architectures
        1. 3.3.2.1. The Middleware Company mPetStore (February 2003)
        2. 3.3.2.2. Common Issues with EJB Architectures
      3. 3.3.3. Ad hoc Non-EJB Architectures
        1. 3.3.3.1. Sun Adventure Builder v 1.0 EA 3.1 (July 2003)
        2. 3.3.3.2. iBatis JPetStore v 3.1
        3. 3.3.3.3. Overall Notes
      4. 3.3.4. "Lightweight Container" Architecture: The Sample Application
    4. 3.4. Deciding Whether an Application Needs an Application Server
    5. 3.5. Summary
  8. 4. The Simplicity Dividend
    1. 4.1. The Cost of Complexity
    2. 4.2. Causes of Complexity in J2EE Applications
      1. 4.2.1. Architectural Causes of Complexity
        1. 4.2.1.1. Use of EJB
        2. 4.2.1.2. Object Distribution
          1. 4.2.1.2.1. Why Not to Distribute Your Business Objects
          2. 4.2.1.2.2. Distribution and Scalability
          3. 4.2.1.2.3. Faking It: Phony Distributed Objects
          4. 4.2.1.2.4. Isn't J2EE about Distribution?
        3. 4.2.1.3. Focusing on Non Goals: "Phantom Requirements"
        4. 4.2.1.4. Pattern-sickness
      2. 4.2.2. Cultural Causes of Complexity: The Complexity Industry
        1. 4.2.2.1. Vendor-driven Architecture
        2. 4.2.2.2. Tools and Complexity
        3. 4.2.2.3. Organizational Delusions
        4. 4.2.2.4. People
          1. 4.2.2.4.1. Simplicity Is for Dummies
          2. 4.2.2.4.2. Career-driven Development
          3. 4.2.2.4.3. The Hands-off Architect
          4. 4.2.2.4.4. Empire Building and Other Political Challenges
          5. 4.2.2.4.5. Resistance to Simplification
    3. 4.3. How Much Complexity Is too Much Complexity?
      1. 4.3.1. Simple or Naïve?
      2. 4.3.2. Just Good Enough?
      3. 4.3.3. The Winds of Change
    4. 4.4. Summary
  9. 5. EJB, Five Years On
    1. 5.1. Hype and Experience
      1. 5.1.1. EJB and the J2EE Industry
      2. 5.1.2. EJB in Practice
    2. 5.2. An Aging Component Model
      1. 5.2.1. Java Language Improvements
      2. 5.2.2. The .NET Challenge
      3. 5.2.3. Web Services
      4. 5.2.4. The Rise of Agile Methodologies
      5. 5.2.5. Confusion Regarding the Aims of EJB
      6. 5.2.6. The Component Market That Didn't Eventuate
      7. 5.2.7. The New Paradigm on the Block: The Emergence of AOP
    3. 5.3. What Do We Really Want from EJB, or Why Stateless Session Beans Are So Popular
      1. 5.3.1. Declarative Transaction Management
      2. 5.3.2. Remoting
      3. 5.3.3. Clustering
      4. 5.3.4. Thread Management
      5. 5.3.5. EJB Instance Pooling
      6. 5.3.6. Resource Pooling
      7. 5.3.7. Security
      8. 5.3.8. Business Object Management
      9. 5.3.9. EJB Services Summary
    4. 5.4. What Don't We Want from EJB?
      1. 5.4.1. The Monolithic, Distinct Container Problem
      2. 5.4.2. Inelegance and the Proliferation of Classes
      3. 5.4.3. Deployment Descriptor Hell
      4. 5.4.4. Class Loader Hell
      5. 5.4.5. Testing
      6. 5.4.6. EJB Overdose
      7. 5.4.7. Complex Programming Model
      8. 5.4.8. Simple Things Can Be Hard
      9. 5.4.9. Is the Goal of Enabling Developers to Ignore the Complexity of Enterprise Applications Even Desirable?
      10. 5.4.10. Loss of Productivity
      11. 5.4.11. Portability Problems
    5. 5.5. Can EJB Reinvent Itself?
      1. 5.5.1. Tool Support
      2. 5.5.2. EJB 3.0
    6. 5.6. Myths and Fallacies
      1. 5.6.1. J2EE == EJB
      2. 5.6.2. Questionable Arguments for Using EJB
    7. 5.7. Moving Forward
      1. 5.7.1. Choosing Whether to Use EJB
      2. 5.7.2. Conventional Wisdom
      3. 5.7.3. Making a Choice Today
      4. 5.7.4. The Emerging Post-EJB Consensus
      5. 5.7.5. Standards, Innovation, and Open Source
        1. 5.7.5.1. Competition versus Command
        2. 5.7.5.2. Open Source in Practice
        3. 5.7.5.3. Avoiding OSS Hell
    8. 5.8. Summary
  10. 6. Lightweight Containers and Inversion of Control
    1. 6.1. Lightweight Containers
      1. 6.1.1. What Is a Lightweight Container?
      2. 6.1.2. Why Do We Need a Container at All?
      3. 6.1.3. Lightweight Containers versus EJB
        1. 6.1.3.1. Benefits of Lightweight Containers
        2. 6.1.3.2. Benefits of EJB
    2. 6.2. Managing Business Objects
      1. 6.2.1. Interface-implementation Separation
      2. 6.2.2. EJB: Only a Partial Solution
    3. 6.3. Inversion of Control
      1. 6.3.1. IoC Implementation Strategies
        1. 6.3.1.1. Dependency Lookup
        2. 6.3.1.2. Dependency Injection
        3. 6.3.1.3. Setter Injection
        4. 6.3.1.4. Constructor Injection
        5. 6.3.1.5. Choosing between Setter and Constructor Injection
        6. 6.3.1.6. When Can't We Use Dependency Injection?
      2. 6.3.2. IoC Containers
        1. 6.3.2.1. The Spring Framework
        2. 6.3.2.2. PicoContainer
      3. 6.3.3. Portability between IoC Containers
    4. 6.4. Implications for Coding Style, Testing, and Development Process
      1. 6.4.1. Coding Style
      2. 6.4.2. Testability
      3. 6.4.3. Development Process
    5. 6.5. Applying Enterprise Services
    6. 6.6. Summary
  11. 7. Introducing the Spring Framework
    1. 7.1. History and Motivation
    2. 7.2. A Layered Application Framework
      1. 7.2.1. Basic Building Blocks
      2. 7.2.2. Spring on J2EE
      3. 7.2.3. Spring for Web Applications
    3. 7.3. The Core Bean Factory
      1. 7.3.1. Fundamental Interfaces
      2. 7.3.2. Populating Beans via XML
        1. 7.3.2.1. Defining Beans
        2. 7.3.2.2. Accessing Beans
      3. 7.3.3. Non-XML Bean Definition Formats
      4. 7.3.4. Wiring up Application Objects
        1. 7.3.4.1. Defining Beans
        2. 7.3.4.2. Accessing Beans
      5. 7.3.5. Autowire and Dependency Checks
      6. 7.3.6. Constructor Resolution
      7. 7.3.7. Lifecycle Callbacks
      8. 7.3.8. Complex Property Values
    4. 7.4. Resource Setup
      1. 7.4.1. Classic Java and J2EE ResourceAccess
      2. 7.4.2. Resource Definitions in a Bean Container
      3. 7.4.3. Factory Beans
        1. 7.4.3.1. Making a JNDI Resource Available
        2. 7.4.3.2. Creating a Local Connection Factory
    5. 7.5. The Spring Application Context
      1. 7.5.1. Lifecycle Callbacks
      2. 7.5.2. Message Source
      3. 7.5.3. File Resources
      4. 7.5.4. Bean Factory Post-processing
    6. 7.6. Summary
  12. 8. Declarative Middleware Using AOP Concepts
    1. 8.1. AOP 101
      1. 8.1.1. Motivation
      2. 8.1.2. AOP in J2EE
      3. 8.1.3. Definitions
      4. 8.1.4. History
    2. 8.2. EJB as a Subset of AOP
    3. 8.3. AOP Implementation Strategies
      1. 8.3.1. Dynamic Proxies
      2. 8.3.2. Dynamic Byte Code Generation
      3. 8.3.3. Java Code Generation
      4. 8.3.4. Use of a Custom Class Loader
      5. 8.3.5. Language Extensions
    4. 8.4. AOP Implementations
      1. 8.4.1. AspectJ
        1. 8.4.1.1. Pros
        2. 8.4.1.2. Cons
      2. 8.4.2. AspectWerkz
      3. 8.4.3. JBoss 4
        1. 8.4.3.1. Pros
        2. 8.4.3.2. Cons
      4. 8.4.4. Spring
        1. 8.4.4.1. Pros
        2. 8.4.4.2. Cons
        3. 8.4.4.3. Advice Types and Pointcuts
      5. 8.4.5. Nanning
      6. 8.4.6. The AOP Alliance
    5. 8.5. AOP Design Issues
      1. 8.5.1. Dangers of AOP
        1. 8.5.1.1. Should We Intercept Fields?
        2. 8.5.1.2. Too Many Aspects?
        3. 8.5.1.3. Orthogonality
        4. 8.5.1.4. Testing Applications Using AOP
        5. 8.5.1.5. Debugging
        6. 8.5.1.6. Won't AOP Seriously Affect Performance?
      2. 8.5.2. AOP Design Recommendations
    6. 8.6. J2EE à la carte
    7. 8.7. AOP in Practice with Spring
      1. 8.7.1. Using the ProxyFactoryBean
      2. 8.7.2. Convenience Factory Beans
      3. 8.7.3. "Autoproxying"
      4. 8.7.4. Programmatic Usage
    8. 8.8. Using Source-level Metadata to Provide an Abstraction above AOP
      1. 8.8.1. .NET Example
      2. 8.8.2. Aside: Conceptual Versus Implementation-level Metadata
      3. 8.8.3. Programmatic Access to Context Information
      4. 8.8.4. Spring Example
      5. 8.8.5. EJB 3.0
    9. 8.9. Implications for Programming Style
      1. 8.9.1. Consistent Naming Conventions
      2. 8.9.2. Avoiding Reliance on the AOP Infrastructure
      3. 8.9.3. Checked Exceptions and Advice
    10. 8.10. References
      1. 8.10.1. Books
      2. 8.10.2. Papers
      3. 8.10.3. Articles and Online Resources
    11. 8.11. Summary
  13. 9. Transaction Management
    1. 9.1. High-level Transaction Management
    2. 9.2. Classic J2EE Transaction Management
      1. 9.2.1. The J2EE Container as Transaction Coordinator
      2. 9.2.2. Everybody Loves CMT
        1. 9.2.2.1. Typical Use: Local Stateless Session Beans
      3. 9.2.3. Direct Use of JTA
      4. 9.2.4. Interlude: Remote Transaction Propagation
    3. 9.3. Lightweight Transaction Infrastructure
    4. 9.4. Transaction Management with the Spring Framework
      1. 9.4.1. Transaction Definition
      2. 9.4.2. Programmatic Transaction Demarcation
        1. 9.4.2.1. Direct PlatformTransactionManager Usage
        2. 9.4.2.2. TransactionTemplate
      3. 9.4.3. Declarative Transaction Demarcation
        1. 9.4.3.1. AOP ProxyFactoryBean and TransactionInterceptor
        2. 9.4.3.2. AOP ProxyFactoryBean with Interfaces
        3. 9.4.3.3. Simplified Setup: TransactionProxyFactoryBean
        4. 9.4.3.4. Source-level Metadata
      4. 9.4.4. Transaction Management Strategies
        1. 9.4.4.1. jtatransactionmanager
        2. 9.4.4.2. DataSourceTransactionManager
        3. 9.4.4.3. JdoTransactionManager
        4. 9.4.4.4. HibernateTransactionManager
      5. 9.4.5. Implications for J2EE Server Choice
    5. 9.5. Summary
  14. 10. Persistence
    1. 10.1. Common Persistence Strategies
      1. 10.1.1. An Overview of Persistence Patterns
      2. 10.1.2. Popular J2EE Data Access Solutions
      3. 10.1.3. Choosing a Persistence Strategy
        1. 10.1.3.1. When to Choose O/R Mapping
        2. 10.1.3.2. Caching of Persistent Data
      4. 10.1.4. Transparent Persistence and Behavior in Domain Objects
    2. 10.2. A Brief History of Java Persistence Technologies
      1. 10.2.1. The Slow Rise of Java O/R Mapping Solutions
        1. 10.2.1.1. 1997-1998: TopLink, CocoBase, ODMG
        2. 10.2.1.2. 1999-2001: Entity Beans, JDO
        3. 10.2.1.3. 2002-2003: TopLink, Hibernate, iBATIS Database Layer
        4. 10.2.1.4. 2004: JDO Evolves; Hibernate Flourishes
      2. 10.2.2. The Failure of Entity Beans
    3. 10.3. Data Access Technologies in Practice
      1. 10.3.1. Resource Handling
      2. 10.3.2. JDBC
        1. 10.3.2.1. Example Code
      3. 10.3.3. iBATIS SQL Maps
        1. 10.3.3.1. Example Code
      4. 10.3.4. JDO
        1. 10.3.4.1. Example Code
        2. 10.3.4.2. State Management
        3. 10.3.4.3. Identity Management
      5. 10.3.5. Hibernate
        1. 10.3.5.1. Example Code
        2. 10.3.5.2. State Management
        3. 10.3.5.3. Lazy Loading
    4. 10.4. The Data Access Object Pattern
      1. 10.4.1. Business Objects and Data Access Objects
      2. 10.4.2. DAOs and Transparent Persistence
      3. 10.4.3. Types of Data Access Objects
      4. 10.4.4. DAO Design Issues
        1. 10.4.4.1. Granularity of Data Access Operations
        2. 10.4.4.2. Transparent Persistence and Object State
        3. 10.4.4.3. Transaction Scopes and Lazy Loading
      5. 10.4.5. DAO Infrastructure Issues
    5. 10.5. Data Access with the Spring Framework
      1. 10.5.1. Generic Data Access Exceptions
      2. 10.5.2. Business Objects and Data Access Objects Revisited
        1. 10.5.2.1. Transactional Objects
      3. 10.5.3. JDBC
        1. 10.5.3.1. JDBC Access via a Template
        2. 10.5.3.2. "RDBMS Operation" Objects
      4. 10.5.4. iBATIS SQL Maps
        1. 10.5.4.1. SQL Map Access via a Template
      5. 10.5.5. JDO
        1. 10.5.5.1. JDO Access via a Template
        2. 10.5.5.2. JDO Access with an Interceptor
      6. 10.5.6. Hibernate
        1. 10.5.6.1. Hibernate Access via a Template
        2. 10.5.6.2. HibernateTemplate Convenience Methods
    6. 10.6. Summary
  15. 11. Remoting
    1. 11.1. Classic J2SE Remoting: RMI
      1. 11.1.1. Accessing and Exporting RMI Services
        1. 11.1.1.1. Setup within a Spring Context
        2. 11.1.1.2. Business Interfaces for RMI Services
      2. 11.1.2. RMI Invoker for Transparent Remoting
    2. 11.2. Classic J2EE Remoting: EJB
      1. 11.2.1. Wire Protocols
      2. 11.2.2. State Management
      3. 11.2.3. Accessing Remote EJBs
        1. 11.2.3.1. Setup within a Spring Context
        2. 11.2.3.2. Exposing an EJB Home Object
        3. 11.2.3.3. Exposing an SLSB with a Business Interface
        4. 11.2.3.4. Non-RMI Business Interfaces
      4. 11.2.4. Deploying Remote EJBs
        1. 11.2.4.1. Exporting Existing Services
    3. 11.3. WSDL-based Web Services: JAX-RPC
      1. 11.3.1. Accessing Web Services
        1. 11.3.1.1. Setup within a Spring Context
        2. 11.3.1.2. Exposing a JAX-RPC Service
        3. 11.3.1.3. Exposing a Service Endpoint
        4. 11.3.1.4. Business Interfaces for Service Endpoints
      2. 11.3.2. Servlet and EJB Endpoints
        1. 11.3.2.1. Exporting Existing Services
    4. 11.4. Lightweight Remoting: Hessian and Burlap
      1. 11.4.1. Accessing and Exporting Hessian and Burlap Services
        1. 11.4.1.1. Setup within a Spring Context
    5. 11.5. Summary
  16. 12. Replacing Other EJB Services
    1. 12.1. Thread Management
      1. 12.1.1. Threading Myths
        1. 12.1.1.1. Do Stateless Service Objects Need to Be Single Threaded?
        2. 12.1.1.2. The Cost of Instance Creation
        3. 12.1.1.3. Resource Management
        4. 12.1.1.4. Should the Solution Totally Reject the Java Threading Model?
        5. 12.1.1.5. Does the EJB Threading Model Provide a Complete Concurrency Solution?
        6. 12.1.1.6. The Tradeoffs in the EJB Solution
      2. 12.1.2. The EJB Threading Model
        1. 12.1.2.1. Locking
        2. 12.1.2.2. Thread Pooling
        3. 12.1.2.3. Resource Pooling
    2. 12.2. EJB Instance Pooling
      1. 12.2.1. When Is Pooling Required?
      2. 12.2.2. The Case Against Instance Pooling
        1. 12.2.2.1. Memory Management
        2. 12.2.2.2. Lack of Shared State
    3. 12.3. Alternatives to EJB Threading and Pooling
      1. 12.3.1. Threading Models
        1. 12.3.1.1. Shared Multithreaded Object
        2. 12.3.1.2. Concurrency Support in Application Code
        3. 12.3.1.3. What Do We Need to Worry About?
          1. 12.3.1.3.1. Synchronization
          2. 12.3.1.3.2. Concurrency Libraries
        4. 12.3.1.4. A New, Dedicated Object per Client
        5. 12.3.1.5. Non-EJB Instance Pooling
        6. 12.3.1.6. ThreadLocal "Pooling"
      2. 12.3.2. Instance Pooling Summary
    4. 12.4. Declarative Security
      1. 12.4.1. The EJB Model
      2. 12.4.2. Flaws in the EJB Model
      3. 12.4.3. Declarative Security via AOP
    5. 12.5. JMS and Message-driven Beans
    6. 12.6. Summary
  17. 13. Web Tier Design
    1. 13.1. Goals and Architectural Issues
      1. 13.1.1. Web Tier Design Goals
      2. 13.1.2. Ad hoc MVC via Servlets and JSPs
      3. 13.1.3. Integration into Overall Application Architecture
        1. 13.1.3.1. Hard-wired Singleton Business Objects
        2. 13.1.3.2. Stateless Session Beans
        3. 13.1.3.3. ServletContext Attributes
        4. 13.1.3.4. IoC-based Middle Tier Backbone
    2. 13.2. Request-driven Web MVC Frameworks
      1. 13.2.1. Struts 1.1
        1. 13.2.1.1. Basic Controller Workflow
        2. 13.2.1.2. Model and View Handling
        3. 13.2.1.3. Configuration Example
        4. 13.2.1.4. Integration with a Middle Tier
        5. 13.2.1.5. Struts Recap
      2. 13.2.2. WebWork2
        1. 13.2.2.1. Basic Controller Workflow
        2. 13.2.2.2. Model and View Handling
        3. 13.2.2.3. Configuration Example
        4. 13.2.2.4. Integration with a Middle Tier
        5. 13.2.2.5. Recap
      3. 13.2.3. Web MVC with the Spring Framework
        1. 13.2.3.1. Basic Controller Workflow
        2. 13.2.3.2. Model and View Handling
        3. 13.2.3.3. Configuration Example
        4. 13.2.3.4. Command Controllers
        5. 13.2.3.5. Form Controllers
        6. 13.2.3.6. Integration with a Middle Tier
        7. 13.2.3.7. Recap
      4. 13.2.4. Appropriate View Technologies
    3. 13.3. Alternative Approaches to Web MVC
      1. 13.3.1. Portals and Portlets
      2. 13.3.2. Event-driven Web MVC Frameworks
        1. 13.3.2.1. Tapestry
        2. 13.3.2.2. Java Server Faces
      3. 13.3.3. A Word on ASP.NET
    4. 13.4. Summary
  18. 14. Unit Testing and Testability
    1. 14.1. Why Testing Matters
    2. 14.2. Goals of Unit Testing
    3. 14.3. Ensuring Testability
      1. 14.3.1. Programming Style
      2. 14.3.2. How to Make Your Code Hard to Test
        1. 14.3.2.1. EJB and the Potential to Create an Untestable Application
        2. 14.3.2.2. The Singleton Antipattern
        3. 14.3.2.3. Static Facades
      3. 14.3.3. Standard Library Challenges
      4. 14.3.4. Techniques for Improving Testability
        1. 14.3.4.1. Code to Interfaces Rather than Classes
        2. 14.3.4.2. Use the Strategy Design Pattern
        3. 14.3.4.3. Consider the "Law of Demeter"
        4. 14.3.4.4. Minimize Dependence on Environment-specific APIs
        5. 14.3.4.5. Ensure That Each Object Has a Consistent Set of Responsibilities
        6. 14.3.4.6. Hide Implementation Details
        7. 14.3.4.7. Refactor into Methods to Allow Overriding
      5. 14.3.5. Inversion of Control
      6. 14.3.6. AOP
    4. 14.4. Unit Testing Techniques
      1. 14.4.1. Stubs
      2. 14.4.2. Mock Objects
        1. 14.4.2.1. Concepts
        2. 14.4.2.2. Dynamic Mock Objects
        3. 14.4.2.3. Deciding When to Use Mock Objects
      3. 14.4.3. Writing Effective Tests
        1. 14.4.3.1. Negative Tests
        2. 14.4.3.2. Equivalence Partitioning
        3. 14.4.3.3. Coding Practice
          1. 14.4.3.3.1. Test Cases Should Be Economical Yet Self-documenting
          2. 14.4.3.3.2. Don't Rely on External Configuration Unless There's No Alternative
          3. 14.4.3.3.3. Refactor the Test Suite as Necessary
          4. 14.4.3.3.4. Avoid Tests with Side-effects
    5. 14.5. Test-driven Development (TDD)
      1. 14.5.1. Benefits
      2. 14.5.2. Arguments against TDD
        1. 14.5.2.1. "TDD Means That There Won't Be an Overall Theme to the Design"
        2. 14.5.2.2. "But TDD Goes out the Window When You Have a Deadline"
        3. 14.5.2.3. "TDD Takes Longer, and the Client Won't Pay for It"
        4. 14.5.2.4. "We Want Developers to Generate Code from a Model, Not Hack in Their IDE"
        5. 14.5.2.5. "We Don't Like XP"
      3. 14.5.3. Practicing TDD
      4. 14.5.4. Learning TDD
    6. 14.6. Case Study: The Spring Experience
    7. 14.7. Testing Spring Applications
      1. 14.7.1. Testing POJOs
      2. 14.7.2. Benefiting from Spring Abstractions
      3. 14.7.3. When You Do Need to Depend on Spring APIs
      4. 14.7.4. Testing with an Alternate Configuration
    8. 14.8. Coverage Analysis and Other Test Tools
      1. 14.8.1. Test Generators
      2. 14.8.2. Coverage Tools
        1. 14.8.2.1. Benefits
        2. 14.8.2.2. Dangers
      3. 14.8.3. Mutation Testing Tools
    9. 14.9. Resources
    10. 14.10. Summary
  19. 15. Performance and Scalability
    1. 15.1. Definitions
    2. 15.2. Setting Clear Goals
    3. 15.3. Architectural Choices: The Key to Performance and Scalability
      1. 15.3.1. Object Distribution, Clusters, and Farms
        1. 15.3.1.1. Definitions
        2. 15.3.1.2. The Trouble with Distributed Objects
        3. 15.3.1.3. Clustering Challenges
      2. 15.3.2. Data Access
      3. 15.3.3. Other Architectural Issues
        1. 15.3.3.1. XML Usage
        2. 15.3.3.2. Presentation Tier Technologies
        3. 15.3.3.3. Portability versus Performance
    4. 15.4. Implementation Choices
      1. 15.4.1. The Performance Implications of Dispensing with EJB Service Provision
        1. 15.4.1.1. Benchmark Methodology
        2. 15.4.1.2. Declarative and Programmatic Middleware Models
        3. 15.4.1.3. Remote SLSB with CMT
        4. 15.4.1.4. Local SLSB with CMT
        5. 15.4.1.5. AOP Transaction Management
        6. 15.4.1.6. Programmatic Transaction Management
        7. 15.4.1.7. Threading Models
        8. 15.4.1.8. Shared Multithreaded Object
        9. 15.4.1.9. Spring Instance Pooling
        10. 15.4.1.10. Result Summary and Conclusions
      2. 15.4.2. Caching and Code Optimization
        1. 15.4.2.1. Code Optimization and Why to Avoid it
        2. 15.4.2.2. Caching
        3. 15.4.2.3. Potential Code Optimizations
        4. 15.4.2.4. Start with Algorithms
        5. 15.4.2.5. Use the Correct Collection Type
        6. 15.4.2.6. Avoid Unnecessary String Operations
        7. 15.4.2.7. Unnecessary Logging
        8. 15.4.2.8. Contentious Optimizations
        9. 15.4.2.9. Opportunities to Improve Tests
    5. 15.5. Tuning and Deployment
      1. 15.5.1. JVM
      2. 15.5.2. Application Server
      3. 15.5.3. Framework Configuration
      4. 15.5.4. Database Configuration
    6. 15.6. An Evidence-based Approach to Performance
      1. 15.6.1. Benchmarking
      2. 15.6.2. Profiling
        1. 15.6.2.1. Why Use a Profiler?
        2. 15.6.2.2. Profiling in Practice
      3. 15.6.3. Diagnostics
    7. 15.7. Resources
    8. 15.8. Summary
  20. 16. The Sample Application
    1. 16.1. Pet Store Requirements
    2. 16.2. The iBATIS JPetStore 3.1
      1. 16.2.1. Middle Tier
      2. 16.2.2. Remoting
      3. 16.2.3. Room for Improvement
    3. 16.3. Spring JPetStore
      1. 16.3.1. Middle Tier
        1. 16.3.1.1. Configuration Using IoC
        2. 16.3.1.2. Transaction Management: TransactionProxyFactoryBean
        3. 16.3.1.3. Transaction Management: Source-level Attributes
      2. 16.3.2. Data Access Tier
        1. 16.3.2.1. Local Transactions
        2. 16.3.2.2. Distributed Transactions
        3. 16.3.2.3. DAO Implementation
      3. 16.3.3. Web Tier
        1. 16.3.3.1. Struts 1.1
        2. 16.3.3.2. Simple Controllers
        3. 16.3.3.3. Form Controllers
        4. 16.3.3.4. Spring Web MVC
        5. 16.3.3.5. Simple Controllers
        6. 16.3.3.6. Form Controllers
        7. 16.3.3.7. SignonInterceptor
      4. 16.3.4. Remoting
        1. 16.3.4.1. Exporting Remote Services
        2. 16.3.4.2. Hessian and Burlap
        3. 16.3.4.3. WSDL Web Service via Axis
        4. 16.3.4.4. RMI Invoker
        5. 16.3.4.5. Accessing Remote Services
        6. 16.3.4.6. Hessian and Burlap
        7. 16.3.4.7. WSDL Web Service via Axis
        8. 16.3.4.8. RMI Invoker
    4. 16.4. Build and Deployment
      1. 16.4.1. WAR Deployment Issues
        1. 16.4.1.1. Listeners and Startup Servlets
        2. 16.4.1.2. Resource References
        3. 16.4.1.3. JSP and JSTL
      2. 16.4.2. Deploying the Spring JPetStore
    5. 16.5. Summary
  21. 17. Conclusion
    1. 17.1. Looking Back
    2. 17.2. Moving Forward
      1. 17.2.1. Choosing the Best Architecture for Your Application
      2. 17.2.2. The Lightweight Container Architecture
      3. 17.2.3. Standards
      4. 17.2.4. Is Spring the Only Alternative to EJB?
      5. 17.2.5. Key Messages
    3. 17.3. Guidelines
      1. 17.3.1. Architecture
      2. 17.3.2. Programming Style
      3. 17.3.3. Inversion of Control (IoC) and Dependency Injection
      4. 17.3.4. AOP
      5. 17.3.5. Testing
    4. 17.4. Last Words