Web Application Engineering & Content Management Übungsteil zu 184.209 VU 2.0 Übungsergänzungen zur Vorlesung an der Technischen Universität Wien Wintersemester 2014/2015 Univ.-Lektor Dipl.-Ing. Dr. Markus Schranz staatlich befugter und beeideter Ingenieurkonsulent für Informatik
Web Applikationsmanagement - Praxisbeispiel Mason2: ein PERL-basierter Web Application Server M a so n W e b A p p lica tio n S e rve r m o d e rn e Ko n ze p te zu m te ch n isch e n W e b S e rv ice M a n a g e m e n t Lö su n g e n fü r ty p isch e W e b A p p lica tio n D e velo p m e n u n d M a n a g e m e n t P ro b le m e W a rtb a rke it, Pe rfo rm a n ce, Z u ve rlä ssig ke it ca ch in g, d e b u g g in g, te m p la tin g, sta g in g,... ü b e r C G I, A p a ch e ::m o d _ p e rl o d e r a k tu e ll m it P S G I 2
Agenda Z u g ä n g e ve rte ile n W e b S e rve r Ko n fig u ra tio n M a so n Ko n fig u ra tio n A u fg a b e u n d W e rk ze u g e S e ssio n h a n d lin g Pe rsiste n te W Y S IW Y G D a te n b a n k a n b in d u n g E d ito r Re strictio n s: Ke in e La u fg a ra n tie a n W o ch e n e n d e n (b zw. W a rtu n g sfe n ster) 3
Perl-basierter Web Application Server D e fin itio n d e r in d iv id u e lle n B e isp ie le m a so n /p e rl scrip ts, sim p le B e isp ie le, p ro o f o f co n ce p t S im p le C M S Te m p la te fü r Ko m p o n e n te Ko m p o n e n te T ip p s fü r D B D e sig n fü r Fo rm u la r fü r D B -A u sle se, D B -E in tra g u n d A u fg a b e u n ter h ttp ://w e n g.cu ltu ra ll.co m :8 0 2 0 /A n g a b e W A E 4
Perl-basierter Web Application Server A rch ite k tu re n vo n W e b -A p p lik a tio n e n C lie n t W e b -S e rve r S ta n d a rd S o ftw a re In te rfa ce s zu W e b A p p lica tio n S e rve r S o ftw a re F ra m e w o rk M o d e ll d e s F ra m e w o rk s / A rch ite k tu r Fe a tu re s (Te m p la tin g, O O, e tc.) Ko n fig u ra tio n 5
Perl-basierter Web Application Server - Konfiguration Welchen Webserver? IIS Apache Welche Software-Struktur? Monolith WAS/ Framework Welche Integrationsform? CGI FastCGI 6 nginx Welche Sprache? JS C# Perl PHP Python Java Ruby Rack/Ruby WSGI/Python Servlets PSGI
Perl-basierter Web Application Server - Konfiguration Welche Rolle spielen die Komponenten in einer Web-Architektur? W e b serve r (z.b. A p a ch n gein, x) B etre u t Fea tu re s d e s P ro to kolls, sta tisch e D o k u m e n te, P rox y in g, alia sin g, S S L-Ze rtifik a te, v irtu e lle S e rve r, etc. W A S S o ftw a re C o o rd in a to r (z.b. p lasta ckrm u p an,) S erviciert e in e S o ftw are-a p p lika tio n, M em o ry M g m t, S tart-pa ra m Ko n fig u ra tio n d e s W A S, ru n tim e e n v iro n m en t, scale a b ility, C a ch in g In itia lisa tio n, D B -Reso u rce s, e tc. O ffe riert d ie In te g ra tio n sfo rm (S e rv le ts, PSG C,IGm I, o d _ p h p ) W e b F ra m e w o rk (W A S S o ftw a re C o n cep t, zb P H P, R u bpy,o EP Ty /M th oanso, n) B ie te t d e n E n tw ick le rn Ko m fo rt u n d Fe a tu re s d e r jew e ilig e n S p r Z u g riffe a u f Re so u rce n d e s W A S -C o o rd in a to rs u n d d es W e b -S e r S o ftw a re -M o d elle fü r ko m p lexe s W e b -A p p lik a tio n sm an a g e m e n t Te m p la tin g, C ach in g, M u lti-m a n d a tin g, E rro r-h a n d lin g, e tc. 7
Perl-basierter Web Application Server konkrete Konfiguration N g in x a ls W e b se rve r E in fa ch e Ko n fig u ra tio n fü r sta tisch e Fä lle S im p le s M e n g e n g e rü st fü r S k a lie rb a rke it S p e zie lle Ko n fig fü r M a so n 2 -Ko m p o n e n te n P rox y a u f sta rm a n se rv ice Id e n tifizie ru n g d e r M a n d a n te n (Ü b u n g sg ru p p e n ) u n d sp e zifisch e s P ro x y in g a u f O rd n e r d e r M a n d a n te n 8
Perl-basierter Web Application Server konkrete Konfiguration S ta rm a n a ls P S G I-A d m in istra to r ( W A S S o ftw a re C o o rd in a to r ) P ro ze ss, d er e in e W e b -A p p lik a tio n d ed izie rt sta rte t E ig e n e s S e rv ice a u f sp e zie lle m Po rt, M u lti-p ro ce ss fü r S k a lie rb a rke it (in itia l 5 P ro ze ss b e i Ü b u n g ) M o d u le k ö n n e n zb m e m -sh a re d a rb e ite n, Pa ra m e t S ta rt w o rke rs M o d u le im sh a re d m e m o ry *.p sg i a ls Ko n fig u ra tio n sd a te i d e r W e b -A p p lik a tio n, h i 9
Perl-basierter Web Application Server konkrete Konfiguration P S G I a ls In te ra k tio n sm o d e ll zu m W e b se rve r ( Pe rl W e b se rve r G a te w ay In te rfa ce S p e cific S ta n d a rd in te rfa ce zw isch en W e b -S e rve rn u n d Pe rl a p p lica tio n s o dw e re b fra m e w o rk s E in e P S G I-A p p e rh ä lt d e n R e q u e st vo m W e b serve r H a sh -A rg u m e n t u n d liefe rt e in A rray m it 3 E le m e n A n tw o rt S ta tu s (h ttp -sta tu s) H e a d e rs / M e ta d a ta C o n te n t-b o d y 10
Perl-basierter Web Application Server Terminology in PSGI W e b S e rve r P S G I S erve r Ist e in e P S G I-A p p lica tion u n d e in S e rve r. E s ve rh ä lt sich w ie e in e A p p lik a tion, w e n n au fg e ru fe n, k a n n se in erse its a b e r w e ite re A p p lik a tio n e nsta aurm frua)fe n n ( Fra m e w o rk d e ve lo p e rs E in e (w e b ) a p p lica tio n a k ze p tie rt H TT P -Re q u e sts u n d b e a n tw o rte t sie. E in e P S G I (w tu t d ie s ko n fo rm zu r P S G I S ch n ittste lle, w a s d ie Ü b e rg a b e u n d Re to u rn ie ru n g d e r P E rg e b n isse d e fin ie rt. (In u n se re m Fa ll h a b e n w ir im m e r P S G I A p p s) M id d lew are Ist e in Pe rl-p ro g ra m m, d a s d ie U m g e b u n g fü r e in e P S G I(-ko n fo rm e ) A p p lica tio n an b ie te t (in u n se re m sta Fallrm a nod e r p la ck u p ) A p p licatio n s N im m t H TT P re q u e sts e n tg e g e n, b e a n tw o rte t o d e r d isp a tch e d zu e in e r w e b a p p lica d e rart ko n fig u rie rt (in u n se re m n gfa in xll) S ch rie b e n so lch e S o ftw a re w ie M a so n 2, P O E T, sta rm an, e tc. W e b A p p lica tio n d ev elo p e rs D a s sin d w ir; w ir n u tze n d ie o b ig e n Fe atu re s, u m kon k re te S o ftw a re fü r A n w e n d u n 11
Perl-basierter Web Application Server der WAS P O E T a ls U m g e b u n g sb e re ite r Fra m e w o rk /m id d le w a re fü r M a so n -E n tw ick le r. E s ve rw e n P S G I/P la ck zu r S e rve r-in te g ra tio n, M a so n 2 fü r Re q u e st u n d Te m p la tin g u n d C PA N -M o d u le fü r C a ch in g, Lo g g in g M a so n 2 a ls O b je k to rie n tie rte s E n tw ick lu n g sfra m e w o rk Fo k u s a u f Te m p la tin g, sta tisch e E le m e n te u n d Pe rl a ls d S p ra ch e zu r S o ftw a re in teg ra tio n M e ist g e m e in sa m m it d e m Pa rtn e r P O E T, a b e r a u ch a ls T E n g in e in D a n ce r o d e r C a ta ly st e in se tzb a r A ls H T M L::M a so n (M a so n 1 ) m it A p a ch e 2 /m o d _ p e rl2 A ls M a so n 2 b e sch rie b e n in C PA N (z.b. M a so n ::M a n u a ve rw e n d e t Ko m p o n e n te n, M e th o d e n, Filte r, Te m p la te s 12
Mason2 Handling Statische Mason-Komponente H e llo W o rld < % in it> m y $ te x t = d ie se r Te x t w ird n ie a n g e ze ig t ; < /% in it> 13
Mason2 Handling Argumente in Mason-Komponenten Hello World, this page is for users that are at least <% $.age %> years old. <%class> has 'name'; has 'age' => (required => 1); </%class> <%init> my $text = test ; </%init> 14
Mason2 Handling Template hierarchie: Base.mc <%augment wrap> <html> <head><title><% $mytitle %></title> <body> <& inner() &> </body> </html> <%init> my $mytitle = $.title; </%init> </%augment> 15
Mason Handling Persistent Database connection Hello World <% $dbresults %> <%init> my $dbresults = ; my $sth = $dbh->prepare( SELECT... ); $sth->execute(...); while (my $tmp = $sth>fetchrow_hashref()) { # push(@myresult,$tmp); $dbresults.= $tmp->{ name }; } </%init> Mehr dazu bei der Angabe, bei DBI und www.masonhq.com Mason::Manual (u.a.) Beispiel unter http://weng.culturall.com:8020/wae99/ 16
Perl-basierter Web Application Server Komponententypen.m c H a u p tko m p o n e n te n S ie e n tsp re ch e n (m e ist) e in er W e b -Pa g e E n d u n g in U R L n ich t ve rw e n d e t.m i in te rn e Ko m p o n e n te n W e rd e n vo n H a u p tko m p o n e n te n e in g e se tzt M ü sse n m it.m i-e n d u n g in te g rie rt w e rd e n.m p p u re -p e rl Ko m p o n e n te n Ke in e H T M L-In te g ra tio n m ö g lich 17