Applicazioni Java – WS con Axis - Dipartimento di Ingegneria dell

Transcript

Applicazioni Java – WS con Axis - Dipartimento di Ingegneria dell
Applicazioni Java – W S con Ax is
Laurea Specialistica in Ingegneria Informatica per la Gestione d'Azienda
Corso di Sistemi Informativi per le Aziende
sistema di tr ac c iab il ità
ag r o al imen tar e
Ing. Mario G.C.A. Cimino
Dicembre 2004
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
1/14
Installazione di Axis su Jakarta Tomcat
Axis (h t t p :/ / w s.a p a c h e .o r g/ a xis/ ) è u n SO AP e n gin e , u n f r a m e w o r k p e r c o st r u ir e
SO AP p r o c e sso r (c o m e c l ie n t , se r v e r , ga t e w a y ...)
È
p
c
c
sv il u p p
a c k a ge
o n t ie n e
o p ia n d o
a to c o m e
(h t t p :/ / a p
u n f il e f o
la c a rte lla
j a v a se r v l e t , p e r
a c h e .f is.u n ir o m a
r m a t o w e b a p p ic
webapps\ax i s n e
c u i si in st a l l a su se r v l e t e n gin e c o m e T o m c
2 .it / w s/ a xis/ 1 _ 2 R C1 / a xis-1 _ 2 R C1 -b in .z ip )
a t io n (a xis.w a r ) m a si in st a l l a a u t o m a t ic a m
l l a c o r r isp o n d e n t e c a r t e l l a webapps d i T o m c
a t.Il
n o n
e n te
a t.
N o n e ` n e c e ssa r io r ia v v ia r e T o m c a t : in p o c h i se c o n d i v ie n e r il e v a t a a u t o m a t ic a m e n t e
l ’ a p p l ic a z io n e e st a m p a t i i r e l a t iv i m e ssa ggi su l l a sh e l l , t r a c u i l a m a n c a n z a d i a l c u n i
p a c k a ge d a a ggiu n ge r e m a n u a l m e n t e c o m e d i se gu it o .
Co p ia r e i 4 f il e s .j ar d e l l ’ X M L p a r se r d e l l a Xer c es n e l l a c a r t e l l a ax i s/ W E B -I N F / l i b
Ac c e d e r e m e d ia n t e il b r o w se r a l l a u r l h t t p :/ / l o c a l h o st :8 0 8 0 / a xis/ q u in d i e se gu ir e il
t e st d i v a l id a z io n e h appy ax i s (h t t p :/ / l o c a l h o st :8 0 8 0 / a xis/ h a p p y a xis.j sp ) c l ic c a n d o su l
l in k V al i d at e.
N o r m a l m e n t e , v ie n e r il e v a t a l a m a n c a n z a d e gl i u l t e r io r i p a c k a ge s d e sc r it t i d i se gu it o ,
d a c o p ia r e se m p r e n e l l a c a r t e l l a ax i s/ W E B -I N F / l i b.
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
2/14
PACKAGE
CO N T EN U T O N EL F I L E
S CAR I CAB I L E D A
activation.jar
j a f -1 _ 0 _ 2 -u p d . z i p
h ttp ://ja v a .s u n .c o m /p r o d u c ts /ja v a b e a n s /g la s g o w /ja f .h tm l
x m l s e c.jar
x m l -s e c u r i t y -b i n -1 _ 1 _ 0 . z i p
h t t p : / / x m l . a p a c h e . o r g / s e c u r i t y / d i s t / j a v a -l i b r a r y / x m l -s e c u r i t y -b i n -1 _ 1 _ 0 . z i p
m ail .jar
Su c c
H T T
e le m
a lla
a p p a
j a v a m a i l -1 _ 3 _ 2 . z i p
e ssiv a m e n t e si t e st a u
P P O S T p e r in v ia r e u
e n t a r e m e c c a n ism o H
u r l h t t p :/ / l o c a l h o st :8
r ir e q u a l c o sa d e l ge n e
h ttp ://ja v a .s u n .c o m /p r o d u c ts /ja v a m a il/d o w n lo a d s /in d e x .h tm l
n SO AP e n d p o in t . Se b b e n e l o st a n d a r d SO AP
n a r ic h ie st a X M L a d u n e n d p o in t , Axis su p p o
T T P G E T , u t il e a sc o p o d i t e st in g. Ac c e d e r e
0 8 0 / a xis/ se r v ic e s/ V e r sio n ? m e t h o d = ge t V e r sio n
re :
u si r ic h
rta a n c h
d a b ro
. D o v r
ie st e
e u n
w se r
e b b e
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getVersionResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getVersionReturn
xsi:type="xsd:string">
Apache Axis version: 1.1 Built on Apr 04, 2003 (01:30:37 PST)
</getVersionReturn>
</getVersionResponse>
</soapenv:Body>
</soapenv:Envelope>
T e st ia m o o r a u n J a v a W e b Se r v ic e (J W S) E n d p o in t . J W S è u n m e c c a n ism o c h e
p e r m e t t e d i ge n e r a r e u n W S Se r v e r a u t o m a t ic a m e n t e d a c o d ic e J a v a . Ac c e d e r e d a
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
3/14
b r o w se r a l l a u r l h t t p :/ / l o c a l h o st :8 0 8 0 / a xis/ E c h o H e a d e r s.j w s? m e t h o d = l ist . D o v r e b b e
a p p a r ir e q u a l c o sa d i sim il e :
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<listResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<listReturn xsi:type="soapenc:Array"
soapenc:arrayType="xsd:string[6]"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<item>accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*</item>
<item>accept-language:en-us</item>
<item>accept-encoding:gzip, deflate</item>
<item>user-agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)</item>
<item>host:localhost:8080</item>
<item>connection:Keep-Alive</item>
</listReturn>
</listResponse>
</soapenv:Body>
</soapenv:Envelope>
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
4/14
G enerazione di un W S tramite JW S
I f il e .j ws so n o f il e .j av a c o n d iv e r sa e st e n sio n e , c h e v e n go n o r ic o n o sc iu t i d a A x i s e
c o m p il a t i a l p r im o a c c e sso . Sc r iv e r e l a se gu e n t e c l a sse J a v a e c o p ia r l a n e l l a c a r t e l l a
webapps/ ax i s.
// calcolatore.jws
public cla s s C alcolatore {
public in t som m a( in t i 1 ,
r e t ur n i 1 + i 2 ;
}
}
in t
public in t sottraz i on e( in t
r e t ur n i 1 - i 2 ;
}
i 2 )
i 1 ,
{
in t
i 2 )
{
Ac c e d e r e d a b r o w se r a l l a u r l h t t p :/ / l o c a l h o st :8 0 8 0 / a xis/ Ca l c o l a t o r e .j w s.Axis c o m p il a
a u t o m a t ic a m e n t e l a c l a sse e c o n v e r t e l e c h ia m a t e SO AP in in v o c a z io n i d i m e t o d o
d e l l a c l a sse . I l f il e C al c o l at o r e.c l ass v e r r à p o st o in ax i s/ W E B -I N F / j wsC l asses.
E ` p o ssib il e e sa m in a r e il w sd l su h t t p :/ / l o c a l h o st :8 0 8 0 / a xis/ Ca l c o l a t o r e .j w s? w sd l
<?x m l v e r s i o n ="1. 0 " e n c o d i
<w s d l :d e f i n i t i o n s t a r g e t
x m l n s :a p a c h e s o a p ="h t
x m l n s :i m p l ="h t t p ://l
x m l n s :i n t f ="h t t p ://l
M.G.C.A.Cimino,”Applicazioni Java-W
n g ="U T F -8 " ?>
N a m e s p a c e ="h t t p ://l o c
t p ://x m l . a p a c h e . o r g /x
o c a l h o s t :8 0 8 0 /a x i s /C a
o c a l h o s t :8 0 8 0 /a x i s /C a
S con Ax is ”, D ipar t ime nt o d i I
a l
m l
l c
l c
ng
h o s
-s o
o l a
o l a
e g ne
t :8 0
a p "
t o r e
t o r e
r ia d e
8 0 /a x i s /C a l c o l a t o r e . j w s "
. j w s "
. j w s "
ll’ I nf or mazione - U nive r s it à d i P is a
5/14
x m l n s :s o a
x m l n s :w s d
x m l n s :w s d
x m l n s :x s d
<! -- W S D L c
<w s d l :m e s s a
<w s d l :p a r
<w s d l :p a r
</w s d l :m e s s
<w s d l :m e s s a
<w s d l :p a r
</w s d l :m e s s
<w s d l :m e s s a
<w s d l :p a r
</w s d l :m e s s
<w s d l :m e s s a
<w s d l :p a r
<w s d l :p a r
</w s d l :m e s s
<w s d l :p o r t T
<w s d l :o p e
<w s d l :i
<w s d l :o
</w s d l :o p
<w s d l :o p e
<w s d l :i
<w s d l :o
</w s d l :o p
</w s d l :p o r t
<w s d l :b i n d i
<w s d l s o a p
<w s d l :o p e
<w s d l s o
<w s d l :i
<w s d l
p e n c ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
l ="h t t p ://s c h e m a s . x m l s o a p . o r g /w s d l /"
l s o a p ="h t t p ://s c h e m a s . x m l s o a p . o r g /w s d l /s o a p /"
="h t t p ://w w w . w 3 . o r g /20 0 1/X M L S c h e m a ">
r e a t e d b y A p a c h e A x i s v e r s i o n : 1. 2R C 2 B u i l t o n N o v 16
g e n a m e ="s o m m a R e q u e s t ">
t n a m e ="i 1" t y p e ="x s d :i n t " />
t n a m e ="i 2" t y p e ="x s d :i n t " />
a g e >
g e n a m e ="s o t t r a z i o n e R e s p o n s e ">
t n a m e ="s o t t r a z i o n e R e t u r n " t y p e ="x s d :i n t " />
a g e >
g e n a m e ="s o m m a R e s p o n s e ">
t n a m e ="s o m m a R e t u r n " t y p e ="x s d :i n t " />
a g e >
g e n a m e ="s o t t r a z i o n e R e q u e s t ">
t n a m e ="i 1" t y p e ="x s d :i n t " />
t n a m e ="i 2" t y p e ="x s d :i n t " />
a g e >
y p e n a m e ="C a l c o l a t o r e ">
r a t i o n n a m e ="s o m m a " p a r a m e t e r O r d e r ="i 1 i 2">
n p u t m e s s a g e ="i m p l :s o m m a R e q u e s t " n a m e ="s o m m a R e q u e s t "
u t p u t m e s s a g e ="i m p l :s o m m a R e s p o n s e " n a m e ="s o m m a R e s p o n s
e r a t i o n >
r a t i o n n a m e ="s o t t r a z i o n e " p a r a m e t e r O r d e r ="i 1 i 2">
n p u t m e s s a g e ="i m p l :s o t t r a z i o n e R e q u e s t " n a m e ="s o t t r a z i
u t p u t m e s s a g e ="i m p l :s o t t r a z i o n e R e s p o n s e " n a m e ="s o t t r a
e r a t i o n >
T y p e >
n g n a m e ="C a l c o l a t o r e S o a p B i n d i n g " t y p e ="i m p l :C a l c o l a t o
:b i n d i n g s t y l e ="r p c " t r a n s p o r t ="h t t p ://s c h e m a s . x m l s o a
r a t i o n n a m e ="s o m m a ">
a p :o p e r a t i o n s o a p A c t i o n ="" />
n p u t n a m e ="s o m m a R e q u e s t ">
s o a p :b o d y e n c o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s
n a m e s p a c e ="h t t p ://D e f a u l t N a m e s p a c e " u s e ="e n
</w s d l :i n p u t >
<w s d l :o u t p u t n a m e ="s o m m a R e s p o n s e ">
<w s d l s o a p :b o d y e n c o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s
n a m e s p a c e ="h t t p ://l o c a l h o s t :8 0 8 0 /a x i s /C a l c o
</w s d l :o u t p u t >
</w s d l :o p e r a t i o n >
<w s d l :o p e r a t i o n n a m e ="s o t t r a z i o n e ">
<w s d l s o a p :o p e r a t i o n s o a p A c t i o n ="" />
,
20 0 4
( 12:19 :4 4
E S T )
-->
/>
e " />
o n e R e q u e s t " />
z i o n e R e s p o n s e " />
r e ">
p . o r g /s o a p /h t t p " />
o a p /e n c o d i n g /"
c o d e d " />
o a p /e n c o d i n g /"
l a t o r e 0 u 10 6 ?w s " u s e ="e n c o d e d " />
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
6/14
<w s d l :i n p u t n a m e ="s o
<w s d l s o a p :b o d y e n c
n a m
</w s d l :i n p u t >
<w s d l :o u t p u t n a m e ="s
<w s d l s o a p :b o d y e n c
n a m
</w s d l :o u t p u t >
</w s d l :o p e r a t i o n >
</w s d l :b i n d i n g >
<w s d l :s e r v i c e n a m e ="C a l c
<w s d l :p o r t b i n d i n g ="i m
<w s d l s o a p :a d d r e s s l o
</w s d l :p o r t >
</w s d l :s e r v i c e >
</w s d l :d e f i n i t i o n s >
t t r a z i o n e R e q u e s t ">
o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
e s p a c e ="h t t p ://D e f a u l t N a m e s p a c e " u s e ="e n c o d e d " />
o t t r a z i o n e R e s p o n s e ">
o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
e s p a c e ="h t t p ://l o c a l h o s t :8 0 8 0 /a x i s /C a l c o l a t o r e . j w s " u s e ="e n c o d e d " />
o l a t o r e S e r v i c e ">
p l :C a l c o l a t o r e S o a p B i n d i n g " n a m e ="C a l c o l a t o r e ">
c a t i o n ="h t t p ://l o c a l h o s t :8 0 8 0 /a x i s /C a l c o l a t o r e . j w s " />
P e r t e st a r e il f u n z io n a m e n t o d e l n o st r o W S Se r v e r , sv il u p p ia m o u n W S Cl ie n t c o m e
d i se gu it o :
// C a l c o l a t o r e C l i e n t . j a v a
i m p
i m p
i m p
i m p
o r t
o r t
o r t
o r t
i m p o r t
o r g
o r g
o r g
o r g
. a p
. a p
. a p
. a p
a c h
a c h
a c h
a c h
e . a
e . a
e . a
e . a
x i s
x i s
x i s
x i s
. c l
. c l
. e n
. u t
i e n
i e n
c o d
i l s
t . C
t . S
i n g
. O p
a l l
e r v
. X M
t i o
;
i c e ;
L T y p e ;
n s ;
j a v a x . x m l . r p c . P a r a m e t e r M o d e ;
p u b l i c cl a s s C a l c o l a t o r e C l i e n t
{
p u b l i c s t a t i c v o i d m a i n ( S t r i n g [ ] a r g s ) t h r o w s
O p t i o n s o p t i o n s = n e w O p t i o n s ( a r g s ) ;
S t r i n g
a r g s
i f
e n d p o i n t
E x c e p t i o n
{
= "h t t p ://l o c a l h o s t :" + o p t i o n s . g e t P o r t ( )
"/a x i s /C a l c o l a t o r e . j w s ";
+
= o p t i o n s . g e t R e m a i n i n g A r g s ( ) ;
( a r g s == n u l l | | a r g s . l e n g t h ! = 3 ) {
S y s t e m . e r r . p r i n t l n ( "U s o : C a l c o l a t o r e C l i e n t
<s o m m a | s o t t r a z i o n e > a r g 1 a r g 2") ;
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
7/14
r e t u r n ;
}
S t r i n g m
i f ( ! ( m e
S y s t
r e t u
}
e t
t h
e m
r n
I n t e g e r
I n t e g e r
i 1 = n e w
i 2 = n e w
S e r v i c e
C a l l
s e r v i c e
c a l l
c a
c a
c a
c a
c a
l l
l l
l l
l l
l l
. s
. s
. a
. a
. s
e t
e t
d d
d d
e t
I n t e g e r
}
}
T a
O p
P a
P a
R e
h o d = a r g s [ 0 ] ;
o d . e q u a l s ( "s o m m a ") | | m e t h o d . e q u a l s ( "s o t t r a z i o n e ") ) ) {
. e r r . p r i n t l n ( "U s o : C a l c o l a t o r e C l i e n t <s o m m a | s o t t r a z i o n e > a r g 1 a r g 2") ;
;
r g
e r
r a
r a
t u
r e t
e t
a t
m e
m e
r n
E n
i o
t e
t e
T y
I n t e g e r ( a r g s [ 1] ) ;
I n t e g e r ( a r g s [ 2] ) ;
= n e w S e r v i c e ( ) ;
= ( C a l l ) s e r v i c e . c r e a t e C a l l ( ) ;
d p o i n t A d d r e s s
n N a m e ( m e t h o d
r ( "o p 1", X M L
r ( "o p 2", X M L
p e ( X M L T y p e . X
= ( I n t e g e r )
(
n e
) ;
T y p e
T y p e
S D _ I
j a v a . n e t . U R L ( e n d p o i n t )
w
. X S D _ I N T ,
. X S D _ I N T ,
N T ) ;
c a l l . i n v o k e (
S y s t e m . o u t . p r i n t l n ( "R i s u l t a t o
: " +
P a r a m e t e r M o d e . I N
P a r a m e t e r M o d e . I N
O b j e c t
n e w
) ;
[ ]
{ i 1,
) ;
) ;
i 2 }) ;
r e t ) ;
I l se gu e n t e sc r ip t p r o v v e r e a c o m p il a r e e d e se gu ir e il c l ie n t .
rem
@ ec h
s et
s etl
s et
s et
j av
j av
j av
en d
make.bat
o o f f
CL A S S P A T H =
o c al
l i b= C:\to mc at5 \w
l i bs = % l i b% ax i s .j
% l i b% c o mmo n
ac -c l as s p ath "% l
a -c l as s p ath "% l i
a -c l as s p ath "% l i
l o c al
ebap p s \ax i s
ar; % l i b% j ax
s -d i s c o v ery
i bs % " * .j av
bs % " Cal c o l
bs % " Cal c o l
\W E B -I N F
rp c .j ar;
.j ar; % l
a
ato reCl i
ato reCl i
\l i b\
% l i b% s aaj .j ar; % l i b% c o mmo n s -l o g g i n g .j ar; % l i b% w s d l 4 j .j ar;
i b% ac ti v ati o n .j ar; % l i b% mai l .j ar;
en t -p 8 0 8 0
en t -p 8 0 8 0
s o mma 3 7
s o ttraz i o n e 9
5
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
8/14
@ ec h o
o n
P r o d u c e n d o il se gu e n t e r isu l t a t o
C:my w s > make
R i s u l tato : 1 0
R i s u l tato : 4
G enerazione di un W S tramite Jav a2 W S D L
J a v a 2 W SD L p e r m e t t e l a c r e a z io n e d i W S c o n m a ggio r f l e ssib il it à in f a se
sv il u p p o , m e d ia n t e il f o r m a t o W eb S er v i c e D epl o y m en t D esc r i pt o r (W SD D ).
d i
Su p p o n ia m o d i a v e r e i t r e f il e d i t e st o se gu e n t i:
C:my w s \make.bat
C:my w s \Cal c o l ato reCl i en t2.j av a
C:my w s \s amp l es \c al c o l ato re\Cal c o l ato re.j av a
// C a l c o l a t o r e . j a v a
p a ck a g e s a m p l e s . c a l c o l a t o r e ;
p u b l i c i n t e r f a ce C a l c o l a t o r e {
p u b l i c i n t s o m m a ( i n t i 1, i n t i 2) ;
p u b l i c i n t s o t t r a z i o n e ( i n t i 1, i n t
}
i 2) ;
M o st r e r e m o m a n m a n o il f il e m ak e.bat . P r im a d i t u t t o , c o m p il ia m o il c o d ic e j a v a :
rem make.bat
@ ec h o o f f
s et CL A S S P A T H =
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
9/14
s etl o c al
s et l i b= C:\to mc at5 \w
s et l i bs = % l i b% ax i s .j
% l i b% c o mmo n
j av ac -c l as s p ath "% l
ebap
ar; %
s -d i
i bs %
p s
l i
s c
"
\ax i s
b% j ax
o v ery
s amp l
\W
rp
.j
es
E B -I N F
c .j ar;
ar; % l i
/ c al c o
\l i b\
% l i b% s aaj .j ar; % l i b% c o mmo n s -l o g g i n g .j ar; % l i b% w s d l 4 j .j ar;
b% ac ti v ati o n .j ar; % l i b% mai l .j ar;
l ato re/ * .j av a
Q u in d i si c r e a il W SD L u sa n d o j a v a 2 SW D L , c o n l e se gu e n t i o p z io n i: -o <n o m e d el
f i l e wsd l g en er at o > , -l <c o l l o c az i o n e d el ser v i z i o > , -n <n am espac e d eg l i el em en t i
d el wsd l > -p< n am espac e e pac k ag e asso c i at o >
s et s erv i c e_ l o c ati o n = h ttp :/ / l o c al h o s t:8 0 8 0 / ax i s / s erv i c es / Cal c o l ato re
s et targ et_ n ames p ac e= u rn :c al c o l ato re
s et p ac kag e= s amp l es .c al c o l ato re
j av a -c l as s p ath "% l i bs % " o rg .ap ac h e.ax i s .w s d l .J av a2W S D L -o Cal c o l ato re.w s d l
-l "% s erv i c e_ l o c ati o n % " -n "% targ et_ n ames p ac e% " -p "% p ac kag e% " "% targ et_ n ames p ac e% "
s amp l es .c al c o l ato re.Cal c o l ato re
V ie n e ge n e r a t o u n f il e
<?x m l v e r s i o n ="1. 0 " e
<w s d l :d e f i n i t i o n s t
x m l
x m l
x m l
x m l
x m l
x m l
x m l
<! --W S D L c r e a t e d b y
<w s d l :m e s s a g e n a m e
<w s d l :p a r t n a m e
</w s d l :m e s s a g e >
<w s d l :m e s s a g e n a m e
<w s d l :p a r t n a m e
<w s d l :p a r t n a m e
n c o d
a r g e
n s :i
n s :i
n s :a
n s :w
n s :s
n s :x
n s :w
A p a
="s o
="s o
i n g ="U
t N a m e s
m p l ="u
n t f ="u
p a c h e s
s d l s o a
o a p e n c
s d ="h t
s d l ="h
c h e A x
m m a R e s
m m a R e t
C:myws\Ca l c o l a t o r e . wsd l
T F -8 "?>
p a c e ="u r n :c a l c
r n :c a l c o l a t o r e
r n :c a l c o l a t o r e
o a p ="h t t p ://x m
p ="h t t p ://s c h e
="h t t p ://s c h e m
t p ://w w w . w 3 . o r
t t p ://s c h e m a s .
i s v e r s i o n : 1.
p o n s e ">
u r n " t y p e ="x s d
="s o t t r a z i o n e R e q u e s t ">
="i n 0 " t y p e ="x s d :i n t "/>
="i n 1" t y p e ="x s d :i n t "/>
o l a t o
"
"
l . a p a
m a s . x
a s . x m
g /20 0
x m l s o
2R C 2
d a l se gu e n t e c o n t e n u t o :
r e "
c h e
m l s
l s o
1/X
a p .
B u i
. o
o a
a p
M L
o r
l t
r g /x
p . o r
. o r g
S c h e
g /w s
o n
m l -s o a p "
g /w s d l /s o a p /"
/s o a p /e n c o d i n g /"
m a "
d l /">
N o v 16 , 20 0 4 ( 12:19 :4 4
E S T ) -->
:i n t "/>
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
10 /14
</w s d
<w s d l
<w
</w s d
<w s d l
<w
<w
</w s d
<w s d l
<w
l :m
:m e
s d l
l :m
:m e
s d l
s d l
l :m
:p o
s d l
<w
<w
</w s d
<w s d l
<w
<w
</w s d
</w s d l :p
<w s d l :b i
<w s d l
<w s d l
<w
<w
e s s
s s a
:p a
e s s
s s a
:p a
:p a
e s s
r t T
:o p
s d l
s d l
l :o
:o p
s d l
s d l
l :o
o r t
n d i
s o a
:o p
s d l
s d l
<w
a g e
g e
r t
a g e
g e
r t
r t
a g e
y p e
e r a
:i n
:o u
p e r
e r a
:i n
:o u
p e r
T y p
n g
p :b
e r a
s o a
:i n
s d l
>
n a m
n a m
>
n a m
n a m
n a m
>
n a
t i o
p u t
t p u
a t i
t i o
p u t
t p u
a t i
e >
n a m
i n d
t i o
p :o
p u t
s o a
e ="s o t t r a z i o n e R e s p o n s e ">
e ="s o t t r a z i o n e R e t u r n " t y p e ="x s d :i n t "/>
e ="s o m m a R e q u e s t ">
e ="i n 0 " t y p e ="x s d :i n t "/>
e ="i n 1" t y p e ="x s d :i n t "/>
m e
n
n
t
o n
n
n
t
o n
="C
n a m
a m e
n a m
>
n a m
a m e
n a m
>
e ="C
i n g
n n a
p e r a
n a m
p :b o
a l c o
e ="s
="s o
e ="s
l a
o m
m m
o m
t o
m a
a R
m a
r e
"
e q
R e
">
p a r a m e t e r O r d e r ="i n 0 i n 1">
u e s t " m e s s a g e ="i m p l :s o m m a R e q u e s t "/>
s p o n s e " m e s s a g e ="i m p l :s o m m a R e s p o n s e "/>
e ="s o t t r a z i o n e " p a r a m e t e r O r d e r ="i n 0 i n 1">
="s o t t r a z i o n e R e q u e s t " m e s s a g e ="i m p l :s o t t r a z i o n e R e q u e s t "/>
e ="s o t t r a z i o n e R e s p o n s e " m e s s a g e ="i m p l :s o t t r a z i o n e R e s p o n s e "/>
a l c o l
s t y l e
m e ="s
t i o n
e ="s o
d y u s
n a
a t o r
="r p
o m m a
s o a p
m m a R
e ="e
m e s p
</w s d l :i n p u t >
<w s d l :o u t p u t n a m e ="s o
<w s d l s o a p :b o d y u s e
n a m
</w s d l :o u t p u t >
</w s d l :o p e r a t i o n >
<w s d l :o p e r a t i o n n a m e ="s o
<w s d l s o a p :o p e r a t i o n s
<w s d l :i n p u t n a m e ="s o t
<w s d l s o a p :b o d y u s e
n a m
</w s d l :i n p u t >
<w s d l :o u t p u t n a m e ="s o
<w s d l s o a p :b o d y u s e
n a m
</w s d l :o u t p u t >
</w s d l :o p e r a t i o n >
</w s d l :b i n d i n g >
<w s d l :s e r v i c e n a m e ="C a l c o l a
e S o
c "
">
A c t
e q u
n c o
a c e
a p B i n d i n g " t y p e ="i m p l :C a l c o l a t o r e ">
t r a n s p o r t ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /h t t p "/>
i o n
e s t
d e d
="u
=""/>
">
" e n c o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
r n :c a l c o l a t o r e "/>
m m a R e s p o n s e ">
="e n c o d e d " e n c o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
e s p a c e ="u r n :c a l c o l a t o r e "/>
t t r
o a p
t r a
="e
e s p
a z
A c
z i
n c
a c
i o n e
t i o n
o n e R
o d e d
e ="u
">
=""/>
e q u e s t ">
" e n c o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
r n :c a l c o l a t o r e "/>
t t r a z i o n e R e s p o n s e ">
="e n c o d e d " e n c o d i n g S t y l e ="h t t p ://s c h e m a s . x m l s o a p . o r g /s o a p /e n c o d i n g /"
e s p a c e ="u r n :c a l c o l a t o r e "/>
t o r e S e r v i c e ">
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
11/14
<w s d l
<w
</w s d
</w s d l :s
</w s d l :d e f i
:p o
s d l
l :p
e r v
n i t
r t
s o
o r
i c
i o
n a m e ="C a l c o l a t o r e " b i n d i n g ="i m p l :C a l c o l a t o r e S o a p B i n d i n g ">
a p :a d d r e s s l o c a t i o n ="h t t p ://l o c a l h o s t :8 0 8 0 /a x i s /s e r v i c e s /C a l c o l a t o r e "/>
t >
e >
n s >
Si u sa il W SD L ge n e r a t o p e r c r e a r e t u t t i i c o m p o n e n t i n e c e ssa r i, c o n W SD L 2 J a v a :
j av a -c l as s p ath "% l i bs % " o rg .ap ac h e.ax i s .w s d l .W S D L 2J av a -o . -d S es s i o n
-N "% targ et_ n ames p ac e% " s amp l es .c al c o l ato re Cal c o l ato re.w s d l
-s
-S
tru e
V e n go n o ge n e r a t i i f il e se gu e n t i:
C:my w s \s amp
C:my w s \s amp
C:my w s \s amp
C:my w s \s amp
C:myws\sa mp
C:my w s \s amp
C:my w s \s amp
C:my w s \s amp
C:my w s \s amp
l es \c
l es \c
l es \c
l es \c
l e s\c
l es \c
l es \c
l es \c
l es \c
al
al
al
al
a l
al
al
al
al
c o l
c o l
c o l
c o l
c o l
c o l
c o l
c o l
c o l
ato
ato
ato
ato
a t o
ato
ato
ato
ato
re\Cal
re\Cal
re\Cal
re\Cal
r e \Ca l
re\Cal
re\Cal
re\d ep
re\u n d
c o l
c o l
c o l
c o l
c o l
c o l
c o l
l o y
ep l
ato re.c l as s
ato re.j av a
ato reS erv i c
ato reS erv i c
a t o r e S o a p B i
ato reS o ap B i
ato reS o ap B i
.w s d d
o y .w s d d
e.j
eL o
n d i
n d i
n d i
in te rfa c c
av a
in te rfa c c
c ato r.j av a
im p le m e
n g I mp l . j a v a
im p le m e
n g S kel eto n .j av a s k e l e t o n
n g S tu b.j av a
s tu b la to
d e s c ritto
d e s c ritto
ia d i p a rte n z a re s a re m o ta c o n R M I
ia d i s e rv iz io la to c lie n t
n ta z io n e d e l s e rv iz io la to c lie n t
n ta z io n e d i d e fa u lt d e l s e rv e r (c o m p le ta re )
la to s e rv e r
c lie n t
re d i d e p lo y m e n t
re d i u n d e p lo y m e n t
a n o i in t e r e ssa so l o Ca l c o l a t o r e S o a p B i n d i n g I mp l . j a v a : o c c o r r e se m p l ic e m e n t e
im p l e m e n t a r e i c o r p i d e i m e t o d i, in c u i v ie n e r it o r n a t o u n v a l o r e d i d e f a u l t -3.
// C a l c o l a t o r e S o a p B i n d i n g I m p l . j a v a
p a ck a g e
s a m p l e s . c a l c o l a t o r e ;
p u b l i c cl a s s C a l c o l a t o r e S o a p B i n d i n g I m p l i m p l e m e n t s s a m p l e s . c a l c o l a t o r e . C a l c o l a t o r e
p u b l i c i n t s o m m a ( i n t i n 0 , i n t i n 1) t h r o w s j a v a . r m i . R e m o t e E x c e p t i o n {
r e t u r n -3 ;
}
p u b l i c i n t s o t t r a z i o n e ( i n t i n 0 , i n t i n 1) t h r o w s j a v a . r m i . R e m o t e E x c e p t i o n {
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
{
12/14
}
}
r e t u r n
-3 ;
Fa t t o c iò , si p u ò f a r e il d e p l o y m e n t d e l se r v iz io m e d ia n t e l ’ a p p l ic a z io n e A d m i n C l i en t
e c o m p il a r e l e c l a ssi ge n e r a t e d a W S D L 2 J av a c o l l o c a n d o i f il e .c l ass n e l l a c a r t e l l a
W E B -I N F \c l asses d i Axis.
j av a -c l as s p ath "% l i bs % " o rg .ap ac h e.ax i s .c l i en t.A d mi n Cl i en t s amp l es \c al c o l ato re\d ep l o y .w s d d
s et d ep l o y d i r= C:\to mc at5 \w ebap p s \ax i s \W E B -I N F \c l as s es
j av ac –c l as s p ath "% l i bs % " s amp l es / c al c o l ato re/ * .j av a –d % d ep l o y d i r%
Ac c e d e n d o d a b r o w se r a l l a u r l
c o m p a r e u n m e ssa ggio d e l ge n e r e :
h t t p :/ / l o c a l h o st :8 0 8 0 / a xis/ se r v ic e s/ Ca l c o l a t o r e
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
13/14
Q
a
d
p
C
u e st o in d ic a c h e il se r v e r è a t t iv o . An
ggiu n ge n d o a l l a f in e d e l l a U R L il su
e l se r v iz io c h e p u ò e sse r e sa l v a t a d
o ssia m o a d o p e r a r e q u e l l o v ist o p e r il
al c o l at o r eC l i en t 2 e m o d if ic a n d o so l o
S t r i n g
e n d p o i n t
a l o ga m
f f isso ?
a c h i d
m e c c a n
l’e n d p o
= "h t t p ://l o c a l h o s t :" + o p t i o n s . g e t P o r t ( )
"/a x i s /s e r v i c e s /C a l c o l a t o r e ";
e n te a q u a n to fa
wsd l Axis ge n e
e v e sv il u p p a r e
ism o j w s, r in o m
in t n e l se gu e n t e
tto p e r l’e
r a l a d e sc
il c l ie n t .
in a n d o l a
m o d o :
n d p o in
r iz io n e
Co m e
c l a sse
t j w s,
w sd l
c l ie n t
c o m e
+
Fa t t o c iò si p u ò r ic o m p il a r e e r ie se gu ir e il c l ie n t , o t t e n e n d o o v v ia m e n t e i m e d e sim i
r isu l t a t i d e l se r v e r j w s. E c c o l ’ u l t im a p a r t e d e l f il e m ak e.bat :
j av
j av
j av
en d
@ ec
ac -c l as s p ath "% l i bs % " * .j av a
a -c l as s p ath "% l i bs % " Cal c o l ato reCl i en t2 -p 8 0 8 0
a -c l as s p ath "% l i bs % " Cal c o l ato reCl i en t2 -p 8 0 8 0
l o c al
h o o n
s o mma 3 7
s o ttraz i o n e 9
5
M.G.C.A.Cimino,”Applicazioni Java-W S con Ax is ”, D ipar t ime nt o d i I ng e g ne r ia d e ll’ I nf or mazione - U nive r s it à d i P is a
14/14