Active AJAX based Active AJAX based Active AJAX based Active ...
Unit v Introduction to Ajax and Web Services
-
Upload
gopivrajan -
Category
Documents
-
view
224 -
download
1
Transcript of Unit v Introduction to Ajax and Web Services
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 1/39
UNIT V INTRODUCTION TO AJAX and WEB SERVICES 9AJAX: Ajax Client Server Architecture-XML Http Request Object-Call Bac Meth!"s# $eb Services: %ntr!"ucti!n- Java &
services Basics ' Creatin() *ublishin() +estin( an" ,escribin( a $eb services $S,L.-C!nsu/in( a &eb service) ,ataba
,riven &eb service 0r!/ an applicati!n ' SOA*1
5.1 AJAX: AJAX CLIENT SERVER ARCHITECTURE
• AJAX stan"s 0!r As2nchr!n!us Ja vaScript an" XML1 AJAX is a ne& technique 0!r creatin( better) 0aster) an" /!
interactive &eb applicati!ns &ith the help !0 XML) H+ML) CSS) an" Java Script1
• Ajax uses XH+ML 0!r c!ntent) CSS 0!r presentati!n) al!n( &ith ,!cu/ent Object M!"el an" JavaScript 0!r "2na/
c!ntent "ispla21
• C!nventi!nal &eb applicati!ns trans/it in0!r/ati!n t! an" 0r!/ the server usin( s2nchr!n!us requests1 %t /eans 2
0ill !ut a 0!r/) hit sub/it) an" (et "irecte" t! a ne& pa(e &ith ne& in0!r/ati!n 0r!/ the server1
• $ith AJAX) &hen 2!u hit sub/it) JavaScript &ill /ae a request t! the server) interpret the results) an" up"ate t
current screen1 %n the purest sense) the user &!ul" never n!& that an2thin( &as even trans/itte" t! the server1
• XML is c!//!nl2 use" as the 0!r/at 0!r receivin( server "ata) alth!u(h an2 0!r/at) inclu"in( plain text) can be use"
• AJAX is a &eb br!&ser techn!l!(2 in"epen"ent !0 &eb server s!0t&are1
• A user can c!ntinue t! use the applicati!n &hile the client pr!(ra/ requests in0!r/ati!n 0r!/ the server in th
bac(r!un"1
• %ntuitive an" natural user interacti!n1 Clicin( is n!t require") /!use /!ve/ent is a su00icient event tri((er1
• ,ata-"riven as !pp!se" t! pa(e-"riven1
AJAX is Based on Oen S!anda"ds
AJAX is base" !n the 0!ll!&in( !pen stan"ar"s:
• Br!&ser-base" presentati!n usin( H+ML an" Casca"in( St2le Sheets CSS.1
• ,ata is st!re" in XML 0!r/at an" 0etche" 0r!/ the server1
• Behin"-the-scenes "ata 0etches usin( XMLHttpRequest !bjects in the br!&ser1
• JavaScript t! /ae ever2thin( happen1
1
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 2/39
5.# X$L HTT% RE&UEST OBJECT
+he XMLHttpRequest Object
All /!"ern br!&sers supp!rt the XMLHttpRequest !bject1
+he XMLHttpRequest !bject is use" t! exchan(e "ata &ith a server behin" the scenes1 +his /eans that it is p!ssible t! up"a
parts !0 a &eb pa(e) &ith!ut rel!a"in( the &h!le pa(e1
Create an XMLHttpRequest Object
All /!"ern br!&sers Chr!/e) %345) 6ire0!x) Sa0ari) an" Opera. have a built-in XMLHttpRequest !bject1
S2ntax 0!r creatin( an XMLHttpRequest !bject:
variable 7 ne& XMLHttpRequest.#
Ol" versi!ns !0 %nternet 3xpl!rer %38 an" %39. use an ActiveX Object:
variable 7 ne& ActiveXObjectMicr!s!0t1XMLH++*.#
+! han"le all br!&sers) inclu"in( %38 an" %39) chec i0 the br!&ser supp!rts the XMLHttpRequest !bject1 %0 it "!es) create
XMLHttpRequest !bject) i0 n!t) create an ActiveXObject:
E'a()e
var xhttp#
i0 &in"!&1XMLHttpRequest. ;
xhttp 7 ne& XMLHttpRequest.#
2
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 3/39
< else ;
== c!"e 0!r %39) %38
xhttp 7 ne& ActiveXObjectMicr!s!0t1XMLH++*.#
<
Sen" a Request +! a Server
+! sen" a request t! a server) &e use the !pen. an" sen". /eth!"s !0 the XMLHttpRequest !bject:
xhttp1!pen>3+) ajax?in0!1txt) truexhttp1sen".#
Method Description
open(method, url, async)
Specifes the type o requestmethod: the type o request: GET or POSTurl: the server (fe) oc!tionasync: true (!synchronous) or !se (synchronous)
send() Sends the request to the server (used or GET)
send(string) Sends the request to the server (used or POST)
>3+ !r *OS+@
>3+ is si/pler an" 0aster than *OS+) an" can be use" in /!st cases1
H!&ever) al&a2s use *OS+ requests &hen:
• A cache" 0ile is n!t an !pti!n up"ate a 0ile !r "atabase !n the server.1
• Sen"in( a lar(e a/!unt !0 "ata t! the server *OS+ has n! sie li/itati!ns.1
• Sen"in( user input &hich can c!ntain unn!&n characters.) *OS+ is /!re r!bust an" secure than >3+1
>3+ Requests
A si/ple >3+ request:
E'a()e
xhttp1!pen>3+) "e/!?(et1asp) true.#
xhttp1sen".#
%n the exa/ple ab!ve) 2!u /a2 (et a cache" result1 +! av!i" this) a"" a unique %, t! the RL:
E'a()e
xhttp1!pen>3+) "e/!?(et1asp@t7 5 Math1ran"!/.) true.#
xhttp1sen".#
%0 2!u &ant t! sen" in0!r/ati!n &ith the >3+ /eth!") a"" the in0!r/ati!n t! the RL:
"
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 4/39
E'a()e
xhttp1!pen>3+) "e/!?(et1asp@0na/e7Henr2Dlna/e76!r") true.#
xhttp1sen".#
*OS+ Requests
A si/ple *OS+ request:
E'a()e
xhttp1!pen*OS+) "e/!?p!st1asp) true.#
xhttp1sen".#
+! *OS+ "ata lie an H+ML 0!r/) a"" an H++* hea"er &ith setRequestHea"er.1 Speci02 the "ata 2!u &ant t! sen" in t
sen". /eth!":
E'a()e
xhttp1!pen*OS+) ajax?test1asp) true.#
xhttp1setRequestHea"erC!ntent-t2pe) applicati!n=x-&&&-0!r/-urlenc!"e".#
xhttp1sen"0na/e7Henr2Dlna/e76!r".#
Method Description
set#equest$e!der(he!der% v!ue)
&dds $TTP he!ders to the request
he!der: specifes the he!der n!'ev!ue: specifes the he!der v!ue
+he url - A 6ile On a Server
+he url para/eter !0 the !pen. /eth!") is an a""ress t! a 0ile !n a server:
xhttp1!pen>3+) ajax?test1asp) true.#
+he 0ile can be an2 in" !0 0ile) lie 1txt an" 1x/l) !r server scriptin( 0iles lie 1asp an" 1php &hich can per0!r/ acti!ns !n t
server be0!re sen"in( the resp!nse bac.1
As2nchr!n!us - +rue !r 6alse@
AJAX stan"s 0!r As2nchr!n!us JavaScript an" XML) an" 0!r the XMLHttpRequest !bject t! behave as AJAX) the as2
para/eter !0 the !pen. /eth!" has t! be set t! true:
xhttp1!pen>3+) ajax?test1asp) true.#
Sen"in( as2nchr!n!us requests is a hu(e i/pr!ve/ent 0!r &eb "evel!pers1 Man2 !0 the tass per0!r/e" !n the server a
ver2 ti/e c!nsu/in(1 Be0!re AJAX) this !perati!n c!ul" cause the applicati!n t! han( !r st!p1
$ith AJAX) the JavaScript "!es n!t have t! &ait 0!r the server resp!nse) but can instea":
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 5/39
• execute !ther scripts &hile &aitin( 0!r server resp!nse
• "eal &ith the resp!nse &hen the resp!nse rea"2
As2nc7true
$hen usin( as2nc7true) speci02 a 0uncti!n t! execute &hen the resp!nse is rea"2 in the !nrea"2statechan(e event:
E'a()e
xhttp1!nrea"2statechan(e 7 0uncti!n. ;
i0 xhttp1rea"2State 77 E DD xhttp1status 77 FF. ;
"!cu/ent1(et3le/entB2%""e/!.1innerH+ML 7 xhttp1resp!nse+ext#
<
<#
xhttp1!pen>3+) ajax?in0!1txt) true.#
xhttp1sen".#
G!u &ill learn /!re ab!ut !nrea"2statechan(e in a later chapter1
As2nc70alse
+! use as2nc70alse) chan(e the thir" para/eter in the !pen. /eth!" t! 0alse:
xhttp1!pen>3+) ajax?in0!1txt) 0alse.#
sin( as2nc70alse is n!t rec!//en"e") but 0!r a 0e& s/all requests this can be !1
Re/e/ber that the JavaScript &ill O+ c!ntinue t! execute) until the server resp!nse is rea"21 %0 the server is bus2 !r sl!&) t
applicati!n &ill han( !r st!p1
No!e: $hen 2!u use as2nc70alse) "! O+ &rite an !nrea"2statechan(e 0uncti!n - just put the c!"e a0ter the sen". state/en
E'a()e
xhttp1!pen>3+) ajax?in0!1txt) 0alse.#
xhttp1sen".#
"!cu/ent1(et3le/entB2%""e/!.1innerH+ML 7 xhttp1resp!nse+ext#
5.* CALL BAC+ $ETHODS
+he a,a'S-ess/ a))0a 2 /eth!" attaches a 0uncti!n t! be execute" &henever an AJAX request c!/pletes success0ul+his is an Ajax 3vent1
S3n!a'
Here is the si/ple s2ntax t! use this /eth!" I
$(document)1ajaxSuccess callbac .
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 6/39
%a"a(e!e"s
Here is the "escripti!n !0 all the para/eters use" b2 this /eth!" I
• a))0a I +he 0uncti!n t! execute1 +he event !bject) XMLHttpRequest) an" settin(s use" 0!r that request are pass
as ar(u/ents t! the callbac1
E'a()e
Assu/in( &e have 0!ll!&in( H+ML c!ntent in result1ht/l 0ile I
hK+H%S %S R3SL+111=hK
6!ll!&in( is a si/ple exa/ple a si/ple sh!&in( the usa(e !0 this /eth!"1
ht/l
hea" title+he juer2 3xa/ple=title script t2pe 7 text=javascript
src 7 http:==ajax1(!!(leapis1c!/=ajax=libs=jquer2=1K1N=jquer21/in1js=script
script t2pe 7 text=javascript lan(ua(e 7 javascript "!cu/ent.1rea"20uncti!n. ;
=P >l!bal variable P= var c!unt 7 F#
Q"river.1clic0uncti!nevent.; Qsta(eF.1l!a"result1ht/l.# <.#
=P >ets calle" &hen request starts P=
"!cu/ent.1ajaxStart0uncti!n.; c!unt55# Qsta(eK.1ht/lhKStarts) C!unt : 5 c!unt 5 =hK.# <.#
=P >ets calle" &hen request is sent P= "!cu/ent.1ajaxSen"0uncti!nevt) req) set.; c!unt55# Qsta(e.1ht/lhKSen"s) C!unt : 5 c!unt 5 =hK.# Qsta(e.1appen"hKRL : 5 set1url 5 =hK.# <.#
=P >ets calle" &hen request c!/pletes P= "!cu/ent.1ajaxC!/plete0uncti!nevent)request)settin(s.; c!unt55# Qsta(eN.1ht/lhKC!/pletes)C!unt: 5 c!unt 5 =hK.# <.#
=P >ets calle" &hen request is st!ppe" P= "!cu/ent.1ajaxSt!p0uncti!nevent)request)settin(s.; c!unt55# Qsta(eE.1ht/lhKSt!ps) C!unt : 5 c!unt 5 =hK.#
*
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 7/39
<.#
=P >ets calle" &hen all request c!/pletes success0ull2 P= "!cu/ent.1ajaxSuccess0uncti!nevent)request)settin(s.; c!unt55# Qsta(e8.1ht/lhKSuccess)C!unt : 5 c!unt 5 =hK.# <.#
<.#
=script =hea"
b!"2
pClic !n the butt!n t! l!a" result1ht/l 0ile:=p
"iv i" 7 sta(eF st2le 7 bac(r!un"-c!l!r:blue# S+A>3 - F ="iv
"iv i" 7 sta(eK st2le 7 bac(r!un"-c!l!r:blue#
S+A>3 - K ="iv
"iv i" 7 sta(e st2le 7 bac(r!un"-c!l!r:blue# S+A>3 - ="iv
"iv i" 7 sta(eN st2le 7 bac(r!un"-c!l!r:blue# S+A>3 - N ="iv
"iv i" 7 sta(eE st2le 7 bac(r!un"-c!l!r:blue# S+A>3 - E ="iv
"iv i" 7 sta(e8 st2le 7 bac(r!un"-c!l!r:blue# S+A>3 - 8 ="iv
input t2pe 7 butt!n i" 7 "river value7L!a" ,ata =
=b!"2
=ht/lAJAX is an acr!n2/ stan"in( 0!r As2nchr!n!us JavaScript an" XML an" this techn!l!(2 help us t! l!a" "ata 0r!/ the serv
&ith!ut a br!&ser pa(e re0resh1
%0 2!u are ne& &ith AJAX) % &!ul" rec!//en" 2!u (! thr!u(h !ur Ajax +ut!rial be0!re pr!cee"in( 0urther1
Juer2 is a (reat t!!l &hich pr!vi"es a rich set !0 AJAX /eth!"s t! "evel!p next (enerati!n &eb applicati!n1
L!a"in( si/ple "ata
+his is ver2 eas2 t! l!a" an2 static !r "2na/ic "ata usin( Juer2 AJAX1 Juer2 pr!vi"es )oad/2 /eth!" t! "! the j!b I
+
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 8/39
S3n!a'
Here is the si/ple s2ntax 0!r )oad/2 /eth!" I
4se)e!o".l!a" RL) "ataT) callbacT .#Here is the "escripti!n !0 all the para/eters I
• URL I +he RL !0 the server-si"e res!urce t! &hich the request is sent1 %t c!ul" be a C>%) AS*) JS*) !r *H* scr
&hich (enerates "ata "2na/icall2 !r !ut !0 a "atabase1
• da!a I +his !pti!nal para/eter represents an !bject &h!se pr!perties are serialie" int! pr!perl2 enc!"e" para/ete
t! be passe" t! the request1 %0 speci0ie") the request is /a"e usin( the%OST /eth!"1 %0 !/itte") the6ET /eth!"
use"1
• a))0a I A callbac 0uncti!n inv!e" a0ter the resp!nse "ata has been l!a"e" int! the ele/ents !0 the /atche" s
+he 0irst para/eter passe" t! this 0uncti!n is the resp!nse text receive" 0r!/ the server an" sec!n" para/eter is t
status c!"e1
E'a()e
C!nsi"er the 0!ll!&in( H+ML 0ile &ith a s/all Juer2 c!"in( I
ht/l
hea" title+he juer2 3xa/ple=title script t2pe 7 text=javascript
src 7 http:==ajax1(!!(leapis1c!/=ajax=libs=jquer2=1K1N=jquer21/in1js=script
script t2pe 7 text=javascript lan(ua(e 7 javascript "!cu/ent.1rea"20uncti!n. ; Q"river.1clic0uncti!nevent.; Qsta(e.1l!a"=jquer2=result1ht/l.#
<.# <.# =script =hea"
b!"2
pClic !n the butt!n t! l!a" =jquer2=result1ht/l 0ile I=p
"iv i" 7 sta(e st2le 7 bac(r!un"-c!l!r:ccF# S+A>3 ="iv
input t2pe 7 butt!n i" 7 "river value 7 L!a" ,ata =
=b!"2
=ht/lHere )oad/2 initiates an Ajax request t! the speci0ie" RL 7,8-e"37"es-)!.!() 0ile1 A0ter l!a"in( this 0ile) all the c!ntent &!ul"
p!pulate" insi"e "iv ta((e" &ith %, stage1 Assu/in() !ur =jquer2=result1ht/l 0ile has just !ne H+ML line I
hK+H%S %S R3SL+111=hK
,
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 9/39
$hen 2!u clic the (iven butt!n) then result1ht/l 0ile (ets l!a"e"1
>ettin( JSO "ata
+here &!ul" be a situati!n &hen server &!ul" return JSO strin( a(ainst 2!ur request1 Juer2 utilit2 0uncti!ne!JSON
parses the returne" JSO strin( an" /aes the resultin( strin( available t! the callbac 0uncti!n as 0irst para/eter t! ta
0urther acti!n1
S3n!a'
Here is the si/ple s2ntax 0!r e!JSON/2 /eth!" I
4se)e!o".(etJSO RL) "ataT) callbacT .#Here is the "escripti!n !0 all the para/eters I
• URL I +he RL !0 the server-si"e res!urce c!ntacte" via the >3+ /eth!"1
• da!a I An !bject &h!se pr!perties serve as the na/e=value pairs use" t! c!nstruct a quer2 strin( t! be appen"e"
the RL) !r a pre0!r/atte" an" enc!"e" quer2 strin(1
• a))0a I A 0uncti!n inv!e" &hen the request c!/pletes1 +he "ata value resultin( 0r!/ "i(estin( the resp!nse b!as a JSO strin( is passe" as the 0irst para/eter t! this callbac) an" the status as the sec!n"1
E'a()e
C!nsi"er the 0!ll!&in( H+ML 0ile &ith a s/all Juer2 c!"in( I
ht/l
hea" title+he juer2 3xa/ple=title script t2pe 7 text=javascript
src 7 http:==ajax1(!!(leapis1c!/=ajax=libs=jquer2=1K1N=jquer21/in1js=script
script t2pe 7 text=javascript lan(ua(e 7 javascript "!cu/ent.1rea"20uncti!n. ; Q"river.1clic0uncti!nevent.;
1(etJSO=jquer2=result1js!n) 0uncti!nj". ; Qsta(e.1ht/lp a/e: 5 j"1na/e 5 =p.# Qsta(e.1appen"pA(e : 5 j"1a(e5 =p.# Qsta(e.1appen"p Sex: 5 j"1sex5 =p.# <.#
<.#
<.# =script =hea"
b!"2
pClic !n the butt!n t! l!a" result1js!n 0ile I=p
"iv i" 7 sta(e st2le 7 bac(r!un"-c!l!r:Qeee# S+A>3
-
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 10/39
="iv
input t2pe 7 butt!n i" 7 "river value 7 L!a" ,ata =
=b!"2
=ht/lHere Juer2 utilit2 /eth!" e!JSON/2 initiates an Ajax request t! the speci0ie" RL "es-)!.,son 0ile1 A0ter l!a"in( this 0ile)
the c!ntent &!ul" be passe" t! the callbac 0uncti!n &hich 0inall2 &!ul" be p!pulate" insi"e "iv ta((e" &ith %,stag
Assu/in() !ur result1js!n 0ile has 0!ll!&in( js!n 0!r/atte" c!ntent I
;na/e: Uara Ali)a(e : 94)sex: 0e/ale<$hen 2!u clic the (iven butt!n) then result1js!n 0ile (ets l!a"e"1
*assin( "ata t! the Server
Man2 ti/es 2!u c!llect input 0r!/ the user an" 2!u pass that input t! the server 0!r 0urther pr!cessin(1 Juer2 AJAX /a"e
eas2 en!u(h t! pass c!llecte" "ata t! the server usin( da!a para/eter !0 an2 available Ajax /eth!"1
E'a()e
+his exa/ple "e/!nstrate h!& can pass user input t! a &eb server script &hich &!ul" sen" the sa/e result bac an" &
&!ul" print it I
ht/l
hea" title+he juer2 3xa/ple=title script t2pe 7 text=javascript
src 7 http:==ajax1(!!(leapis1c!/=ajax=libs=jquer2=1K1N=jquer21/in1js=script
script t2pe 7 text=javascript lan(ua(e 7 javascript "!cu/ent.1rea"20uncti!n. ; Q"river.1clic0uncti!nevent.; var na/e 7 Qna/e.1val.# Qsta(e.1l!a"=jquer2=result1php) ;na/e:na/e< .# <.# <.# =script =hea"
b!"2
p3nter 2!ur na/e an" clic !n the butt!n:=p input t2pe 7 input i" 7 na/e sie 7 EF =br =
"iv i" 7 sta(e st2le 7 bac(r!un"-c!l!r:ccF# S+A>3 ="iv
input t2pe 7 butt!n i" 7 "river value 7 Sh!& Result =
1.
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 11/39
=b!"2
=ht/lHere is the c!"e &ritten in "es-)!. script I
@phpi0 ?R33S+na/eT .;
na/e 7 ?R33S+na/eT#
ech! $elc!/e 1 na/e#<@!& 2!u can enter an2 text in the (iven input b!x an" then clic Sh!& Result butt!n t! see &hat 2!u have entere" in th
input b!x1
Juer2 AJAX Meth!"s
G!u have seen basic c!ncept !0 AJAX usin( Juer21 6!ll!&in( table lists "!&n all i/p!rtant Juer2 AJAX /eth!"s &hich 2
can use base" 2!ur pr!(ra//in( nee" I
S/0/ Methods Description
1 juer21ajax !pti!ns . o!d ! re'ote p!3e usin3 !n $TTP request/
2 juer21ajaxSetup !pti!ns . Setup 3o4! settin3s or &5&6 requests/
" juer21(et url) "ataT) callbacT) t2peT . o!d ! re'ote p!3e usin3 !n $TTP GET request/
juer21(etJSO url) "ataT) callbacT . o!d 5SO0 d!t! usin3 !n $TTP GET request/
juer21(etScript url) callbacT . o!ds !nd e7ecutes ! 5!v!Script fe usin3 !n $TTP GET request/
* juer21p!st url) "ataT) callbacT) t2peT . o!d ! re'ote p!3e usin3 !n $TTP POST request/
+l!a" url) "ataT) callbacT . o!d $TM ro' ! re'ote fe !nd in8ect it into the DOM/
,serialie . Seri!i9es ! set o input ee'ents into ! strin3 o d!t!/
-serialieArra2 . Seri!i9es ! or's !nd or' ee'ents ie the /seri!i9e() 'ethod 4ut returns ! 5SO0d!t! structure or you to ;or ;ith/
Juer2 AJAX 3vents
G!u can call vari!us Juer2 /eth!"s "urin( the li0e c2cle !0 AJAX call pr!(ress1 Base" !n "i00erent events=sta(es 0!ll!&/eth!"s are available I
G!u can (! thr!u(h all the AJAX 3vents1
S11 Meth!"s D ,escripti!n
KajaxC!/plete callbac . Attach a 0uncti!n t! be execute" &henever an AJAX request c!/pletes1
ajaxStart callbac .
11
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 12/39
Attach a 0uncti!n t! be execute" &henever an AJAX request be(ins an" there is n!ne alrea"2 active1
Najax3rr!r callbac . Attach a 0uncti!n t! be execute" &henever an AJAX request 0ails1
EajaxSen" callbac . Attach a 0uncti!n t! be execute" be0!re an AJAX request is sent1
8ajaxSt!p callbac . Attach a 0uncti!n t! be execute" &henever all AJAX requests have en"e"1
9ajaxSuccess callbac . Attach a 0uncti!n t! be execute" &henever an AJAX request c!/pletes success0ull21
5.; WEB SERVICES: INTRODUCTION<
$eb services are !pen stan"ar" XML) SOA*) H++* etc1. base" $eb applicati!ns that interact &ith !ther &eb applicati!ns
the purp!se !0 exchan(in( "ata1
$eb Services can c!nvert 2!ur existin( applicati!ns int! $eb-applicati!ns1
,i00erent b!!s an" "i00erent !r(aniati!ns pr!vi"e "i00erent "e0initi!ns t! $eb Services1 S!/e !0 the/ are liste" here1
• A &eb service is an2 piece !0 s!0t&are that /aes itsel0 available !ver the internet an" uses a stan"ar"ie" XM
/essa(in( s2ste/1 XML is use" t! enc!"e all c!//unicati!ns t! a &eb service1 6!r exa/ple) a client inv!es a &eservice b2 sen"in( an XML /essa(e) then &aits 0!r a c!rresp!n"in( XML resp!nse1 As all c!//unicati!n is in XM &eb services are n!t tie" t! an2 !ne !peratin( s2ste/ !r pr!(ra//in( lan(ua(e--Java can tal &ith *erl# $in"!applicati!ns can tal &ith nix applicati!ns1
• $eb services are sel0-c!ntaine") /!"ular) "istribute") "2na/ic applicati!ns that can be "escribe") publishe") l!cate
!r inv!e" !ver the net&!r t! create pr!"ucts) pr!cesses) an" suppl2 chains1 +hese applicati!ns can be l!ca"istribute") !r &eb-base"1 $eb services are built !n t!p !0 !pen stan"ar"s such as +C*=%*) H++*) Java) H+ML) aXML1
• $eb services are XML-base" in0!r/ati!n exchan(e s2ste/s that use the %nternet 0!r "irect applicati!n-t!-applicati
interacti!n1 +hese s2ste/s can inclu"e pr!(ra/s) !bjects) /essa(es) !r "!cu/ents1
• A &eb service is a c!llecti!n !0 !pen pr!t!c!ls an" stan"ar"s use" 0!r exchan(in( "ata bet&een applicati!ns
s2ste/s1 S!0t&are applicati!ns &ritten in vari!us pr!(ra//in( lan(ua(es an" runnin( !n vari!us plat0!r/s can u &eb services t! exchan(e "ata !ver c!/puter net&!rs lie the %nternet in a /anner si/ilar t! inter-pr!cec!//unicati!n !n a sin(le c!/puter1 +his inter!perabilit2 e1(1) bet&een Java an" *2th!n) !r $in"!&s an" Linapplicati!ns. is "ue t! the use !0 !pen stan"ar"s1
+! su//arie) a c!/plete &eb service is) there0!re) an2 service that:
• %s available !ver the %nternet !r private intranet. net&!rs
• ses a stan"ar"ie" XML /essa(in( s2ste/
• %s n!t tie" t! an2 !ne !peratin( s2ste/ !r pr!(ra//in( lan(ua(e
• %s sel0-"escribin( via a c!//!n XML (ra//ar
• %s "isc!verable via a si/ple 0in" /echanis/
12
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 13/39
Co(onen!s o= We0 Se">ies
+he basic &eb services plat0!r/ is XML 5 H++*1 All the stan"ar" &eb services &!r usin( the 0!ll!&in( c!/p!nents
• SOA* Si/ple Object Access *r!t!c!l.
• ,,% niversal ,escripti!n) ,isc!ver2 an" %nte(rati!n.
• $S,L $eb Services ,escripti!n Lan(ua(e.
All these c!/p!nents have been "iscusse" in the $eb Services Architecture chapter1
Ho? Does a We0 Se">ie Wo"@
A &eb service enables c!//unicati!n a/!n( vari!us applicati!ns b2 usin( !pen stan"ar"s such as H+ML) XML) $S,L) aSOA*1 A &eb service taes the help !0 :
• XML t! ta( the "ata
• SOA* t! trans0er a /essa(e
• $S,L t! "escribe the availabilit2 !0 service1
G!u can buil" a Java-base" &eb service !n S!laris that is accessible 0r!/ 2!ur Visual Basic pr!(ra/ that runs !n $in"!&s1
G!u can als! use CQ t! buil" ne& &eb services !n $in"!&s that can be inv!e" 0r!/ 2!ur &eb applicati!n that is base" JavaServer *a(es JS*. an" runs !n Linux1
E'a()e
C!nsi"er a si/ple acc!unt-/ana(e/ent an" !r"er pr!cessin( s2ste/1 +he acc!untin( pers!nnel use a client applicati!n bu &ith Visual Basic !r JS* t! create ne& acc!unts an" enter ne& cust!/er !r"ers1
+he pr!cessin( l!(ic 0!r this s2ste/ is &ritten in Java an" resi"es !n a S!laris /achine) &hich als! interacts &ith a "atabase st!re in0!r/ati!n1
+he steps t! per0!r/ this !perati!n are as 0!ll!&s:
• +he client pr!(ra/ bun"les the acc!unt re(istrati!n in0!r/ati!n int! a SOA* /essa(e1
1"
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 14/39
• +his SOA* /essa(e is sent t! the &eb service as the b!"2 !0 an H++* *OS+ request1
• +he &eb service unpacs the SOA* request an" c!nverts it int! a c!//an" that the applicati!n can un"erstan"1
• +he applicati!n pr!cesses the in0!r/ati!n as require" an" resp!n"s &ith a ne& unique acc!unt nu/ber 0!r th
cust!/er1
• ext) the &eb service paca(es the resp!nse int! an!ther SOA* /essa(e) &hich it sen"s bac t! the client pr!(ra
in resp!nse t! its H++* request1
• +he client pr!(ra/ unpacs the SOA* /essa(e t! !btain the results !0 the acc!unt re(istrati!n pr!cess1
T3es o= We0 Se">ies
+here are /ainl2 t&! t2pes !0 &eb services1
K1 SOA* &eb services1
1 R3S+0ul &eb services1
•
5.5 JAVA WEB SERVICES BASICS
Ja>a ?e0 se">ies !-!o"ia) pr!vi"es c!ncepts an" exa/ples !0 t&! /ain java &eb services api: JAX-$S an" JAX-RS1 + java &eb service applicati!n can be accesse" b2 !ther pr!(ra//in( lan(ua(es such as 1et an" *H*1
Java &eb service applicati!n per0!r/ c!//unicati!n thr!u(h $S,L $eb Services ,escripti!n Lan(ua(e.1 +here are t& &a2s t! &rite java &eb service applicati!n c!"e: SOA* an" R3S+0ul1
Ja>a We0 Se">ies A%I
+here are t&! /ain A*%s "e0ine" b2 Java 0!r "evel!pin( &eb service applicati!ns since Java33 91
K. JAX<WS: 0!r SOA* &eb services1 +he are t&! &a2s t! &rite JAX-$S applicati!n c!"e: b2 R*C st2le an" ,!cu/ent st2le1
. JAX<RS: 0!r R3S+0ul &eb services1 +here are /ainl2 i/ple/entati!n currentl2 in use 0!r creatin( JAX-RS applicati!Jerse2 an" R3S+eas21
1
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 15/39
5. CREATIN6 %UBLISHIN6 TESTIN6 AND DESCRIBIN6 A WEB SERVICES /WSDL2
$S,L stan"s 0!r $eb Services ,escripti!n Lan(ua(e1 %t is the stan"ar" 0!r/at 0!r "escribin( a &eb service1 $S,L &a
"evel!pe" j!intl2 b2 Micr!s!0t an" %BM1
6eatures !0 $S,L
• $S,L is an XML-base" pr!t!c!l 0!r in0!r/ati!n exchan(e in "ecentralie" an" "istribute" envir!n/ents1
•
$S,L "e0initi!ns "escribe h!& t! access a &eb service an" &hat !perati!ns it &ill per0!r/1
• $S,L is a lan(ua(e 0!r "escribin( h!& t! inter0ace &ith XML-base" services1
• $S,L is an inte(ral part !0 niversal ,escripti!n) ,isc!ver2) an" %nte(rati!n ,,%.) an XML-base" &!rl"&i"
business re(istr21
• $S,L is the lan(ua(e that ,,% uses1
1
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 16/39
• $S,L is pr!n!unce" as &i-"ull an" spelle" !ut as $-S-,-L1
$S,L sa(e
$S,L is !0ten use" in c!/binati!n &ith SOA* an" XML Sche/a t! pr!vi"e &eb services !ver the %nternet1 A client pr!(ra
c!nnectin( t! a &eb service can rea" the $S,L t! "eter/ine &hat 0uncti!ns are available !n the server1 An2 special "atat2p
use" are e/be""e" in the $S,L 0ile in the 0!r/ !0 XML Sche/a1 +he client can then use SOA* t! actuall2 call !ne !0 t
0uncti!ns liste" in the $S,L1
Hist!r2 !0 $S,L
$S,L K1K &as sub/itte" as a $NC !te b2 Ariba) %BM) an" Micr!s!0t 0!r "escribin( services 0!r the $NC XML Activit2 !n XM
*r!t!c!ls in March FFK1
$S,L K1K has n!t been en"!rse" b2 the $!rl" $i"e $eb C!ns!rtiu/ $NC.) h!&ever it has just release" a "ra0t 0!r versi
1F that &ill be a rec!//en"ati!n an !00icial stan"ar".) an" thus en"!rse" b2 the $NC1
$S,L breas "!&n &eb services int! three speci0ic) i"enti0iable ele/ents that can be c!/bine" !r reuse" !nce "e0ine"1
+he three /aj!r ele/ents !0 $S,L that can be "e0ine" separatel2 are:
• +2pes
• Operati!ns
• Bin"in(
A $S,L "!cu/ent has vari!us ele/ents) but the2 are c!ntaine" &ithin these three /ain ele/ents) &hich can be "evel!pe" separate "!cu/ents an" then the2 can be c!/bine" !r reuse" t! 0!r/ c!/plete $S,L 0iles1
WSDL E)e(en!s
A $S,L "!cu/ent c!ntains the 0!ll!&in( ele/ents:
• De=ini!ion : %t is the r!!t ele/ent !0 all $S,L "!cu/ents1 %t "e0ines the na/e !0 the &eb service) "eclares /ulti
na/espaces use" thr!u(h!ut the re/ain"er !0 the "!cu/ent) an" c!ntains all the service ele/ents "escribe" here1
• Da!a !3es : +he "ata t2pes t! be use" in the /essa(es are in the 0!r/ !0 XML sche/as1
• $essae : %t is an abstract "e0initi!n !0 the "ata) in the 0!r/ !0 a /essa(e presente" either as an entire "!cu/ent
as ar(u/ents t! be /appe" t! a /eth!" inv!cati!n1
•
Oe"a!ion : %t is the abstract "e0initi!n !0 the !perati!n 0!r a /essa(e) such as na/in( a /eth!") /essa(e queue)business pr!cess) that &ill accept an" pr!cess the /essa(e1
• %o"! !3e : %t is an abstract set !0 !perati!ns /appe" t! !ne !r /!re en"-p!ints) "e0inin( the c!llecti!n !0 !perati!
0!r a bin"in(# the c!llecti!n !0 !perati!ns) as it is abstract) can be /appe" t! /ultiple transp!rts thr!u(h vari!bin"in(s1
• Bindin : %t is the c!ncrete pr!t!c!l an" "ata 0!r/ats 0!r the !perati!ns an" /essa(es "e0ine" 0!r a particular p
t2pe1
1*
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 17/39
• %o"! : %t is a c!/binati!n !0 a bin"in( an" a net&!r a""ress) pr!vi"in( the tar(et a""ress !0 the serv
c!//unicati!n1
• Se">ie : %t is a c!llecti!n !0 relate" en"-p!ints enc!/passin( the service "e0initi!ns in the 0ile# the services /ap t
bin"in( t! the p!rt an" inclu"e an2 extensibilit2 "e0initi!ns1
%n a""iti!n t! these /aj!r ele/ents) the $S,L speci0icati!n als! "e0ines the 0!ll!&in( utilit2 ele/ents:
• Do-(en!a!ion: +his ele/ent is use" t! pr!vi"e hu/an-rea"able "!cu/entati!n an" can be inclu"e" insi"e a
!ther $S,L ele/ent1
• I(o"! : +his ele/ent is use" t! i/p!rt !ther $S,L "!cu/ents !r XML Sche/as1
NOTE: $S,L parts are usuall2 (enerate" aut!/aticall2 usin( &eb services-a&are t!!ls1
Te WSDL Do-(en! S!"-!-"e
+he /ain structure !0 a $S,L "!cu/ent l!!s lie this:
"e0initi!ns
t2pes "e0initi!n !0 t2pes11111111 =t2pes
/essa(e "e0initi!n !0 a /essa(e1111 =/essa(e
p!rt+2pe !perati!n "e0initi!n !0 a !perati!n1111111
=!perati!n =p!rt+2pe
bin"in( "e0initi!n !0 a bin"in(1111 =bin"in(
service "e0initi!n !0 a service1111 =service="e0initi!ns
A $S,L "!cu/ent can als! c!ntain !ther ele/ents) lie extensi!n ele/ents an" a service ele/ent that /aes it p!ssible(r!up t!(ether the "e0initi!ns !0 several &eb services in !ne sin(le $S,L "!cu/ent1
*r!cee" 0urther t! anal2e an exa/ple !0 $S,L ,!cu/ent1
WSDL < de=ini!ion E)e(en!
he de=ini!ions ele/ent /ust be the r!!t ele/ent !0 all $S,L "!cu/ents1 %t "e0ines the na/e !0 the &eb service1
Here is the piece !0 c!"e 0r!/ the last chapter that uses thedefinitions ele/ent1
1+
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 18/39
"e0initi!ns na/e7Hell!Service tar(eta/espace7http:==&&&1exa/ples1c!/=&s"l=Hell!Service1&s"l x/lns7http:==sche/as1x/ls!ap1!r(=&s"l= x/lns:s!ap7http:==sche/as1x/ls!ap1!r(=&s"l=s!ap= x/lns:tns7http:==&&&1exa/ples1c!/=&s"l=Hell!Service1&s"l x/lns:xs"7http:==&&&1&N1!r(=FFK=XMLSche/a 111111111111111111111111111111111111111111111111="e0initi!ns6r!/ the ab!ve exa/ple) &e can c!nclu"e that "e0initi!ns:
• is a c!ntainer !0 all the !ther ele/ents1
• speci0ies that this "!cu/ent is calle"HelloService1
• speci0ies a targetNamespace attribute1 +he targetNamespace is a c!nventi!n !0 XML Sche/a that enables the $S,
"!cu/ent t! re0er t! itsel01 %n this exa/ple) &e have speci0ie" a targetNamespace
http:==&&&1exa/ples1c!/=&s"l=Hell!Service1&s"l
• speci0ies a "e0ault na/espace: x/lns7http:==sche/as1x/ls!ap1!r(=&s"l=1 All ele/ents &ith!ut a na/espace pre0
such as message !r portType) are there0!re assu/e" t! be a part !0 the "e0ault $S,L na/espace1
• speci0ies nu/er!us na/espaces that are use" thr!u(h!ut the re/ain"er !0 the "!cu/ent1
5. CONSU$IN6 A WEB SERVICE
C"ea!in and %-0)isin We0 Se">ie
1,
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 19/39
K1 Create a Java *r!ject WCalc$S1
1 Create a paca(e Wc!/1the!pentut!rials1&s1calc1
1-
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 20/39
N1 Create a Java class WCalculat!r an" t2pe the 0!ll!&in( c!"e1
FKFFNFEF8F9F4FYFZKF
KKKKNKE
paca(e c!/1the!pentut!rials1&s1calc#i/p!rt javax1j&s1$ebService# [$ebServicepublic class Calculat!r ; public int a""int a) int b. ; return a 5 b.# <
public int subint a) int b. ;
return a - b.# < <
E1 [$ebService ann!tati!n at the be(innin( !0 the class "e0initi!n tells the Java interpreter that &e inten" t! publish Athe /eth!"s !0 this class as a &eb service1 %0 &e &ant t! publish !nl2 particular /eth!"s then &e can u[$ebMeth!" ann!tati!n be0!re the /eth!" si(nature1
2.
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 21/39
81 %n !r"er t! publish !ur class an" its /eth!"s as &eb service &e nee" t! crate appr!priate stub 0iles !r arti0acts 0!r &service "epl!2/ent an" inv!cati!n1 6!rtunatel2 Java pr!vi"es a t!!l calle" W&s(en &hich (enerates JAX-$S p!rtabarti0acts use" in JAX-$S &eb services1
91 Open c!//an" pr!/pt !r ter/inal in Linux an" (! t! the pr!ject 0!l"er WCalc$S1
41 !& issue the 0!ll!&in( c!//an")
&s(en -cp bin -" bin c!/1the!pentut!rials1&s1calc1Calculat!r
the 'cp !pti!n speci0ies the classpath 0!r !ur Calculat!r class &hich is in Wbin 0!l"er) the '" !pti!n speci0ies &here t!place (enerate" !utput 0iles &hich is als! the Wbin 0!l"er in !ur case1
Y1 $e can als! have a l!! at the s!urce !0 the (enerate" 0iles b2 usin( the 's !pti!n pr!vi"e" b2 W&s(en1
&s(en -s src -cp bin -" bin c!/1the!pentut!rials1&s1calc1Calculat!r
21
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 22/39
Z1 !& &e nee" t! publish !ur class as a &eb service en"p!int1 6!r that &e use the static publish. /eth!" !0 t javax1x/l1&s13n"p!int class t! publish !ur WCalculat!r class as a &eb service in the speci0ie" c!ntext r!!t1
22
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 23/39
KF1 Create a paca(e Wc!/1the!pentut!rials1&s1calc1en"p!int1
KK1 Create a class WCalc3n"p!int*ublisher &ith /ain /eth!" an" t2pe the 0!ll!&in( c!"e1
2"
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 24/39
FKFFNFEF8F9F4FYFZ
KFKKKKN
paca(e c!/1the!pentut!rials1&s1calc1en"p!int# i/p!rt javax1x/l1&s13n"p!int#i/p!rt c!/1the!pentut!rials1&s1calc1Calculat!r# public class Calc3n"p!int*ublisher ;
public static v!i" /ainStrin(T ar(s. ; 3n"p!int1publishhttp:==l!calh!st:YFYF=Calc$S=Calculat!r)
ne& Calculat!r..# < <
K1 Run this class as WJava Applicati!n1
KN1 G!u /a2 n!t (et !utput in the C!ns!le1 +! chec &hether !ur class is publishe" as &eb service) !pen a br!&ser at2pe the RL /enti!ne" in the en"p!int &ith a para/eter @&s"l appen"e"1
http:==l!calh!st:YFYF=Calc$S=Calculat!r@&s"l
KE1 $hen 2!u run the applicati!n) the Java S3 9 plat0!r/ has a s/all &eb applicati!n server that &ill publish the &service at the a""ress http:==l!calh!st:YFYF=Calc$S=Calculat!r &hile the JVM is runnin(1
K81 %0 2!u see a lar(e a/!unt !0 XML that "escribes the 0uncti!nalit2 behin" the &eb service) then the "epl!2/entsuccess0ul1
C"ea!in and ons-(in a We0 Se">ie C)ien!
K1 Havin( publishe" the &eb service) &e n!& create a client &hich c!//unicates &ith the service an" "ispla2s tresult1
2
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 25/39
1 Create a Java pr!ject WCalc$SClient1
N1 Just lie W&s(en) JAX-$S als! pr!vi"es a t!!l calle" W&si/p!rt 0!r (eneratin( the arti0acts require" 0!r creatin( ac!nsu/in( a &eb service1 W&si/p!rt taes a &s"l 0ile as input1
E1 6r!/ the pr!ject 0!l"er in c!//an" pr!/pt !r ter/inal) issue the 0!ll!&in( c!//an")
&si/p!rt -s src -" bin http:== l!calh!st:YFYF=Calc$S=Calculat!r@&s"l
2
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 26/39
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 27/39
41 %n that paca(e) create a class WCalcClient &ith /ain /eth!" an" t2pe the 0!ll!&in( c!"e1
FKFFNFEF8F9F4
FYFZKFKKKKNKEK8K9
paca(e c!/1the!pentut!rials1&s1calc1client# i/p!rt c!/1the!pentut!rials1&s1calc1Calculat!r#i/p!rt c!/1the!pentut!rials1&s1calc1Calculat!rService# public class CalcClient ;
public static v!i" /ainStrin(T ar(s. ; int a 7 KF# int b 7 K# Calculat!rService calcService 7 ne& Calculat!rService.# Calculat!r calc 7 calcService1(etCalculat!r*!rt.# S2ste/1!ut1printlna 5 5 5 b 5 7 5 calc1a""a) b..# S2ste/1!ut1printlna 5 - 5 b 5 7 5 calc1suba) b..# <<
Y1 Run this class as Java Applicati!n1
Z1 G!u &ill (et the 0!ll!&in( !utput in the c!ns!le1
KF 5 K 7
KF ' K 7 -
5.F DATABASE DRIVEN WEB SERVICE GRO$ AN A%%LICATION
he user re(istrati!n=acc!unt re(istrati!n 0!r/ &ill be presente" t! the user1 Once user 0ills in the 0!r/ an" clics !n the O\butt!n) the serversi"e JS* &ill call the &ebservice t! re(ister the user1
+his &ebservices &ill exp!se the insert user !perati!n &hich &ill be use" b2 the JS* client t! re(ister the user1 $e &ill use th
2+
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 28/39
etBeans 91K %,3 t! "evel!p an" test the applicati!n1
+he M2SL "atabase is use" t! save the user re(istrati!n "ata1 G!u can /!"i02 the c!"e t! use an2 "atabase !0 2!ur ch!ice+he existin( &ebservices can als! be /!"i0ie" t! use the Hibernate !r an2 !ther ORM techn!l!(ies1 G!u can als! use the3ntit2 beans t! persist the "ata int! "atabase1
S!0t&are require" t! "evel!p an" run this exa/ple:
• J,\ K19
• etBeans 91K
• M2SL ,atabase 8 !r ab!ve
Le!s e! s!a"!ed ?i! !e de>e)o(en! o= !e a)ia!on
$3S8) Da!a0ase Con=i-"a!ion In Ne!BeansLets c!n0i(ure M2SL "atabase in teh etBeans %,3 an" then create the require" table int! "atabase1
S!e 1:
• Clic !n the service tab in etBeans as sh!&n bel!& in 6i( K1
Gi.
S!e #:
• Ri(ht Clic !n the ,atabases
• Select e& C!nnecti!n as sh!&n bel!& in 6i( 1
2,
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 29/39
Gi. #.
S!e *:
• %t !pens a "ial!( b!x 0!r the /2sql c!n0i(urati!n1
• +2pe the "river na/e) url ) user na/e an" pass&!r" as sh!&n bel!& in 6i(1 N1
Gi. *S!e ;:
• Clic !n the O butt!n 1
• !& expan" the e&l2 create" "atabase c!nnecti!n1
• %t sh!&s the all the tables !0 the "atabase test as sh!&n bel!& in 6i( E1
2-
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 30/39
Gi. ;
S!e 5:
• Create a table na/e" l!(in1
• Ri(ht Clic !n the +ables an" select Create table
as sh!&n bel!& in 6i( 8
Gi. 5S!e :
• %t !pens a "ial!( b!x 0!r (ivin( the 0iel"s na/e !0 the table
• !& (ive the 0iel" na/e an" "ata t2pe as sh!&n bel!& in 6i( 91
".
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 31/39
Gi.
S!e :
• Clic !n the O
• %t creates the table l!(in in the test "atabase1
C"ea!in !e We0Se">ie "o"a( =o" Ao-n! "ea!ion
S!e F:
• Open the netbeans 91K
• Creat a ne& &eb pr!ject as sh!&n bel!& in 6i( 41
Gi.
S!e 9:
• +2pe the pr!ject a/e as M2Acc!unt
• Clic !n the next butt!n as sh!&n bel!& in 6i( Y1
"1
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 32/39
Gi. F
S!e 1:
• Select the server as >lass0ish
• Clic !n the ext an" then 0inish butt!n as sh!&n bel!& in 6i( Z1
Gi. 9S!e 11:
• %t creates a $eb *r!ject na/e" M2Acc!unt1
C"ea!in !e We0Se">ie
S!e 1#:
• Ri(ht Clic !n the pr!ject M2Acc!unt
• Select e&--$ebService as sh!&n bel!& in 6i( KF1
"2
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 33/39
Gi. 1
S!e 1*:
• +2pe the na/e !0 the $ebService as /2acc!unt &ith the paca(e as /2pac1
• Clic !n the 6inish butt!n as sh!&n bel!& in 6i( KK1
Gi. 11
S!e 1;:
• %t creates a $ebService applicati!n in "esi(n vie&
• Clic !n the A"" !perati!n as sh!&n bel!& in 6i( K1
""
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 34/39
Gi. 1#S!e 15:
• %n the "ial!( b!x t2pe all para/eter na/es1
• Als! select the appr!priate "ata t2pe1
• Clic !n O as sh!&n bel!& in 6i( KN1
Gi. 1*S!e 1:
• %t creates a $ebService applicati!n
• Clic !n the s!urce tab as sh!&n bel!& in the 6i( KE1
"
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 35/39
Gi. 1;S!e 1:
• !& create the "atabase s!urce
• Ri(ht Clic in the s!urce c!"e !0 /2acc!unt1java
• Select the 3nterprise Res!urces--se ,atabase as sh!&n bel!& in 6i( K81
"
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 36/39
Gi. 15S!e 1F:
• %n the ch!!se "atabase select the A"" butt!n as sh!&n bel!& in 6i( K91
Gi. 1
S!e 19:
• %t !pens a A"" ,ata S!urce Re0erence1
• +2pe the Re0erence a/e as "ataK
• 6!r *r!ject ,ata S!urces Clic !n the A"" butt!n as sh!&n bel!& in 6i( K41
Gi. 1
S!e #:
• %n the Crea ,ata S!urce t2pe th2e jn"i na/e as jn"iK
• %n the "atabase c!nnecti!n select the ne&l2 create" "atabase c!nncti!n 0!r the /2sql1
as sh!&n bel!& in 6i( KY1
"*
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 37/39
Gi. 1F
S!e #1:
• Clic !n the O butt!n
• %t creates the "atabase c!nnecti!n (ives the "ial!( b!x as sh!&n bel!&1
• Clic !n the O butt!n as sh!&n bel!& in 6i( KZ1
Gi. 19
5.9 SOA%
SOA* is an !pen-stan"ar") XML-base" /essa(in( pr!t!c!l 0!r exchan(in( in0!r/ati!n a/!n( c!/puters1 +his is
brie0 tut!rial that intr!"uces the rea"ers t! the 0un"a/entals !0 SOA* be0!re /!vin( !n t! explain its vari!us ele/en
enc!"in() an" h!& SOA* is transp!rte"1
SOA* is an acr!n2/ 0!r Si/ple Object Access *r!t!c!l1 %t is an XML-base" /essa(in( pr!t!c!l 0!r exchan(in( in0!r/atia/!n( c!/puters1 SOA* is an applicati!n !0 the XML speci0icati!n1
%oin!s !o No!e
Bel!& /enti!ne" are s!/e i/p!rtant p!int &hich the user sh!ul" tae n!te !01 +hese p!ints brie0l2 "escribes the natureSOA* I
• SOA* is a c!//unicati!n pr!t!c!l "esi(ne" t! c!//unicate via %nternet1
"+
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 38/39
• SOA* can exten" H++* 0!r XML /essa(in(1
• SOA* pr!vi"es "ata transp!rt 0!r $eb services1
• SOA* can exchan(e c!/plete "!cu/ents !r call a re/!te pr!ce"ure1
• SOA* can be use" 0!r br!a"castin( a /essa(e1
• SOA* is plat0!r/- an" lan(ua(e-in"epen"ent1
• SOA* is the XML &a2 !0 "e0inin( &hat in0!r/ati!n is sent an" h!&1
• SOA* enables client applicati!ns t! easil2 c!nnect t! re/!te services an" inv!e re/!te /eth!"s1
Alth!u(h SOA* can be use" in a variet2 !0 /essa(in( s2ste/s an" can be "elivere" via a variet2 !0 transp!rt pr!t!c!ls) tinitial 0!cus !0 SOA* is re/!te pr!ce"ure calls transp!rte" via H++*1
Other 0ra/e&!rs inclu"in( CORBA) ,COM) an" Java RM% pr!vi"e si/ilar 0uncti!nalit2 t! SOA*) but SOA* /essa(es a &ritten entirel2 in XML an" are there0!re uniquel2 plat0!r/- an" lan(ua(e-in"epen"ent1
A SOA* /essa(e is an !r"inar2 XML "!cu/ent c!ntainin( the 0!ll!&in( ele/ents I
• En>e)oe ,e0ines the start an" the en" !0 the /essa(e1 %t is a /an"at!r2 ele/ent1
• Heade" C!ntains an2 !pti!nal attributes !0 the /essa(e use" in pr!cessin( the /essa(e) either at an inter/e"ia
p!int !r at the ulti/ate en"-p!int1 %t is an !pti!nal ele/ent1
• Bod3 C!ntains the XML "ata c!/prisin( the /essa(e bein( sent1 %t is a /an"at!r2 ele/ent1
• Ga-)! An !pti!nal 6ault ele/ent that pr!vi"es in0!r/ati!n ab!ut err!rs that !ccur &hile pr!cessin( the /essa(e1
All these ele/ents are "eclare" in the "e0ault na/espace 0!r the SOA* envel!pe I
http:==&&&1&N1!r(=FFK=K=s!ap-envel!pe an" the "e0ault na/espace 0!r SOA* enc!"in( an" "ata t2pes is
http:==&&&1&N1!r(=FFK=K=s!ap-enc!"in(
NOTE I All these speci0icati!ns are subject t! chan(e1 S! eep up"atin( 2!ursel0 &ith the latest speci0icati!ns available !n th
$N &ebsite1
SOA* Messa(e Structure
+he 0!ll!&in( bl!c "epicts the (eneral structure !0 a SOA* /essa(e I
@x/l versi!n7K1F@SOA*-3V:3nvel!pe x/lns:SOA*-3V7http: ==&&&1&N1!r(=FFK=K=s!ap-envel!pe SOA3V:enc!"in(St2le7http:==&&&1&N1!r(=FFK=K=s!ap-enc!"in(
SOA*-3V:Hea"er 111 111 =SOA*-3V:Hea"er
",
7/25/2019 Unit v Introduction to Ajax and Web Services
http://slidepdf.com/reader/full/unit-v-introduction-to-ajax-and-web-services 39/39
SOA*-3V:B!"2 111 111 SOA*-3V:6ault 111 111 =SOA*-3V:6ault 111 =SOA*-3V:B!"2
=SOA*?3V:3nvel!peSOA* &ith H++* *OS+
+he 0!ll!&in( exa/ple illustrates the use !0 a SOA* /essa(e &ithin an H++* *OS+ !perati!n) &hich sen"s the /essa(e
the server1 %t sh!&s the na/espaces 0!r the envel!pe sche/a "e0initi!n an" 0!r the sche/a "e0initi!n !0 the enc!"in( rule
+he OrderEntry re0erence in the H++* hea"er is the na/e !0 the pr!(ra/ t! be inv!e" at the tut!rialsp!int1c!/ &ebsite1
*OS+ =Or"er3ntr2 H++*=K1KH!st: &&&1tut!rialsp!int1c!/C!ntent-+2pe: applicati!n=s!ap# charset7ut0-YC!ntent-Len(th: nnnn
@x/l versi!n7K1F@
SOA*-3V:3nvel!pe x/lns:SOA*-3V7http:==&&&1&N1!r(=FFK=K=s!ap-envel!pe SOA*-3V:enc!"in(St2lehttp:==&&&1&N1!r(=FFK=K=s!ap-enc!"in( 111 Messa(e in0!r/ati!n (!es here 111=SOA*-3V:3nvel!pe