47
How to Build an E-Commerce Application using J2EE Carol McDonald Code Camp Engineer

How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

  • Upload
    donga

  • View
    227

  • Download
    5

Embed Size (px)

Citation preview

Page 1: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

How to Build an E-Commerce Application using J2EE™

Carol McDonald

Code Camp Engineer

Page 2: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Code Camp Agenda

• J2EE™ & Blueprints

– Application Architecture and J2EE– Blueprints E-Commerce Application Design

• Enterprise JavaBeans™ (EJB™)– Designing and implementing the Business Model:

• Entity Beans, Stateless and Stateful Session Beans• Servlets , Java ServerPages™ (JSP™)

– Designing and architecting the "View" or Presentation logic

• Assembling and Deploying the J2EE™ Application:– Transactions JTS™ and JTA™

• Describe how the sample application uses the transaction capabilities of the J2EE™ platform to simplify component development.

– Security How to use J2EE™ security to safeguard your e-commerce application

Page 3: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Download Code Camps

• All slides with notes are on your CD

• You can download this and other Code Camps :– EJB, Java Performance, J2ME, JINI, JMS, JSP, XML

http://www.sun.com/developer/evangcentral– under Events: Developer Code Camps

• ALSO– You can also ask questions there

– Listen to audiocasts

Page 4: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EE™ & Blueprints Agenda

• Application Architecture and J2EE• Sun BluePrints™ Design Guidelines• Architecture of the sample application

Page 5: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Architecture and the Cube

Architecting your application Using TiersTiers andLayersLayers affect the application CapabilitiesCapabilities

Page 6: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

CapabilitiesCapabilities = Non-Functional System Requirements

•• AvailabilityAvailability: service is accessible

•• ReliabilityReliability: consistency of application and transactions

•• CapacityCapacity: can serve # users

•• ExtensibilityExtensibility: can add functionality

•• FlexibilityFlexibility: can support changes

•• PerformancePerformance: good response time

•• ScalabilityScalability: can support increased load

Page 7: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Example Architecture Requirements

• E-Commerce Apps:– Many Clients, – lots of reading, – less updating, – low contention– Need High performance and scalabilityperformance and scalability for Reading

data

• Insurance Intranet App: – Fewer Clients, Low concurrency– High transaction isolation level, Need Higher

Consistency–– ReliabilityReliability of Updates to DB more importantmore important than

performance for Reading data

Page 8: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

The Relationships between the Elements of Architecture

Architecting your application Using Tiers and Layers affect the application Capabilities

Page 9: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EE™ Platform Specification

JN

DI

J2SE

JMS

RM

I/IIO

P

JD

BC

DatabaseDatabase

AppClientApp

Client

App Client ContainerApp Client Container

HTTP/HTTPSHTTP/HTTPS

J2SE

RMIRMI

J2SEJ

ND

I

JMS

RM

I/IIO

P

JD

BC

JTA JavaMail

JAF JN

DI

JMS

RM

I/IIO

P

JD

BC

JTA JavaMail

JAF

HTTP/HTTPSHTTP/HTTPS

Applet Container

Applet Container

AppletApplet JSPJSP ServletServlet EJBEJB

Web ContainerWeb Container EJB™ ContainerEJB™ Container

RMIRMI

J2SEJ2SE

Components run within Container.

Container provides Runtime environment, J2SE ™ & J2EE™ APIs, and remote communication

Page 10: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Layers of Services: The Application Server provides services to the Container, which in turn provides services to the EJB.

PersistenceTransactionsNaming

ORB

DB

Client

Environment Services

EJBEJB EJB

Container

Application Server

Operating System Services

Application Server ServicesApplication Server Services

Container ServicesContainer Services

ApplicationApplication

Page 11: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Layers

• Layers are abstractions of underlying implementation

• Each Layer hides implementation details of layer below

• The Container provides components services of the layers below

• Advantages:– Easier development, maintenance for high

performance, scalability

– Does not require developer to know complex details of distributed protocols, concurrency, transactions, load balancing, security, resource pooling and sharing…

Page 12: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Application Server : Key Services

Dispatching

Developer

Session Management,Caching

Thread Allocation

Applications Servers are primarily Resource ManagersResource Managers

Object Pooling

Applications Servers Manage: dispatching, thread allocation, pools, caches, load balancing, clusters

Page 13: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

What features might you look for in an Application Server?

Clustering

LoadBalancing

TransactionManagement

Security

Page 14: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

EJB Container Services

EJBEJB EJB

Container

Application Server

Transaction Security

State Management

PersistenceLife Cycle

RemoteInterface

Transaction manager

Page 15: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Components

Monolithic: 1 binary file

Recompiled & linked for any changes

Components: • plug-gable Parts. • Implementation separated from

Interface, only Interface published• hides implementation details• Better design, easier updates•• Better Flexibility, ExtensibilityBetter Flexibility, Extensibility

Page 16: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Architecture and the Cube

