Professional Documents
Culture Documents
Apache CXF and Axis2 Web Services
Apache CXF and Axis2 Web Services
The JAX-WS implementation built into the JDK really is just the basic soap stuf. If you
nee any of the more comple! WS-" thin#s li$e WS-Security% WS-&'% WS-(olicy% etc...%
you nee to use one of the alternati)es li$e *X+ or 'etro or A!is,. It can also epen
on -hat you are tryin# to inte#rate -ith. +or e!ample% *X+ has top notch Sprin#
support as -ell as )ery #oo .S/i support.
*X+ also has other thin#s besies just JAX-WS. It has a compliant JAX-&S
implementation as -ell an supports e!posin# ser)ices as both &0ST an S.A( )ery
-ell. 1as a W2* compliant S.A(3J'S implementation if that type of thin#s is
re4uire. 5asically% lots of stuf not a)ailable from the in-j$ JAX-WS impl.
Inte#ration - *X+ has much better Sprin# inte#ration if you use Sprin#. All the
con6#uration an such is one throu#h Sprin#. Also% people ten to consier *X+ as
more 7embeable7 8I9)e ne)er loo$e at A!is, from this perspecti)e: into other
applications. ;ot sure if thin#s li$e that matter to you.
(erformance - they both perform )ery -ell. I thin$ A!is,9s proprietary AD5
atabinin# is a bit faster than *X+% but if you use JAX5 8stanars base A(I9s
a#ain:% *X+ is a bit faster. When usin# more comple! scenarios li$e WS-Security% the
unerlyin# security 7en#ine7 8WSS<J: is the same for both so the performance is
completely comparable.
=ou nee to o-nloa
>. JDK ?
,. 0clipse 2.@
2. *X+-,.@.,
<. Tomcat @
+ollo-in# jar must be in *lass(ath
>. aopalliance->.A.jar
,. commons-lo##in#->.>.>.jar
2. c!f-,.@.,.jar
<. httpasyncclient-<.A-beta2.jar
B. httpclient-<.,.>.jar
?. httpcore-<.,.,.jar
@. httpcore-nio-<.,.,.jar
C. neethi-2.A.,.jar
D. sprin#-aop-2.A.@.&0E0AS0.jar
>A. sprin#-asm-2.A.@.&0E0AS0.jar
>>. sprin#-beans-2.A.@.&0E0AS0.jar
>,. sprin#-conte!t-2.A.@.&0E0AS0.jar
>2. sprin#-core-2.A.@.&0E0AS0.jar
><. sprin#-e!pression-2.A.@.&0E0AS0.jar
>B. sprin#--eb-2.A.@.&0E0AS0.jar
>?. -sl<j->.?.,.jar
>@. !mlschema-core-,.A.2.jar
Developing a Service using JAX-WS
=ou can e)elop a ser)ice usin# one of t-o approachesF
Start -ith a WSDE contract an #enerate Ja)a objects to implement the
ser)ice.
Start -ith a Ja)a object an ser)ice enable it usin# annotations.
+or ne- e)elopment the preferre path is to esi#n your ser)ices in WSDE an then
#enerate the coe to implement them. This approach enforces the concept that a
ser)ice is an abstract entity that is implementation neutral. It also means you can
spen more time -or$in# out the e!act interface your ser)ice re4uires before you
start coin#.
1o-e)er% there are many cases -here you may nee to ser)ice enable an e!istin#
application. While JAX-WS eases the process% it oes re4uire that you ma$e some
chan#es to source coe of your application. =ou -ill nee to a annotations to the
source. It also re4uires that you mi#rate your coe to Ja)a B.A.
WSDL First Development
Gsin# the WSDE 6rst moel of ser)ice e)elopment% you start -ith a WSDE ocument
that e6nes the ser)ice you -ish to implement. This WSDE ocument coul be
obtaine from another e)eloper% a system architect% a GDDI re#istry% or you coul
-rite it yourself. The ocument must contain at least a fully speci6e lo#ical interface
before you can be#in #eneratin# coe from it.
.nce you ha)e a WSDE ocument% the process for e)elopin# a JAX-WS ser)ice is
three stepsF
>. /enerate startin# point coe.
,. Implement the ser)ice9s operations.
2. (ublish the implemente ser)ice.
enerating the Starting !oint Code
JAX-WS speci6es a etaile mappin# from a ser)ice e6ne in WSDE to the Ja)a
classes that -ill implement that ser)ice. The lo#ical interface% e6ne by the
-slFportType element% is mappe to a ser)ice enpoint interface 8S0I:. Any comple!
types e6ne in the WSDE are mappe into Ja)a classes follo-in# the mappin#
e6ne by the Ja)a Architecture for X'E 5inin# 8JAX5: speci6cation. The enpoint
e6ne by the -slFser)ice element is also #enerate into a Ja)a class that is use
by consumers to access enpoints implementin# the ser)ice.
The -sl,ja)a comman automates the #eneration of this coe. It also pro)ies
options for #eneratin# startin# point coe for your implementation an an ant base
ma$e6le to buil the application. -sl,ja)a pro)ies a number of ar#uments for
controllin# the #enerate coe.
"unning #sdl2$ava
=ou can #enerate the coe neee to e)elop your ser)ice usin# the follo-in#
commanF
-sl,ja)a -ant -impl -ser)er - outputDir mySer)ice.-sl
The comman oes the follo-in#F
The -ant ar#ument #enerates a Ant ma$e6le% calle buil.!ml% for your
application.
The -impl ar#ument #enerates a shell implementation class for each portType
element in the WSDE ocument.
The -ser)er ar#ument #enerates a simple main8: to launch your ser)ice as a
stan alone application.
The - outputDir ar#ument tells -sl,ja)a to -rite the #enerate coe to a
irectory calle outputDir.
mySer)ice.-sl is the WSDE ocument from -hich coe is #enerate.
enerated code
Table> escribes the 6les #enerate for creatin# a ser)ice.
Table >F /enerate *lasses for a Ser)ice
+ile Description
portType;ame.ja)a
The S0I. This 6le contains the interface
your ser)ice implements. =ou shoul not
eit this 6le.
ser)ice;ame.ja)a
The enpoint. This 6le contains the Ja)a
class your clients -ill use to ma$e re4uests
on the ser)ice.
portType;ameImpl.ja)a
The s$eleton implementation class. =ou -ill
moify this 6le to implement your ser)ice.
portType;ameHportType;ameImpl(ortHSer
)er.ja)a
A basic ser)er main8: that allo-s you to
eploy your ser)ice as a stan alone
process
%mplementing the Service
.nce the startin# point coe is #enerate% you must pro)ie the business lo#ic for
each of the operations e6ne in the ser)ice9s interface.
enerating the implementation code
=ou #enerate the implementation class for your ser)ice -ith -sl,ja)a9s -impl Ia#.
enerated code
The ser)ice implementation coe consists of t-o 6lesF
portType;ame.ja)a is the ser)ice interface8S0I: for the ser)ice.
portType;ameImpl.ja)a is the class you -ill use to implement the operations
e6ne for the ser)ice.
%mplement the operation&s logic
=ou pro)ie the business lo#ic for your ser)ice9s operations by completin# the stub
methos in portType;ameImpl.ja)a. +or the most part% you use stanar Ja)a to
implement the business lo#ic. If your ser)ice uses custom X'E Schema types% you
-ill nee to use the #enerate classes for each type to manipulate them. There are
also some *X+ speci6c A(Is that you can use to access some a)ance features.
Java First Development
To create a ser)ice startin# from Ja)a you nee to o the follo-in#F
>. *reate a Ser)ice 0npoint Interface 8S0I: that e6nes the methos you -ish to
e!pose as a ser)ice.
'ip
=ou can -or$ irectly from a Ja)a class% but -or$in# from an interface is the
recommene approach. Interfaces are better for sharin# -ith the
e)elopers -ho -ill be responsible for e)elopin# the applications
consumin# your ser)ice. The interface is smaller an oes not pro)ie any
of the ser)ice9s implementation etails.
,. A the re4uire annotations to your coe.
2. /enerate the WSDE contract for your ser)ice.
'ip
If you inten to use the S0I as the ser)ice9s contract% it is not necessary to
#enerate a WSDE contract
<. (ublish the ser)ice.
Creating the S(%
The ser)ice enpoint interface 8S0I: is the piece of Ja)a coe that is share bet-een
a ser)ice an the consumers that ma$e re4uests on it. When startin# -ith a WSDE
contract% the S0I is #enerate by the coe #enerators. 1o-e)er% -hen startin# from
Ja)a% it is the up to a e)eloper to create the S0I.
There are t-o basic patterns for creatin# an S0IF
/reen 6el e)elopment
=ou are e)elopin# a ne- ser)ice from the #roun up. When startin# fresh% it
is best to start by creatin# the S0I 6rst. =ou can then istribute the S0I to any
e)elopers that are responsible for implementin# the ser)ices an consumers
that use the S0I.
)ote
The recommene -ay to o #reen 6el ser)ice e)elopment is to start by
creatin# a WSDE contract that e6nes the ser)ice an its interfaces.
Ser)ice enablement
In this pattern% you typically ha)e an e!istin# set of functionality that is
implemente as a Ja)a class an you -ant to ser)ice enable it. This means
that you -ill nee to o t-o thin#sF
>. *reate an S0I that contains onl* the operations that are #oin# to be
e!pose as part of the ser)ice.
,. 'oify the e!istin# Ja)a class so that it implements the S0I.
)ote
=ou can a the JAX-WS annotations to a Ja)a class% but that is not
recommene.
Writing the inter+ace
The S0I is a stanar Ja)a interface. It e6nes a set of methos that a class -ill
implement. It can also e6ne a number of member 6els an constants to -hich the
implementin# class has access.
In the case of an S0I the methos e6ne are intene to be mappe to operations
e!pose by a ser)ice. The S0I correspons to a -slFportType element. The methos
e6ne by the S0I correspon to -slFoperation elements in the -slFportType
element.
'ip
JAX-WS e6nes an annotation that allo-s you to specify methos that are not
e!pose as part of a ser)ice. 1o-e)er% the best practice is to lea)e such methos
out of the S0I.
package org.apache.cxf;
public interface QuoteReporter
{
public Quote getQuote(String ticker);
}
Implementing the interface