Download pdf - dsfdsfdsff

Transcript
  • 199

    Sum

    mar

    y

    7.6.

    3B

    est

    desi

    gn p

    ract

    ices

    Wh

    en u

    sin

    g an

    y pe

    rsis

    ten

    ce s

    olut

    ion

    wit

    h R

    estl

    et, y

    ou s

    hou

    ld t

    ry lo

    adin

    g an

    d st

    orin

    gth

    e st

    ate

    of y

    our

    reso

    urce

    s ea

    ch ti

    me

    a ServerResource in

    stan

    ce is

    cre

    ated

    in o

    rder

    topr

    oces

    s a

    new

    cal

    l. T

    he

    goal

    is to

    res

    pect

    the

    stat

    eles

    s co

    nst

    rain

    t of

    RE

    ST.

    Th

    is c

    onst

    rain

    t do

    esn

    t m

    ean

    th

    at y

    our

    appl

    icat

    ion

    can

    t h

    ave

    stat

    e, b

    ut t

    hat

    th

    eco

    nve

    rsat

    ion

    bet

    wee

    n c

    lien

    ts a

    nd

    serv

    ers

    shou

    ldn

    t be

    dri

    ven

    by

    out-o

    f-ban

    d in

    form

    a-ti

    on s

    uch

    as

    cook

    ie-b

    ased

    ses

    sion

    s pr

    omot

    ed in

    the

    Serv

    let A

    PI.

    For

    eff

    icie

    ncy

    rea

    son

    s yo

    u sh

    ould

    con

    side

    r pu

    ttin

    g in

    pla

    ce d

    atab

    ase

    con

    nec

    tion

    pool

    s an

    d da

    ta c

    ach

    es i

    n y

    our

    Res

    tlet

    app

    licat

    ion

    sub

    clas

    ses,

    acc

    essi

    ng

    thos

    e m

    ech

    a-ni

    sms

    by c

    astin

    g th

    e re

    sult

    of th

    e ServerResource#getApplication()

    met

    hod.

    Ano

    ther

    opti

    on t

    o sh

    are

    stat

    e be

    twee

    n s

    ever

    al r

    esou

    rce

    inst

    ance

    s is

    via

    th

    e pa

    ren

    t Context

    inst

    ance

    , wh

    ich

    con

    tain

    s a

    map

    of a

    ttri

    bute

    s. W

    hen

    dea

    ling

    wit

    h t

    ran

    sien

    t da

    ta, s

    uch

    as

    a sh

    oppi

    ng

    cart

    or

    tran

    sact

    ion

    s ru

    nn

    ing

    acro

    ss s

    ever

    al w

    eb p

    ages

    , you

    sh

    ould

    ret

    hin

    k yo

    ur a

    pplic

    atio

    n d

    esig

    n t

    o tu

    rn t

    his

    dat

    ain

    to r

    esou

    rces

    , suc

    h a

    s a

    shop

    pin

    g ca

    rt r

    esou

    rce

    wit

    h a

    spe

    cifi

    c U

    RI.

    Th

    e st

    ate

    of th

    ose

    reso

    urce

    s m

    igh

    t be

    stor

    ed in

    a d

    atab

    ase

    like

    oth

    er r

    esou

    rces

    , may

    be w

    ith

    a s

    hor

    ter

    life-

    cycl

    e bu

    t wit

    hou

    t spe

    cial

    trea

    tmen

    t. F

    ar fr

    om b

    ein

    g a

    back

    war

    d st

    ep, t

    his

    sta

    tele

    ss c

    onst

    rain

    t can

    eve

    n b

    enef

    it y

    our

    end

    user

    sth

    ey w

    ont

    expe

    rien

    ce th

    e ty

    pica

    l ses

    sion

    exp

    irat

    ion

    issu

    e w

    hen

    taki

    ng

    too

    lon

    gto

    com

    plet

    e a

    purc

    has

    e or

    der,

    for

    exam

    ple.

    7.7

    Sum

    mar

    yIn

    th

    is c

    hap

    ter

    you

    lear

    ned

    bes

    t pr

    actic

    es t

    hat

    , ta

    ken

    tog

    eth

    er,

    mak

    e th

    e di

    ffer

    ence

    betw

    een

    a p

    roto

    type

    Res

    tlet a

    pplic

    atio

    n a

    nd

    a m

    ore

    mat

    ure

    one

    suita

    ble

    for

    prod

    uctio

    n.

    You

    firs

    t saw

    how

    to c

    ompl

    ete

    an a

    pplic

    atio

    n w

    ith

    the

    usua

    l web

    ele

    men

    ts m

    anip

    u-la

    ted

    in m

    ost

    web

    API

    s an

    d w

    ebsi

    tes,

    suc

    h a

    s H

    TM

    L f

    orm

    s h

    andl

    ing,

    sta

    tic

    file

    ser

    vin

    g,an

    d co

    okie

    man

    ipul

    atio

    n. E

    ach

    feat

    ure

    has

    bee

    n c

    aref

    ully

    illu

    stra

    ted

    in th

    e co

    nte

    xt o

    fth

    e on

    goin

    g m

    ail s

    erve

    r ex

    ampl

    e. Y

    ou a

    lso

    lear

    ned

    tw

    o co

    mpl

    emen

    tary

    way

    s to

    han

    dle

    web

    fee

    ds i

    n t

    he

    Ato

    m a

    nd

    RSS

    for

    mat

    s us

    ing

    two

    Res

    tlet

    ext

    ensi

    ons,

    com

    pari

    ng

    the

    adva

    nta

    ges

    and

    disa

    dvan

    -ta

    ges

    of e

    ach

    of

    them

    . Th

    en y

    ou le

    arn

    ed h

    ow t

    o re

    dire

    ct c

    lien

    t ca

    lls, e

    ith

    er m

    anua

    llyby

    set

    tin

    g th

    e pr

    oper

    HT

    TP

    stat

    uses

    or

    mor

    e au

    tom

    atic

    ally

    an

    d po

    wer

    fully

    wit

    h t

    he

    Redirector c

    lass

    . W

    e al

    so d

    iscu

    ssed

    per

    form

    ance

    an

    d m

    odul

    ariz

    atio

    n a

    spec

    ts i

    n o

    rder

    to

    deal

    wit

    hap

    plic

    atio

    ns

    grow

    ing

    in s

    ize

    and

    com

    plex

    ity.

    We

    look

    ed a

    t H

    TT

    P bu

    ilt-in

    feat

    ures

    suc

    ha

    con

    diti

    onal

    met

    hod

    pro

    cess

    ing,

    en

    tity

    com

    pres

    sion

    , an

    d ca

    chin

    g su

    ppor

    t. W

    e al

    soin

    trod

    uced

    Res

    tlet

    -spe

    cifi

    c fe

    atur

    es s

    uch

    as

    the

    serv

    er d

    ispa

    tch

    er, t

    he

    inte

    rnal

    rou

    ter,

    and

    the

    RIA

    P ps

    eudo

    prot

    ocol

    to c

    omm

    unic

    ate

    opti

    mal

    ly in

    side

    a R

    estl

    et c

    ompo

    nen

    t. Y

    oull

    now

    con

    tin

    ue e

    xplo

    rin

    g fu

    rth

    er R

    estl

    et F

    ram

    ewor

    k po

    ssib

    iliti

    es,

    such

    as

    depl

    oym

    ent

    in c

    loud

    com

    puti

    ng,

    web

    bro

    wse

    rs,

    and

    smar

    tph

    ones

    an

    d in

    nov

    ativ

    ese

    man

    tic

    web

    sup

    port

    .