Page 17: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

HTML Web Server

RMI / IIOP

Application Server

Data Base

n-tier Architecture with J2EE™

RDBMS

PeopleSoftSAP R/3

LegacySystems

networknetwork

Browserclients

C++, VB..clients

Javaclients

HTTP

BeansContainer

Clients EIS Tier

Page 18: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Tiers

• Tiers separate functionality§ Presentation Logic, Business Logic, Data Schema

• Advantages:§ One tier can be changed without changing the

rest= easier updates

§ Lower deployment and maintenance costs.

§§ Capabilities go up: Flexibility , ExtensibilityCapabilities go up: Flexibility , Extensibility

Page 19: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

CapabilitiesCapabilitiesNon-Functional Requirements

WebServer

WebServer

WebServer

AppServer

AppServer

AppServer

ROUTER

Reliability, Availability, Extensibility,Reliability, Availability, Extensibility,Flexibility, Scalability, Goes up Flexibility, Scalability, Goes up

ROUTER

With Good Architecture, LayeringLayering, TiersTiers,Load Balancing, Clustering, Transaction Mgmt, Security …

Page 20: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Why J2EE™?

• Gives you the Advantages of a StandardizedLayeredLayered, TierTier Architecture:

• Simplifies the complexity of a building n-tier applications.

• Standardizes an API between components and application server container.

• J2EE™ Application Server and Containers provide the framework Services

Page 21: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Agenda J2EE™ & Blueprints

• J2EE Architecture• Sun BluePrints ™ Design Guidelines• Architecture of the sample application

Page 22: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

The J2EE™ Platform Has a Rich Set of APIs

Middle Tier

EIS Tier

Client

Client

Client

Client

Other Services:JNDI, JMS,JavaMail™

Enterprise JavaBean

Enterprise JavaBean

Enterprise Information

Systems (EIS):

Relational-Database,

Legacy Applications,ERP Systems

Client

Web ServerJSP, Servlet, HTML, XML

ApplicationServer

Client Tier

Firewall

Page 23: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Why J2EE™ Blueprints

Rich APIs More than one way of doing things

Similar Problems

Need to leverage time-tested solutionsDon’t reinvent the wheel

BluePrints

Provides Answers,Examples of Best Practices

Page 24: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EE™ Blueprints

• Guidelines and Best practices for designing n-tierenterprise applications with J2EE™

• J2EE™ blueprints include:

– Book, Designing Enterprise Applications

– Application (source code)—• “Java Pet Store”

FREE:

• http://java.sun.com/j2ee

Page 25: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Blueprints

FREE: http://java.sun.com/j2ee

Page 26: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EEJ2EE™™ DeliverablesDeliverables

J2EEJ2EE™™

J2EEJ2EE™™SpecificationSpecification

J2EEJ2EE™™ReferenceReference

ImplementationImplementation

J2EEJ2EE™™BluePrintsBluePrints

J2EEJ2EE™™Compatibility Compatibility Test SuiteTest Suite

Page 27: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

“Java™ Pet Store” Demo

Page 28: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Some Key BluePrints™ Questions-Issues Faced by Developers

• When to use Servlets verses JavaServerPages™?

• Where to store client session state: client-tier, web-tier or EJB™ tier?

• Access Data Base Resources via EJB™ or directly from JSP™ JavaBean ?

• When to use EJB™ components?• When to use Session Beans and when to

use Entity Beans?

Page 29: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Design of Sample Application Blueprints Choices:

Blueprints Choices:

Client tier• HTML Clients for End-User Web Access

• XML for Data externalization (Order procurement)

Web Server tier• JavaServer Pages™ (JSP)

for dynamic content generation

Application Server tier• EJB™ for business logic

Page 30: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EE™ Blueprints Guidelines

1. Scenarios or Use Cases

2. partitioning of functionality into modules

3. Application architecture using Model-View-Controller: 1. assignment of functionality to tiers:

1. Design of the Model

2. Design of the View

3. Design of the Controller

2. object decomposition within tiers

Process for developing an application from requirements, to design, to implementation

Page 31: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

1) Sample Application – Shopping Scenario

1. Web-based browsing of a product catalog

2. Creation and maintenance of a shopping cart

3. User account creation/ Login

4. Placing orders

5. Secure order processing1. B2B transactions

2. Externalisation of order data (expressed in XML)

3. Order confirmation using e-mail

Page 32: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

1) Use Case Shopping Scenario

C r e a t e / U p d a t e C u s t o m e r A c c o u n t

C u s t o m e r

A d d O r d e r t o W a r e h o u s e S y s t e m

( e x t e r n a l )

L o g i n t o C u s t o m e r A c c o u n t

S e n d R e c e i p t

c h e c k o u t o r d e r i t e m s

< < i n c l u d e s > >

< < e x t e n d > >

< < i n c l u d e s > >

B r o w s e C a t a l o g

