Introduction
Introduction
Objectives
Java Web Application Architecture
J2EE Architecture
Web Application Programming Model – MVC
Patterns
Factory Method
Singleton
Command
Modeling the Structure Aspect of Command Pattern
Modeling the Behavior Aspect of Command Pattern
Facade
Adapter
Proxy
Publish-Subscribe
Modeling the Structural Aspect of the Publish-Subscribe Pattern
Modeling the Behavioral Aspect of the Publish-Subscribe Pattern
Presentation Tier Patterns
Objectives
Why use the intercepting filter pattern?
Uses for Filtering
What is a filter?
Features of filters
The Filter interface
How a filter works
In what order?
A simple logging filter
Configuring the filter
Mapping the filter
The Web Deployment Descriptor
Common filter tasks
Request and Response Wrappers
How Struts uses this design pattern?
Front Controller Pattern
Command and Controller Strategy
Advantages of command and controller strategy
How Struts uses this strategy?
View Helper Pattern
Use JavaBean as result bean helper
Use JavaBean as command bean helper
Use custom tag for display logic written in Java
Components of a Tag library
JSTL Overview
How Struts uses this pattern
Problem
Solution 1 – use jsp:include
Solution 2 – use Struts templates
Solution 2 continued
Transform View Pattern
The Music Collection Example – Sample XML file
The Music Collection Example – Retrieving owner details
The Music Collection Example – Retrieving the core data
The Music Collection Example – Current Output
Transformation with Java
Reading an XML
Transforming to HTML
Transforming to System.out
Summary
Presentation Tier Design Considerations
Objectives
HttpSession
Why on the server?
Session Tracking Options
URL Rewriting
Do not store large Object Graphs in HttpSession
Session and Clustering
The problem
The design pattern that fixes it
A client side fix
Struts implementation
Typical validation rules
Client-side validations
Jakarta commons validation framework features
Not resetting JavaBeans between requests
Passing HttpServletRequest to business tier
Summary
Business and Integration Tier Patterns
Objectives
Business Delegate Pattern
How it works
Data Transfer Object Pattern
DTO Example (Output)
DTO Example (Input)
Role of DTO in MVC
Trouble with DTO
Value Object Pattern
Multiple Value Objects
Best Practice – derive EJB from the Value Object
Composite Entity Pattern
An example
Class Diagram
How the client interacts
Value Object Assembler
Value List Handler
How does it work?
How does it work - continued
Design Considerations
Service Locator
Data Access Object (DAO)
DAO Implementation Guidelines
Service Activator
MDB- Integrating JMS and EJB
Message-Driven Beans Are Different From Other EJBs
Message-Driven Beans are Stateless
Message-Driven Bean Interfaces
Example: Message Counter
Class MessageCounter
Class MessageCounter
Processing the Message
Deployment Descriptor Entry
Summary
Business and Integration Tier Best Practices
Objectives
Exception Handling
Exception Handling (cont.)
Use java:comp to locate resources
Example: Defining Data Source Resource Reference in WebSphere Studio
Use java:comp to locate resources - continued
Use Container Authentication.
Use JDBC Connection Pooling
Prepared Statement Cache.
Release JDBC Resources
Optimize database first
DB2 Tuning - MaxAppls
DB2 Tuning - MaxAgents
DB2 Tuning - Buffer Pool Tuning
DB2 Tuning - Configuring buffpage
DB2 Tuning - Evaluating the buffer pool size
DB2 Tuning - Monitoring the database buffer pool
DB2 Tuning - reorgchk
Using log4j from an Web application
Using Log4J
Example servlet using log4j
Summary
Other EJB Patterns
Objectives
Session Façade
Session Façade Pattern
Session Façade
Miscellaneous Details
Message Façade Pattern
Message Façade
Message façade pattern shortcomings
Version Number pattern
Version Number Pattern
Sequence Blocks
Stored Procedures for Autogenerated Keys
Fast Lane Pattern
Summary
Transaction Management
Topics
What is a transaction?
ACID properties
Transaction demarcation
Resource managers
Isolation levels
Isolation Level
WebSphere - Setting Isolation Level for EJB
WebSphere - CMP EJB Access Intent
WSAD - Setting Access Intent
WSAD - Setting Data Source Isolation Level
WebLogic – Isolation Level
Basics
Manage your own transactions
Change isolation level
EJB Transaction Basics
Transaction Propagation
Client Managed Transaction
Bean Managed Transaction
Container Managed Transaction
Transaction Outcome
Vetoing Transaction
Let the container manage transactions
CMT and the Session Façade
CMT and other EJBs
Transactions and Message Driven Beans
Distributed transaction
Two-phase commit
Aborting a global transaction
Optimizations
Window of doubt
JMS, EJB, XA
Using XA-enabled data source
Increase concurrency by reducing transaction isolation level
Keep transactions short
Multi-step wizard “the wrong way”
What’s wrong?
Multi-step wizard “the right way”
Summary
Performance
Topics
Overview
Visitor, hit, user
Load, throughput, response time
Response time
Effect of load on the system
Saturation and buckle points
Scaling
Performance and scalability are different!
Problem Areas
CPU utilization
Measure CPU utilization everywhere
Symptoms of underutilization
What causes underutilization?
Network capacity problem?
Synchronization problem?
Slow external resource?
Is the test pushing the system hard enough?
Does your system scale?
Symptoms of burstiness
Infrequent synchronization problem?
Test driver synchronization problem?
Slow back-end systems?
Slow garbage collection?
Timeout problems?
Erratic network traffic?
Symptoms of overutilization
The components of CPU usage
High User CPU
High System CPU
High Wait CPU
Server hanging
Thread dump in WebSphere v5
Thread dump file
Uneven cluster loading
Load balancer configured correctly?
Plan of attack
Overview
What is WPT?
Download and install
record
Configure your system to use record
Record a session
Output from record
Details of running a stress test
Best Practices
Summary
Messaging Tier Patterns
Objectives
Java Message Service
JMS Programming: Overview
The JMS Interfaces
JMS PTP Programming: Example
One-to-one (Local)
One-to-one (Remote)
Request-Reply
One-to-Many
Many-to-one
Many-to-one With Reply
Many to Many
Hub and Spoke
Route to different queues based on message content
Break a composite message and process separately
Combine related messages to a single message
Send Large Messages Using the Memento Pattern
Summary
Architecting Security
Objectives
Security Functionality
What Can You Secure?
Form-based Authentication
Form-based Authentication in J2EE
User Registry
LDAP User Registry
Custom User Registry HTTP
Single Sign On (SSO)
J2EE Authorization Model
WebSphere Authorization Model
Protecting Web Resources
Protecting EJB Methods
EJB Delegation Policies
Build and Deployment
What is Ant?
Writing a Build Script
How to run Ant?
Using ant from WSAD
Running Ant in WSAD
Advanced Task
Automating Deployment
WebSphere Deployment Tasks
JUnit and Eclipse
Objectives
What is JUnit?
Who uses JUnit?
Why JUnit?
The xUnit Philosophy
A JUnit Test
Running the tests
Swing-based Test Runner
Text-based Test Runner
JUnit Basics
assertTrue
assertEquals
assertSame
assertNull
The failure message
The Test Class
The Test Method
The Test Suite
JUnit Design
JUnit with Ant
JUnit with Eclipse
Create a Test Case
Running Tests
Eclipse Test Runner Icons
Rerun an individual test
Failure Trace
Debug with JUnit
Test Suite Wizard
Testing Strategies
Specific Techniques
Testing simple Java classes
Testing with databases
Testing web applications
Test-Driven Design
Test-Driven Design
Parting Thoughts
Summary
Struts Architecture and Overview
Objectives
Review: MVC Model
Review: Request, Session and Application
What is Struts?
Struts Flow
Components in Struts
The Model
The View
The Controller
Struts Flow
struts-config.xml
struts-config.xml Content
The element in the struts-config.xml
The element in the struts-config.xml
The element in the struts-config.xml
The element in the struts-config.xml
Sample struts-config.xml
The Role of web.xml for the Application
Configuring Struts in the web.xml
web.xml Content
Steps to Configuring Struts in the web.xml
Step 1. Configuring the Action Servlet Instance in the web.xml
Action Servlet Config Example
Step 2. Configuring the Action Servlet Mapping in web.xml
Prefix Mapping Example
Extension Mapping Example
Step 3. Configuring the Struts Tag Libraries in the web.xml
Sample web.xml
Summary