Sie sind auf Seite 1von 28

DEPARTMENT OF INFORMATION

TECHNOLOGY
IT2406
SERVICE ORIENTED ARCHITECTURE LAB
LAB MANUAL
CREATION OF ADDITION WEB SERVICE:
Aim:
To create a web service for adding few numbers using NetBeans.
Alg!i"#m:
1. Using the Netbeans API create a project of the type web appication.
!. "reate a web service in the project.
#. "ic$ on the %esign tab and design the prototype of the web service.
&. "ic$ on source tab and modify the appication ogic of the web service.
'. (ave the project.
). *ight cic$ on the project and cic$ on depoy and undepoy.
+. Then test the web service.
STEPS TO CREATE ADDITION WEB SERVICE:
I.(T,P( -.* "*,ATIN/ (,*0,* (I%, P*.1,"T2
1..P,N -ie34New34NewProject345eb345eb App..cic$ ne6t
!./ive Project name34addserver7then cic$ finish
#.The addserver project wi be created in right side.*ight cic$ it and choose the
foowing.
/ive the web service name as addweb.
&.After this in eft side 8the design window choose the add operation
'. /ive the foowing in the opened window for creating operation
Name34add
).Then in the source add the foowing code and save it.
pac$age org9
import java6.jws.5eb:ethod9
import java6.jws.5ebParam9
import java6.jws.5eb(ervice9
;5eb(ervice<=
pubic cass addweb >
?@@
@ 5eb service operation
@?
;5eb:ethod<operationName A BaddB=
pubic int add<;5ebParam<name A BaB=
int a8 ;5ebParam<name A BbB=
int b= >
int $AaCb9
return $9
D
D
+.Then right cic$ on add addserver and perform undepoy and depoy7after that right
cic$ on addweb and do test web service to see the (.AP reEuest and response message.
/ive some integers and cic$ add.
CREATION OF WEB SERVICE CLIENT
Aim:
To create a web service for adding few numbers using NetBeans and write cient side
code to invo$e the web service.
Alg!i"#m:
1. Using the Netbeans API create a project of the type web appication.
!. "reate a web service in the project.
#. "ic$ on the %esign tab and design the prototype of the web service.
&. "ic$ on source tab and modify the appication ogic of the web service.
'. (ave the project.
). *ight cic$ on the project and cic$ on depoy and undepoy.
+. Then test the web service.
F. "reate another web appication project and create a jsp fie.
G. *ight cic$ on project and cic$ on create web service cient.
1H. Browse and choose the web service created i.e wsd ur
11. %rag and drop the web service reference to the source code window.
1!. Then pass the appropriate parameters to the web service cient and invo$e the web
service.
STEPS TO CREATE CLIENT SIDE PRO$ECT:
1.create the new project as above and give the name as addcient.
!. addcient project wi be created. right cic$ it and choose the foowing.
#.Then browse and choose the addweb wsd fie
&.Then choose the foowing and add the source code in inde6.jsp and save it.
Inde6.jsp source code
IJ;page contentTypeABte6t?htmB page,ncodingABUT-3FBJ4
IK%."TLP, MT:N PUBNI" B3??5#"??%T% MT:N &.H1 Transitiona??,NB
Bhttp2??www.w#.org?T*?htm&?oose.dtdB4
Ihtm4
Ihead4
Imeta http3eEuivAB"ontent3TypeB contentABte6t?htm9 charsetAUT-3FB4
Itite41(P PageI?tite4
I?head4
Ibody4
Ih14Meo 5ordKI?h14
Iform nameABB actionABactionn.jspB methodABpostB4
,nter 1st No2Iinput nameABfstB typeABte6tB ?4Ibr?4
,nter !nd No2Iinput nameABsndB typeABte6tB ?4Ibr?4
Iinput nameABo$B typeABsubmitB vaueABAddB ?4
I?form4
I?body4
I?htm4
'.Then create an action.jsp as foows.
*ight cic$ web page in addcient and choose new34jsp
Name2action
"ic$ finish
).cic$ on the actionn.jsp page..then right cic$ in it and choose web service cient
reference 34ca web service
+.The invo$e the add service.
F. add the foowing code in the action.jsp
IJ;page contentTypeABte6t?htmB page,ncodingABUT-3FBJ4
IK%."TLP, MT:N PUBNI" B3??5#"??%T% MT:N &.H1 Transitiona??,NB
Bhttp2??www.w#.org?T*?htm&?oose.dtdB4
Ihtm4
Ihead4
Imeta http3eEuivAB"ontent3TypeB contentABte6t?htm9 charsetAUT-3FB4
Itite41(P PageI?tite4
I?head4
Ibody4
Ih14Meo 5ordKI?h14
IJ
(tring a1AreEuest.getParameter<BfstB=9
(tring b1AreEuest.getParameter<BsndB=9
int aaAInteger.parseInt<a1=9
int bbAInteger.parseInt<b1=9
J4
IJ33 start web service invocation 33J4Ihr?4
IJ
try >
org.Addweb(ervice service A new org.Addweb(ervice<=9
org.Addweb port A service.getAddwebPort<=9
?? T.%. initiaiOe 5( operation arguments here
int a A aa9
int b A bb9
?? T.%. process resut here
int resut A port.add<a8 b=9
out.printn<B*esut A BCresut=9
D catch <,6ception e6= >
?? T.%. hande custom e6ceptions here
D
J4
IJ33 end web service invocation 33J4Ihr?4
I?body4
I?htm4
F.finay undepoy and depoy the addcient and run it.
CREATION OF A WEB SERVICE WITH DATABASE CONNECTIVITY
Aim:
To create a web service for adding few numbers using NetBeans and write cient side
code to invo$e the web service.
Alg!i"#m:
1. Using the Netbeans API create a project of the type web appication.
!. ,stabish connectivity with the database aong with the necessary authentication
parameters.
#. "reate a web service in the project.
&. "ic$ on the %esign tab and design the prototype of the web service.
'. "ic$ on source tab and modify the appication ogic of the web service.
). (ave the project.
+. *ight cic$ on the project and cic$ on depoy and undepoy.
F. Then test the web service.
G. "reate another web appication project and create a jsp fie.
1H. *ight cic$ on project and cic$ on create web service cient.
11. Browse and choose the web service created i.e wsd ur
1!. %rag and drop the web service reference to the source code window.
1#. Then pass the appropriate parameters to the web service cient and invo$e the web
service.
STEPS FOR CREATING TRAVEL WEB SERVICE
R%&'i!%m%("):
*+M,)&l
*+(%"-%.() /i"# gl.)) 0i)#12 )%!1%!
I2B%0!% 3!%."i(g 4!5%3" i( (%" -%.() 6 "#% 0ll/i(g:
1.insta :ysE setup fie and the gui toos .
!.Then open the mysE browser in the start34programs34mysE34mysE browser
Then restore the bac$ up<newproject!H117= as foows
1.choose toos34mysE administrator
!.Then choose restore in that window..Then cic$ open bac$up in the bottom7open the
bac$up fie<newproject!H17.= which is in the attachment7.then cic$ start restore..
#.now the schema is created in the mysE7..
Now strat the coding in netbeans7
SERVER SIDE:
1.create the server project as before and with the foowing changes.
Project name2 PPNBusTraves
!.web service name2PPNBusTraves
Pac$age name2$pnpac$
#.in design window
.peration name2getBus
Parameters2
(ource and destination with the type as (tring.
&.Add the foowing code in source
pac$age $pnpac$9
import java.sE."onnection9
import java.sE.%river:anager9
import java.sE.*esut(et9
import java.sE.(tatement9
import java.uti.ArrayNist9
import java.uti.Mashtabe9
import java6.jws.5eb:ethod9
import java6.jws.5ebParam9
import java6.jws.5eb(ervice9
?@@
@
@ ;author user
@?
;5eb(ervice<=
pubic cass PPNBusTraves5( >
?@@
@ 5eb service operation
@?
;5eb:ethod<operationName A BgetBusB=
pubic (tring getBus<;5ebParam<name A BsourceB=
(tring source8 ;5ebParam<name A BdestinationB=
(tring destination= >
??T.%. write your impementation code here2
ArrayNistI(tring4 serviceQname A new ArrayNistI(tring4<=9
ArrayNistI(tring4 departureQtime A new ArrayNistI(tring4<=9
ArrayNistI(tring4 arrivaQtime A new ArrayNistI(tring4<=9
ArrayNistI(tring4 busQfare A new ArrayNistI(tring4<=9
ArrayNistI(tring4 busQtype A new ArrayNistI(tring4<=9
ArrayNistI(tring4 busQcategoryAnew ArrayNistI(tring4<=9
try >
"ass.forName<Bcom.mysE.jdbc.%riverB=9
"onnection
conA%river:anager.get"onnection<Bjdbc2mysE2??ocahost2##H)?EosB8BrootB8BrootB=9
(tatement st1Acon1.create(tatement<=9
st1.e6ecuteUpdate<Binsert into Eostabe<webname8
e6etime8price8compute8avaitime= vaues<RBCwnCBR8RBCetCBR8RBCprCBR8RBCctCBR8RBCatCBR=B=9
(tatement stAcon.create(tatement<=9
*esut(et rs A st.e6ecuteSuery<sE=9
int iAH9
whie <rs.ne6t<== >
departureQtime.add<rs.get(tring<#==9
arrivaQtime.add<rs.get(tring<&==9
busQfare.add<rs.get(tring<'==9
busQtype.add<rs.get(tring<G==9
busQcategory.add<rs.get(tring<11==9
serviceQname.add<rs.get(tring<1!==9
?? serviceQname.add<rs.get(tring<B(ervicenameB==9
D
D catch < ,6ception e= >
e.print(tac$Trace<=9
D
(tring concatBus A serviceQname.to(tring<=CBTBCdepartureQtime.to(tring<=
CBTBCarrivaQtime.to(tring<= CBTBCbusQfare.to(tring<= CBTBC
busQtype.to(tring<= CBTBCbusQcategory.to(tring<= CB8B9
return concatBus9
D
D
'.Then depoy the service and test the web service as before.
/ive input as "hennai and "oimbatore .then cic$ getbus.
"NI,NT (I%,2
1.create new project
Name2cient1
!.As before in addition program create web service reference.
#.The source code for inde6.jsp and action8jsp are as foow.
Inde6.jsp2
IJ;page contentTypeABte6t?htmB page,ncodingABUT-3FBJ4
IK%."TLP, MT:N PUBNI" B3??5#"??%T% MT:N &.H1 Transitiona??,NB
Bhttp2??www.w#.org?T*?htm&?oose.dtdB4
Ihtm4
Ihead4
Imeta http3eEuivAB"ontent3TypeB contentABte6t?htm9 charsetAUT-3FB4
Itite41(P PageI?tite4
I?head4
Ibody4
Ih!4Meo 5ordKI?h!4
Iform nameABB actionABactionn.jspB methodABpostB4
,nter (ource2Iinput nameABsourceB typeABte6tB ?4Ibr?4
,nter %estination2Iinput nameABdestinationB typeABte6tB ?4Ibr?4
Iinput nameABo$B typeABsubmitB vaueABB ?4
I?form4
I?body4
I?htm4
A3"i(25)4
IJ;page contentTypeABte6t?htmB page,ncodingABUT-3FBJ4
IK%."TLP, MT:N PUBNI" B3??5#"??%T% MT:N &.H1 Transitiona??,NB
Bhttp2??www.w#.org?T*?htm&?oose.dtdB4
Ihtm4
Ihead4
Imeta http3eEuivAB"ontent3TypeB contentABte6t?htm9 charsetAUT-3FB4
Itite41(P PageI?tite4
I?head4
Ibody4
Ih!4Meo 5ordKI?h!4
IJ
(tring a1AreEuest.getParameter<BsourceB=9
(tring b1AreEuest.getParameter<BdestinationB=9
J4
IJ33 start web service invocation 33J4Ihr?4
IJ33 end web service invocation 33J4Ihr?4
IJ33 start web service invocation 33J4Ihr?4
IJ
(tringUV res8commaspitAnu8brspitAnu8rbrspitAnu9
(tringUVUV fightQtransAnew (tringU1HHVU1HHV9
int rowAH8coAH9
int trowAH8tcoAH9
int midrowAH8midcoAH9
?? 1agson
(tringUV jagres8jagcommaspitAnu8jagbrspitAnu8jagrbrspitAnu9
(tringUVUV jagfightQtransAnew (tringU1HHVU1HHV9
int jagrowAH8jagcoAH9
??Air India
(tringUV airres8aircommaspitAnu9
(tringUVUV airfightQtransAnew (tringU1HHVU1HHV9
int airrowAH8aircoAH9
try >
$pnpac$.PPNBusTraves5((ervice service A new
$pnpac$.PPNBusTraves5((ervice<=9
$pnpac$.PPNBusTraves5( port A service.getPPNBusTraves5(Port<=9
?? T.%. initiaiOe 5( operation arguments here
java.ang.(tring source A Ba1B9
java.ang.(tring destination A Bb1B9
?? T.%. process resut here
java.ang.(tring resut A port.getBus<source8 destination=9
out.printn<B*esut A BCresut=9
resAresut.spit<BTB=9
(ystem.out.printn<B1et (pit2BCres=9
for<int iAH9iIres.ength9iCC=
>
int jAH9
rowAres.ength9
(tring brAresUiV.repace<BUB8 BB=9
(tring rbrAbr.repace<BVB8 BB=9
commaspitArbr.spit<B8B=9
for< jAH9jIcommaspit.ength9jCC=
>
coAcommaspit.ength9
(ystem.out.printn<BfightQtransUiVUjVBCiCB?BCj=9
if<commaspitUjVKAnu=
fightQtransUjVUiVAcommaspitUjV9
D
?? if< fightQtransUiVUjVAAnu=
?? coAH9
D
?? out.printn<B*es A BCresUHV=9
(ystem.out.printn<BT*B=9
(ystem.out.printn<Bjet*ow2BCrow=9
(ystem.out.printn<Bjet"oumn2BCco=9
for<int rAH9rIrow9rCC=
>
for<int cAH9cIco9cCC=
>
if<fightQtransUrVUcVKAnu=
(ystem.out.print<Btr2BCfightQtransUrVUcV=9
D
(ystem.out.printn<=9
D

D catch <,6ception e6= >
?? T.%. hande custom e6ceptions here
D
J4
IJ33 end web service invocation 33J4Ihr?4
I?body4
I?htm4
&.Then finay undepoy and depoy the cient and run it77777..
CREATION OF A BPEL MODULE AND A COMPOSITE APPLICATION
Aim2
"reate a (.A project with BP,N :odue to compose a web service.
(T,P( T. "*,AT, A BP,N :.%UN,
C!%."i(g . (%/ BPEL M6'l% P!5%3"
The foowing sections use the (ynchronous sampe project8 and provide step3by3step
directions for creating a simpe BP,N modue project8 using the (ynchronous sampe
project.
T C!%."% . BPEL M6'l% P!5%3"
1. In the NetBeans I%,8 choose -ie 4 New Project.
The New Projects wiOard appears.
!. Under "ategories8 seect (ervice .riented Architecture.
#. Under Projects8 seect BP,N :odueand cic$ Ne6t.
&. In the Name and Nocation page8 enter the project name <for this e6ampe
Meo5ord= and specify the project ocation or accept the defauts.
'. "ic$ -inish.
The Projects window now contains a project node for the BP,N :odue project.
C!%."i(g . BPEL P!3%)) U)i(g "#% BPEL D%)ig(%!
Now that you have created your W:N (chema and 5(%N %ocument8 you can create
your BP,N process.
T C!%."% "#% BPEL P!3%))
1. In the Projects window8 e6pand your BP,N modue project node8 right3cic$ the
Process -ies node8 and choose New 34 BP,N Process.
The New BP,N Process diaog bo6 appears.
!. ,nter a name for the process fie name <Meo5ordProcess for this e6ampe=8 and
cic$ -inish.
The new BP,N fie opens in the %esign view of the BP,N %esigner.
If the Paette and Properties windows are not dispayed in your current view8 cic$
5indows 34 *eset 5indows on the NetBeans menu.
#. Add a partner in$ to the BP,N Process.
a. In the Projects window8 e6pand your projectRs Process -ies node and
seect the .wsd fie <(ynchronous.wsd for this e6ampe=.
b. %rag the 5(%N fie from the Projects window to the eft side of the
%esign view canvas.
The I%, provides visua prompts to show you where you can drop the seection.
The BP,N ,ditor adds a partner in$ to the canvas.
&. Add a *eceive activity to the BP,N Process.
a. -rom the 5eb (ervice section of the Paette window8 seect the *eceive
activity.
b. %rag the *eceive activity to the Meo5ordProcess process bo6 in the
%esign view canvas8 between the Process (tart and the Process ,nd
activities.
The *eceive1 activity is added to the process bo6.
c. "ic$ the *eceive1 activityRs ,dit icon.
The *eceive1 Property ,ditor appears.
d. .n the :ain tab8 change the vaue in the Name fied to )".!".
e. -rom the Partner Nin$ drop3down ist8 choose P.!"(%!Li(78.
The I%, popuates the .peration fied with New5(%N.peration.
f. "ic$ the "reate button ne6t to the Input 0ariabe -ied.
The New Input 0ariabe diaog bo6 appears.
g. "ic$ .P to accept the defaut vaues.
h. "ic$ .P to cose the *eceive1 Property ,ditor.
The %esign view dispays the new connection between PartnerNin$1 and the (tart
activity in the process bo6.
'. Add a *epy activity to the BP,N Process.
a. (eect the *epy activity in the 5eb (ervice section of the Paette. %rag
and drop the *epy to the prompt between the (tart activity and the
Process ,nd activity in the process bo6 on the design view canvas.
A *epy1 activity is added to the design view canvas.
b. "ic$ the *epy1 activityRs ,dit icon.
The *epy1 Property ,ditor appears.
c. .n the :ain tab8 change the vaue in the Name fied to ,nd.
d. -rom the Partner Nin$ drop3down ist8 choose PartnerNin$1.
The I%, popuates the .peration fied with New5(%N.peration.
e. To create anew output variabe8 ma$e sure that Norma *esponse is
seected8 and cic$ the "reate button ne6t to the Input 0ariabe -ied.
The New Input 0ariabe diaog bo6 appears. "ic$ .P to accept the defaut vaues.
f. "ic$ .P to cose the *epy1 Property ,ditor.
The %esign view dispays the new connection between the ,nd activity in the process
bo6 and PartnerNin$1.
). Add a Assign activity to the BP,N Process.
a. (eect the Assign activity in the Basic Activities section of the Paette.
%rag and drop the Assign to the prompt between the (tart activity and the
,nd activity in the process bo6 on the design view canvas.
The Assign1 activity is added to the design view canvas.
b. (eect the Assign1 activity and cic$ the :apper button on the editors
toobar.
The BP,N :apper appears.
c. :ap the paramA node under 0ariabes 34 New5(%N.perationIn 34
inputType in the .utput pane of the BP,N :apper8 to the paramA node
under 0ariabes 34 New5(%N.peration.ut 34 resutType in the Input
pane of the :apper. To do this8 seect theparamA node under 0ariabes 34
New5(%N.perationIn 34 inputType in the .utput pane8 and drag your
cursor to the paramA node under 0ariabes 34 New5(%N.peration.ut 34
resutType in the Input pane.
This assignment copies the input statement into the output.
+. To save your changes cic$ the (ave A icon in the I%, menu bar.
C!%."i(g . Cm4)i"% A44li3."i( P!5%3"
A BP,N :odue project is not directy depoyabe. Lou must first add a BP,N :odue
project8 as a 1BI modue8 to a "omposite Appication project. Lou can then depoy the
"omposite Appication project. %epoying the project ma$es the service assemby
avaiabe to the appication server and enabes its service units to run.
T C!%."% . N%/ Cm4)i"% A44li3."i( P!5%3"
1. "hoose -ie 4 New Project <"tr3(hift3N=.
!. In the "ategories ist choose (ervice .riented Architecture8 in the Projects ist
choose "omposite Appication8 and cic$ Ne6t.
#. In the Name and Nocation page8 change the project name to
Meo5ordAppication8 and specify the ocation of project fies.
&. To set the new "omposite Appication the main project as main8 eave the (et as
:ain Project chec$bo6 seected8 and cic$ -inish.
'. To add the BP,N :odue as a 1BI modue to the "omposite Appication project8
right3cic$ the new "omposite Appication and choose Add 1BI :odue.
The (eect Project diaog bo6 opens.
). (eect the Meo5ord project you created earier and cic$ Add Project 1A* -ies.
The (eect Project diaog bo6 coses and the Meo5ord.jar fie is added to the 1BI
:odues node of the Meo5ordAppication "omposite Appication
B'il6i(g .(6 D%4l,i(g "#% Cm4)i"% A44li3."i( P!5%3"
Buiding a project compies the BP,N source fie and pac$ages the BP,N fie and web
service artifacts8 incuding 5(%N and W(% fies8 into a 1A* archive. %epoying the
project compies the fies in the "omposite Appication project8 pac$ages the compied
BP,N and reated web service artifacts <incuding 5(%N and W(% fies= into an archive8
and depoys them to the Appication (erver.
T B'il6 .(6 D%4l, "#% Cm4)i"% A44li3."i( P!5%3"
1. *ight3cic$ the "omposite Appication projectRs node8 and choose Buid.
5hen the buid is compete the .utput window reports Buid (uccessfu. If the .utput
window is not visibe8 choose 5indow 34 .utput 34 .utput.
!. *ight3cic$ the "omposite Appication projectRs node8 and choose %epoy.
#. %epoyment has succeeded when you see a Buid successfu message in the
/ass-ish tab of the .utput window.
&. .pen the (ervices window and e6pand (ervers 34 /ass-ish 0! 34 1BI 34 (ervice
Assembies to see your new depoyed (ervice Assemby.
If you do not see the depoyed project8 right3cic$ the (ervice Assembies node and
choose *efresh.
T%)"i(g "#% Cm4)i"% A44li3."i(
Lou can test your "omposite Appication project by adding test cases8 binding to the
operation8 suppying input8 and then using the tester.
T%)" "#% H%llW!l6A44li3."i( Cm4)i"% A44li3."i( P!5%3"
1. In the Projects window8 e6pand the Meo5ordAppication project node8 right3
cic$ the Test node8 and choose New Test "ase.
The New Test "ase wiOard opens.
!. Accept the defaut test case name8 Test"ase18 and cic$ Ne6t.
#. -rom the (eect the 5(%N %ocument page8 e6pand the Meo5ord 3 Proecss
-ies node8 seect (ynchronous.wsd8 and cic$ Ne6t.
&. -rom the (eect the .peration to Test page8 seect the .peration1 and cic$ -inish.
A new Test"ase1 node is added under the projectRs Test node in the Projects window8
containing two subnodes8 Input and .utput.
The (ource ,ditor appears containing the Input fie8 Input.6m
N"% 9
If the (ource ,ditor does not contain a tab for Input.6m8 doube3cic$ the Input node in
the Projects window to open the fie.
'. -rom the Input.6m tab of the (ource ,ditor8 do the foowing2
a. Nocate the ine2
Isyn2paramA4XstringXIsyn2paramA4
b. *epace XstringX with Meo 5ord8 so that the ine appears as foows2
Isyn2paramA4Meo 5ordIsyn2paramA4
c. -rom the NetBeans I%, menu bar8 cic$ (ave A.
). In the Projects window8 doube3cic$ the .utput node under Test 34 Test"ase1.
.utput.6m is opened in the (ource ,ditor. Initiay8 .utput.6m is empty unti the first
test run popuates the fie.
+. In the Projects window8 right3cic$ the Test"ase1 node and choose *un from the
pop3up menu.
5hen the .verwrite ,mpty .utput diaog bo6 appears8 cic$ Les to accept new output.
The first test run popuates the .utput.6m fie dispayed in the (ource ,ditor.
The test compares the output to the contents of the output fie. Because the first run of the
test has nothing to compare itsef to8 the first test fais. (ubseEuent test runs wi compare
their output with the contents of .utput.6m and shoud succeed.
F. *un the test again.
The test case is compared to the current output fie and succeeds.

Das könnte Ihnen auch gefallen