a d d i t e m s t o s h o p p i n g c a r t

Page 33: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Shopping Scenario Sequence Diagram

: C u s t o m e r

Ca ta log S h o p p i n g

Cart

O r d e r Inventory M a i l e rCont ro l le r A c c o u n t

add i t em to ca r t add i t em to ca r t

b rowse p roduc ts

c h e c k o u t ge t i t ems i n ca r t

ge t accoun t de ta i l s

c rea te o rde r

update inventory

s e n d e m a i l r e c e i p t

Page 34: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EE™ Blueprints

1. Scenarios or Use Cases

2. partitioning of functionality into modules

3. Application architecture using Model-View-Controller: 1. assignment of functionality to tiers:

1. Design of the Model

2. Design of the View

3. Design of the Controller

2. object decomposition within tiers

Process for developing an application from requirements, to design, to implementation

Page 35: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

2) Divide the Application Into Modules Based on Services (Functionality)

A c c o u n t User Account Module: tracks user accountinformation

C a t a l o g Product Catalog Module: provides searchfor products, and product details

C a r t Shopping Cart Module: allows user to saveselected items for the session.

O r d e r Order Processing Module: performs orderProcessing when user buys the items in thecart.

Page 36: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

2) Divide the Application Into Modules Based on Services

I n v e n t o r y

Inventory Module: maintains informationon the number of each type of product instock.

M a i l Messaging Module: sends confirmationreceipt messages.

C o n t r o l Control Module: control interactionsbetween user (browse, add items, check out) and business objects.

Page 37: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Interrelationship of the modules

C o n t r o l

C a t a l o g

A c c o u n t

InventoryO r d e r M a i l

Car t

browse

new/existing account

checkout

add/removeitems

Userinterface

Page 38: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

J2EE™ Blueprints

1. Scenarios or Use Cases

2. partitioning of functionality into modules

3. Application architecture using Model-View-Controller: 1. assignment of functionality to tiers:

1. Design of the Model

2. Design of the View

3. Design of the Controller

2. object decomposition within tiers

Process for developing an application from requirements, to design, to implementation

Page 39: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Divide Application Objects into 3 categories:

• Model View Controller (MVC) UI Pattern• Model represents the application business data and rules

• View is a screen representation of model, presents the user interface

• Controller mediates their interactions

Page 40: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Model View Controller Design Pattern

View Controller

Model

User event

Business Event

View selection

Get DataTo Display

JSPJavaBeanscomponents

Session EJBAndServlet classes

Entity EJB and Session EJB

Page 41: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Assignment of Functionality to TiersAssignment of Functionality to Tiers

View Controller Model

PresentationLogic

ApplicationRequests

BusinessServices

PersistenceDomainObjects

Presentation Business Logic Data

Page 42: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

MVC With J2EE™ Technology

ï Build ViewView in the Web-tierï Use JSP™ components for presentation layoutpresentation layoutï Custom tags and JavaBeans™ components for

presentation logicpresentation logicï Build ControllerController in the Web / EJB™ tier

ï Servlet for dispatchingdispatchingï Session bean for control within business control within business

objects objects ï Build ModelModel in the EJB™ tier

ï Session beans for Business ServicesBusiness Services: Process and Rules

ï Entity beans to maintain model datamodel data

Page 43: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Assignment of Functionality to Tiers or Vertical Layering

#A

PresentationControl

PresentationLayout

BusinessServices

DomainObjects

Data AccessObjects

Session Entity DAOServlet

JSP

Page 44: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

What are Domain Objects?

• Domain Objects model the real world entitiesentities, nouns nouns in business problem

• Also known as Data Model, business object model

• Example – User Account, Account,

–– Order, Order,

–– Product, Product,

–– InventoryInventory

Page 45: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

What are Business Services?

• Business Services Model the verbsverbs in application

• Business processes are the servicesservices in the use cases

• Example

–– BrowseBrowse Catalog

–– AddAdd item to Cart

–– PurchasePurchase items

Page 46: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

servlet

Catalog

ControllerShopping

Inventory

Order

Account

JSP

Mailer

JSP

Entity Entity EJBsEJBsSession Session EJBsEJBs

ProductsItems

JavaBean

Orders

Accounts

ControllerController

JavaBean

DomainObjects

BusinessServices

PresentationLayout

Sample Application Architecture Vertical Layering

PresentationControl

ViewView

Page 47: How to Build an E-Commerce Application using J2EEecomm/Dokumenten/J2EEGeneral/HowtoBuild… · How to Build an E-Commerce Application using J2EE ... JavaMail JAF HTTP/ HTTPS ... •

Summary

• We went over:

– Advantages of horizontal layershorizontal layers

– Advantages of Vertical TiersVertical Tiers

–– Affect ofAffect of LayersLayers and Tiers Tiers onon CapabilitiesCapabilities..

– the process of architectingprocess of architecting the sample application

– the Model View ControllerModel View Controller Design Pattern