Sun Webserv J2EE

Embed Size (px)

Citation preview

  • 8/9/2019 Sun Webserv J2EE

    1/47

    Ho w t o Bu i l d an E-Com m erce App l i ca t i on

    u s i n g J2EE

    Caro l M cD ona ld

    Co de Cam p En g ine er

  • 8/9/2019 Sun Webserv J2EE

    2/47

    Code Camp A g e n d a

    J2EE & Blu ep r in t s Application Architecture and J2EE Blueprints E-Commerce Application Design

    En t er p r ise Java Bean s(EJB)

    Designing and implementing the Business Model: Ent i t y Beans, Sta te less and St a t e f u l Se ssi o n Beans Serv le t s , Java Server Pag es (JSP)

    Designing and architecting the "View" or Presentationlogic

    Assem b l i ng and Dep loy ing the J2EEApplication: Transact ions JTSand JTA Describe how the sample application uses the transaction

    capabilities of the J2EEplatform to simplify componentdevelopment.

    Secur i ty How to use J2EEsecurity to safeguard your e-commerce

    application

  • 8/9/2019 Sun Webserv J2EE

    3/47

    Do w n l o a d Co d e Ca m p s

    A l l sl i des w i t h no tes a re on y ou r CD

    Yo u can d o w n l o a d th i s an d o th er Cod e Cam ps :

    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

  • 8/9/2019 Sun Webserv J2EE

    4/47

    J2EE& BlueprintsA g e n d a

    Application Architecture and J2EE Sun BluePrintsDesign Guidelines Architecture of the sample application

  • 8/9/2019 Sun Webserv J2EE

    5/47

    Arch i tect u r e and th e Cub e

    Architectingyour application UsingTiersTiers and

    LayersLayersaffect the applicationCapabilitiesCapabilities

  • 8/9/2019 Sun Webserv J2EE

    6/47

    CapabilitiesCapabilities= Non-Functional SystemRequirements

    Ava i lab i l i t yAva i lab i l i t y : service is access ib le Rel iab i l i t yRe l iab i l i t y: cons is tency of application and

    transactions

    Capaci tyCapaci ty : can serve # u sers Extens ib i l i t yEx tens ib i l i t y: can a d d f u n ct i o n a l i t y

    Flex ib i l i t yF lex ib i l i t y: can su p p o r t ch a n g e s

    Per fo rm anc ePer fo rm anc e : good r espo nse t im e

    Scalab i l i t ySca lab i l i t y : ca n support i nc reased lo ad

  • 8/9/2019 Sun Webserv J2EE

    7/47

    Exam p le Arch i tectu re Requ i rem en t s

    E-Co m m er ce Ap p s: Many Clients,

    l o t s o f r ead ing ,

    l e ss upda t i ng ,

    low contention N e e d H i g h pe r fo r m ance and sca lab i l i t ype r fo r m ance and sca lab i l i t y fo r Read ing

    d a t a

    I nsu r anc e In t r ane t App :

    Fewer Clients, Low con cu r r en cy High transaction isolation level, N e e d H i g h e r

    Consis tency

    Rel iab i l i t yRe l iab i l i t y o f Upd a tes to DBm o r e im p o r t an tm o r e im p o r t a n t thanperformance for Reading data

  • 8/9/2019 Sun Webserv J2EE

    8/47

    The Re la t i on sh ips be tw een t he Elem en t s o fA rc h i t ec tu re

    Arch i tec t ing your application Using Tiers and Layers af fect the

    application Capabi l i t ies

  • 8/9/2019 Sun Webserv J2EE

    9/47

    J2EEPla t fo rm Spec if i ca t i on

    JNDI

    J2SE

    JMS

    RMI/IIOP

    JDBC

    DatabaseDatabase

    AppClientApp

    Client

    App Client

    Container

    App Client

    Container

    HTTP/HTTPSHTTP/HTTPS

    J2SE

    RMIRMI

    J2SE

    JNDI

    JMS

    R

    MI/IIOP

    JDBC

    JTAJavaMail

    JAF J

    NDI

    JMS

    R

    MI/IIOP

    JDBC

    JTAJavaMail

    JAF

    HTTP/HTTPSHTTP/HTTPS

    AppletContainer

    AppletContainer

    AppletApplet JSPJSP ServletServlet EJBEJB

    Web ContainerWeb Container EJB ContainerEJB Container

    RMIRMI

    J2SEJ2SE

    C omponen ts r u n w it h i n Conta iner.

    Conta iner prov ides Run t im e env ir onm en t , J2SE & J2EEAPIs, a n d remo te

    c o m m u n i c a t i o n

  • 8/9/2019 Sun Webserv J2EE

    10/47

    Laye rs o f Ser vices: TheApplication Server provides servicestothe Container, which in turn providesservices to the EJB.

    PersistenceTransactionsNaming

    O

    RB

    DB

    Client

    Environment Services

    EJBEJB EJB

    Container

    Application Server

    Operating System Services

    Application Server ServicesApplication Server Services

    Container ServicesContainer Services

    ApplicationApplication

  • 8/9/2019 Sun Webserv J2EE

    11/47

    Layers

    Layers are abs t rac t ions o f u n d e r l yi n gi m p l e m e n t a t i o n

    Each Lay er h i d e s i m p l e m e n t a t i o n d e t a i l s o f l ay e r

    b e l o w The Conta ine r p ro v ides com po nen ts serv ices o ft h e l ay e rs be low

    A d v a n t a g e s:

    Easie r deve lopm en t , m a in ten ance fo r h i ghpe r fo r m ance , sca lab i l i t y

    Does n o t r equ i r e deve lope r to k n o w complexdetailsofd i st r i bu ted p r o t oco l s, concurrency,transactions, l oad ba lan c ing , secur i t y , resou rcep o o l i n g a n d s h a r in g

  • 8/9/2019 Sun Webserv J2EE

    12/47

    App l i ca t ion Server : Key Services

    Dispatch ing

    Developer

    Session M anagem en t ,

    Caching

    ThreadA l l oca t i on

    App l ica t io n s Servers areprimarily

    Resource ManagersResource Managers

    Object Poo l i ng

    App l i ca t io ns Servers M a n a g e : d i spa t ch ing , th read a l l oca t i on ,

    po o ls , caches , l oad ba la nc ing , clu ste r s

  • 8/9/2019 Sun Webserv J2EE

    13/47

    W h a t f e at u r e s m ig h t yo u l o o k f o r in a nApp l i ca t ion Server?

    Clustering

    LoadBalancing

    TransactionManagement

    Security

  • 8/9/2019 Sun Webserv J2EE

    14/47

    EJB Co n t ai n er Ser vices

    EJBEJB EJB

    Container

    Application Server

    Tran sact io n Secu r i t y

    Sta teM a n a g e m e n t

    Pers istenceLife Cycl e

    R emo te

    In te r face

    Transactionmanager

  • 8/9/2019 Sun Webserv J2EE

    15/47

    C o m p o n e n t s

    M o n o l i t h i c:1 b i n a ry f i l e

    Re co m p i l ed &

    l i n k e d f o r a n y

    c h a n g e s

    C o m p o n e n ts: p l u g -g a b l e Pa r t s. Im p l e m e n t a t io n s ep a r a t ed f r o m

    In te r face , only Interface published h i d e s i m p l e m e n ta t i o n d e ta i l s B e t te r des ign , eas ier u p d a t e s

    Bet t e r Flex ib i l i t y , Ex t ens ib i l i t yBet t er Flex ib i l i t y , Ext en sib i l i t y

  • 8/9/2019 Sun Webserv J2EE

    16/47

    Arch i tect u r e and th e Cub e

  • 8/9/2019 Sun Webserv J2EE

    17/47

    HTML Web Server

    RMI / IIOP

    Application Server

    Data Base

    n -t i e r A r ch i t e ctu r e w i t h J2EE

    RDBMS

    PeopleSoftSAP R/3

    Legacy

    Systems

    networknetwork

    Browserclients

    C++, VB..

    clients

    Java

    clients

    HTTP

    BeansContainer

    Clients EIS Tier

  • 8/9/2019 Sun Webserv J2EE

    18/47

    Tiers

    Tie rs separ a t e fun ct io n a l i t y

    Presentation Logic, Business Logic, Data Schema

    Adv an tages :

    One tier can be changed w i t h o u t ch a n g i n g t h er es t= easie r up da tes

    Lo w e r d e p l o ym e n t and m a i n t e n a n c e costs.

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

  • 8/9/2019 Sun Webserv J2EE

    19/47

    CapabilitiesCapabilitiesNon-Functional Requirements

    W ebServer

    W ebServer

    W ebServer

    Ap pServer

    Ap pServer

    Ap pServer

    ROUTER

    Reliability, Availability, Extensibility,Reliability, Availability, Extensibility,

    Flexibility, Scalability, Goes upFlexibility, Scalability, Goes up

    ROUTER

    W i t h Goo d Arch i tec tu re , Layer ingLayer ing , TiersTiers,Load Ba lan c ing , Clus ter in g, Tran sact ion M gm t, Secur i ty

  • 8/9/2019 Sun Webserv J2EE

    20/47

    W h y J2EE?

    Gives you the Adv an tages of a Standard izedLayeredLayered , TierTier Architecture:

    Simp l i f i es the complexity of a bu i ld in g n -t i e rapp l i c a t i ons.

    Standard izes an API between c o m p o n e n t s andapplication server c o n t a i n e r .

    J2EEApp l i ca t io n Server and Con ta in e rs p ro v ide t he

    f r am ew ork Se rvi ces

  • 8/9/2019 Sun Webserv J2EE

    21/47

    A g e n d a J2EE& Blueprints

    J2EE Architecture Sun BluePrintsDesign Guidelines Architecture of the sample application

  • 8/9/2019 Sun Webserv J2EE

    22/47

    The J2EEPlatformHas a Rich Set o f APIs

    Middle

    Tier

    EIS

    Tier

    Client

    Client

    Client

    Client

    Other Services:JNDI, JMS,

    JavaMail

    EnterpriseJavaBean

    EnterpriseJavaBean

    Enterprise

    Information

    Systems (EIS):

    Relational-Database,

    LegacyApplications,

    ERP Systems

    Client

    Web Server

    JSP, Servlet,

    HTML, XML

    Application

    Server

    Client

    Tier

    Firewall

  • 8/9/2019 Sun Webserv J2EE

    23/47

    Why J2EEBlueprints

    Rich APIs M o re t h an o n e w ay ofdoing things

    SimilarProblems

    Need to l eve r age t i m e -t est edso l u t i ons

    Dont reinvent the wheel

    BluePrints

    Provides Answer s,Examples of Best Pract ices

  • 8/9/2019 Sun Webserv J2EE

    24/47

    J2EEBlueprints

    Guide l ines and Best p rac t ices f o r designing n-tierenterprise applications with J2EE

    J2EEbluepr in ts inc lude:

    Book, Designing Enterprise Applications

    Application (sou rce cod e)

    Java Pet Store

    FREE:

    h t t p :/ / ja va .su n .co m / j2 ee

  • 8/9/2019 Sun Webserv J2EE

    25/47

    B l u e p r i n t s

    FREE: h t t p :/ / ja va .su n .co m / j2 ee

  • 8/9/2019 Sun Webserv J2EE

    26/47

    J2EEJ2EEDel i ve rab lesDe l i ve rab les

    J2EEJ2EE

    J2EEJ2EE

    Speci f i ca t ionSpeci f i ca t ion

    J2EEJ2EEReferenceReference

    I m p l e m e n t a t i o nI m p l e m e n t a t i o n

    J2EEJ2EEB luePr in t sB luePr in t s

    J2EEJ2EECompat i b i l i t yCompa t i b i l i t y

    Test Su i t eTest Su i t e

  • 8/9/2019 Sun Webserv J2EE

    27/47

    JavaPet StoreDemo

  • 8/9/2019 Sun Webserv J2EE

    28/47

    Some Key BluePrintsQuestions-Issues Faced by Developers

    W h e n t o u se Serv lets verses JavaServerPages?

    W here t o sto re cl ien t session st at e:client-tier, web-tier or EJBtier?

    Access Dat a Base Resou rces via EJBordirectly from JSPJavaBean ?

    W h e n t o u se EJBcomponents? W h e n t o u se Sessio n Bean s and when to

    use En t i ty Bean s?

  • 8/9/2019 Sun Webserv J2EE

    29/47

    Design of Sample ApplicationBlue p r in t s Ch o ices:

    Blueprints Choices:Client tier

    H T M L Cl ients for End-User Web Access

    XM L for Data ex te rn a l i za t i on (Orde r p rocu rem en t )

    Web Server tier JavaServer Pages(JSP)

    for d y n a m i c co n t e n t g e n e ra t i o n

    Application Server tier EJBfor bu siness log ic

  • 8/9/2019 Sun Webserv J2EE

    30/47

    J2EEBlueprints Guidelines

    1 . Scen ar io s o r U se Cases

    2. partitioning of functionality into modules3. Application architecture using Model-View-

    Controller:

    1. assignment of functionality to tiers:

    1. Design of the Model2. Design of the View

    3. Design of the Controller

    2. object decomposit ion within tiers

    Process for developing an application fromr e q u i r e m e n t s, t o d e si g n , t o i m p l e m e n t a t i o n

  • 8/9/2019 Sun Webserv J2EE

    31/47

    1) Sample Application Shopping Scenario

    1. Web-based b r o w s i n g of a product ca ta log2. Creation and maintenance of a sho pp ing car t

    3. User account creation/ Login

    4. Placin g o rd er s5. Secure order processing

    1. B2B transactions

    2 . Ex t er n al isa t io n o f o r d er d at a (expressed in XML)

    3 . Or d er co n f i r m a t io n using e-mail

  • 8/9/2019 Sun Webserv J2EE

    32/47

    1 ) U se Case Sh o p p in g Scen ar io

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

    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

  • 8/9/2019 Sun Webserv J2EE

    33/47

    Sh op pin g Scen ar io Sequ en ce Diagram

    : C u s t o m e r

    Ca ta log Shopp ing

    Cart

    Or de r Inventory Ma i l e r Cont rol ler Accoun t

    add i tem to ca r tadd i tem to ca r t

    b rowse p roduc ts

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

    ge t accoun t de ta i l s

    c rea te o rde r

    update inventory

    send ema i l rece ip t

  • 8/9/2019 Sun Webserv J2EE

    34/47

    J2EEBlueprints

    1. Scenarios or Use Cases

    2 . p a r t i t i o n i n g o f f u n ct i o n a l i t y i n t o m o d u l e s

    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 decomposit ion within tiers

    Process for developing an application fromr e q u i r e m e n t s, t o d e si g n , t o i m p l e m e n t a t i o n

    2 ) Di i d h A l i i I M d l

  • 8/9/2019 Sun Webserv J2EE

    35/47

    2 ) Di vi d e t h e Ap p l i ca t i o n I n t o M o d u l e sBased o n Serv ices (Fu n ct ion a l i t y )

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

    information

    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 save

    selected items for the session.

    O r d e r Order Processing Module: performs order

    Processing when user buys the items in the

    cart.

    2 ) Di i d t h A l i t i I t M d l

  • 8/9/2019 Sun Webserv J2EE

    36/47

    2 ) Di vi d e t h e Ap p l i ca t i o n I n t o M o d u l e sBased o n Services

    I n v e n t o r y Inventory Module: maintains informationon the number of each type of product in

    stock.

    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.

  • 8/9/2019 Sun Webserv J2EE

    37/47

    In t e r r el a t i o n sh i p o f t h e m o d u l e s

    C o n t r o l

    C ata l og

    A c c o u n t

    Inventory

    O r d e r M a i l

    Cart

    browse

    new/existing account

    checkout

    add/removeitems

    Userinterface

  • 8/9/2019 Sun Webserv J2EE

    38/47

    J2EEBluepr ints

    1. Scenarios or Use Cases

    2. partit ioning of functionality into modules

    3 . App l i ca t i on a r ch i t ectu re usi ng M od e l -V iew -Con t ro l l e r :

    1 . a ssi g n m e n t o f f u n ct i o n a l i t y t o t i e r s:1. Design of the M o d e l

    2. Design of the View

    3. Design of the Con t ro l l e r

    2. object decomposition within tiers

    Process for developing an application fromr e q u i r e m e n t s, t o d e si g n , t o i m p l e m e n t a t i o n

    Di id A l i t i Ob j t i t 3

  • 8/9/2019 Sun Webserv J2EE

    39/47

    Divide App l i ca t i on Ob jects in to 3ca tegor ies :

    Model View Controller (MVC) UI Pattern M o d e l represents the application bu siness da t a and ru l es

    View is a scr ee n r e p r ese n t a t i o n o f m o d e l , presen t s th euse r i n t e r face

    Con t ro l l e r m e d i a t e s their i n t e ra c t i o n s

  • 8/9/2019 Sun Webserv J2EE

    40/47

    M od e l View Con t ro l l e r Design Pa t t e rn

    View Controller

    Model

    User event

    Business Event

    View selection

    Get

    Data

    To Display

    JSP

    JavaBeans

    components

    Session EJB

    And

    Servlet classes

    Entity EJB and Session EJB

  • 8/9/2019 Sun Webserv J2EE

    41/47

    Assign m en t o f Fu n ct i on a l i t y t o Tie r sAssign m en t o f Fu n ct i on a l i t y t o Tie r s

    View Co n t ro l le r M o d el

    PresentationLogic

    ApplicationRequests

    BusinessServices

    PersistenceDomainObjects

    Presen t a t io n Bu sin ess Lo g ic Data

  • 8/9/2019 Sun Webserv J2EE

    42/47

    MVC With J2EETechnology

    Build ViewView in the W eb -tier Use JSPcomponents for p r e se n t a t i o n l a yo u tp r e se n t a t i o n l a yo u t Custom tags and JavaBeanscomponents for

    p r e se n t a t i o n l o g i cp r e se n t a t i o n l o g i c

    Build Cont ro l l e rCon t ro l l e r in the W e b/ EJBtier Serv le t for d ispa tch ingd ispa tch ing Session bean for co n t r o l w i t h i n b u si n e ssco n t r o l w i t h i n b u si n e ss

    ob jec tsob jec ts

    Build M o d e lM o d e l in the EJBtier Session beans for Bu sin ess Ser v icesBu sin ess Ser v ices: Process

    and Rules Ent i t y beans to maintain m o d e l d a t am o d e l d a t a

    Assign m en t o f Fu n ct i on a l i t y to Tiers o r#A

  • 8/9/2019 Sun Webserv J2EE

    43/47

    Assign m en t o f Fu n ct i on a l i t y t o Tiers o rVer t i ca l Layer in g

    PresentationControl

    PresentationLayout

    BusinessServices

    DomainObjects

    Data AccessObjects

    Session Ent i ty DAOServ le t

    JSP

  • 8/9/2019 Sun Webserv J2EE

    44/47

    W h a t a r e Do m a in Ob j e ct s?

    Domain Objectsm o d e l t h e re al w o r l den t i t i esen t i t i es, nounsnouns in business problem

    Also known asData M od e l , bu siness ob ject

    m o d e l Example

    User Account,Account,

    Order,Order, Product,Product,

    InventoryInventory

  • 8/9/2019 Sun Webserv J2EE

    45/47

    W h at ar e Bus ine ss Serv ices?

    Bu sin ess Ser vices M o d el t h e verbsverbs inapplication

    Bu sin ess p ro cesses are the servicesservices in t h e

    u se cases Example

    Br owseBr owse Catalog

    Ad dAd d i tem to Cart PurchasePurchase items

    Sample Application Architecture Vert ica l Layer ing

  • 8/9/2019 Sun Webserv J2EE

    46/47

    servlet

    Catalog

    Cont ro l l e rShopping

    Inventory

    Order

    Account

    JSP

    Mailer

    JSP

    EntityEntity EJBsEJBsSessionSessionEJBsEJBs

    Produc tsI t e m s

    JavaBean

    Orde rs

    Accounts

    Cont ro l le rCon t ro l le r

    Java

    Bean

    DomainObjects

    BusinessServices

    PresentationLayout

    Sample Application Architecture Vert ica l Layer ing

    Presentation

    Control

    ViewView

  • 8/9/2019 Sun Webserv J2EE

    47/47

    S u m m a r y

    W e w e n t o ve r :

    Advantages of ho r i zon ta l l ay e r sho r i zon ta l l ay e r s

    Advantages of Ver t i ca l Tie rsVer t i ca l Tie rs

    Af fect o fA f fect o f LayersLayers an d TiersTiers o no n Capabi l i t iesCapabi l i t ies .. the pr ocess o f a rch i tec t i n gpr ocess o f a rch i tec t i n g the sample

    application

    the M o d e l Vi ew Co n t r o l l erM o d e l Vi ew Co n t r o l l e r Design Pattern