Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 41

Apache CXF and Axis2 Web services The JAX-WS implementation built into the JDK really is just

the basic soap stuff. If you need any of the more comple WS-! thin"s li#e WS-Security$ WS-%&$ WS-'olicy$ etc...$ you need to use one of the alternati(es li#e )X* or &etro or A is+. It can also depend on ,hat you are tryin" to inte"rate ,ith. *or e ample$ )X* has top notch Sprin" support as ,ell as (ery "ood -S.i support. )X* also has other thin"s besides just JAX-WS. It has a compliant JAX-%S implementation as ,ell and supports e posin" ser(ices as both %/ST and S-A' (ery ,ell. 0as a W1) compliant S-A'2J&S implementation if that type of thin"s is re3uired. 4asically$ lots of stuff not a(ailable from the in-jd# JAX-WS impl.

Inte"ration - )X* has much better Sprin" inte"ration if you use Sprin". All the confi"uration and such is done throu"h Sprin". Also$ people tend to consider )X* as more 5embeddable5 6I7(e ne(er loo#ed at A is+ from this perspecti(e8 into other applications. 9ot sure if thin"s li#e that matter to you. 'erformance - they both perform (ery ,ell. I thin# A is+7s proprietary AD4 databindin" is a bit faster than )X*$ but if you use JAX4 6standards based A'I7s a"ain8$ )X* is a bit faster. When usin" more comple scenarios li#e WS-Security$ the underlyin" security 5en"ine5 6WSS:J8 is the same for both so the performance is completely comparable. ;ou need to do,nload <. JDK = +. /clipse 1.> 1. )X*-+.>.+ 4. Tomcat > *ollo,in" jar must be in )lass'ath <. aopalliance-<.?.jar +. commons-lo""in"-<.<.<.jar 1. c f-+.>.+.jar :. httpasyncclient-:.?-beta1.jar @. httpclient-:.+.<.jar =. httpcore-:.+.+.jar >. httpcore-nio-:.+.+.jar A. neethi-1.?.+.jar B. sprin"-aop-1.?.>.%/C/AS/.jar <?. sprin"-asm-1.?.>.%/C/AS/.jar <<. sprin"-beans-1.?.>.%/C/AS/.jar <+. sprin"-conte t-1.?.>.%/C/AS/.jar <1. sprin"-core-1.?.>.%/C/AS/.jar <:. sprin"-e pression-1.?.>.%/C/AS/.jar <@. sprin"-,eb-1.?.>.%/C/AS/.jar <=. ,sdl:j-<.=.+.jar <>. mlschema-core-+.?.1.jar

Developing a Service using JAX-WS ;ou can de(elop a ser(ice usin" one of t,o approachesD Start ,ith a WSDC contract and "enerate Ja(a objects to implement the ser(ice. Start ,ith a Ja(a object and ser(ice enable it usin" annotations.

*or ne, de(elopment the preferred path is to desi"n your ser(ices in WSDC and then "enerate the code 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 spend more time ,or#in" out the e act interface your ser(ice re3uires before you start codin". 0o,e(er$ there are many cases ,here you may need to ser(ice enable an e istin" application. While JAX-WS eases the process$ it does re3uire that you ma#e some chan"es to source code of your application. ;ou ,ill need to add annotations to the source. It also re3uires that you mi"rate your code to Ja(a @.?. WSDL First Development Esin" the WSDC first model of ser(ice de(elopment$ you start ,ith a WSDC document that defines the ser(ice you ,ish to implement. This WSDC document could be obtained from another de(eloper$ a system architect$ a EDDI re"istry$ or you could ,rite it yourself. The document must contain at least a fully specified lo"ical interface before you can be"in "eneratin" code from it. -nce you ha(e a WSDC document$ the process for de(elopin" a JAX-WS ser(ice is three stepsD <. .enerate startin" point code. +. Implement the ser(ice7s operations. 1. 'ublish the implemented ser(ice. enerating the Starting !oint Code JAX-WS specifies a detailed mappin" from a ser(ice defined in WSDC to the Ja(a classes that ,ill implement that ser(ice. The lo"ical interface$ defined by the ,sdlDportType element$ is mapped to a ser(ice endpoint interface 6S/I8. Any comple types defined in the WSDC are mapped into Ja(a classes follo,in" the mappin" defined by the Ja(a Architecture for X&C 4indin" 6JAX48 specification. The endpoint defined by the ,sdlDser(ice element is also "enerated into a Ja(a class that is used by consumers to access endpoints implementin" the ser(ice. The ,sdl+ja(a command automates the "eneration of this code. It also pro(ides options for "eneratin" startin" point code for your implementation and an ant based ma#efile to build the application. ,sdl+ja(a pro(ides a number of ar"uments for controllin" the "enerated code.

"unning #sdl2$ava ;ou can "enerate the code needed to de(elop your ser(ice usin" the follo,in" commandD ,sdl+ja(a -ant -impl -ser(er -d outputDir mySer(ice.,sdl The command does the follo,in"D The -ant ar"ument "enerates a Ant ma#efile$ called build. ml$ for your application. The -impl ar"ument "enerates a shell implementation class for each portType element in the WSDC document. The -ser(er ar"ument "enerates a simple main68 to launch your ser(ice as a stand alone application. The -d outputDir ar"ument tells ,sdl+ja(a to ,rite the "enerated code to a directory called outputDir. mySer(ice.,sdl is the WSDC document from ,hich code is "enerated.

enerated code Table< describes the files "enerated for creatin" a ser(ice. Table <D .enerated )lasses for a Ser(ice Description The S/I. This file contains the interface portType9ame.ja(a your ser(ice implements. ;ou should not edit this file. The endpoint. This file contains the Ja(a ser(ice9ame.ja(a class your clients ,ill use to ma#e re3uests on the ser(ice. The s#eleton implementation class. ;ou portType9ameImpl.ja(a ,ill modify this file to implement your ser(ice. A basic ser(er main68 that allo,s you to portType9ameFportType9ameImpl'ortFSe deploy your ser(ice as a stand alone r(er.ja(a process %mplementing the Service -nce the startin" point code is "enerated$ you must pro(ide the business lo"ic for each of the operations defined in the ser(ice7s interface. enerating the implementation code ;ou "enerate the implementation class for your ser(ice ,ith ,sdl+ja(a7s -impl fla". enerated code The ser(ice implementation code consists of t,o filesD *ile

portType9ame.java is the ser(ice interface6S/I8 for the ser(ice. portType9ameImpl.java is the class you ,ill use to implement the operations defined for the ser(ice.

%mplement the operation&s logic ;ou pro(ide the business lo"ic for your ser(ice7s operations by completin" the stub methods in portType9ameImpl.java. *or the most part$ you use standard Ja(a to implement the business lo"ic. If your ser(ice uses custom X&C Schema types$ you ,ill need to use the "enerated classes for each type to manipulate them. There are also some )X* specific A'Is that you can use to access some ad(anced features. Java First Development To create a ser(ice startin" from Ja(a you need to do the follo,in"D <. )reate a Ser(ice /ndpoint Interface 6S/I8 that defines the methods you ,ish to e pose as a ser(ice. 'ip ;ou can ,or# directly from a Ja(a class$ but ,or#in" from an interface is the recommended approach. Interfaces are better for sharin" ,ith the de(elopers ,ho ,ill be responsible for de(elopin" the applications consumin" your ser(ice. The interface is smaller and does not pro(ide any of the ser(ice7s implementation details. +. Add the re3uired annotations to your code. 1. .enerate the WSDC contract for your ser(ice. 'ip If you intend to use the S/I as the ser(ice7s contract$ it is not necessary to "enerate a WSDC contract :. 'ublish the ser(ice. Creating the S(% The ser(ice endpoint interface 6S/I8 is the piece of Ja(a code that is shared bet,een a ser(ice and the consumers that ma#e re3uests on it. When startin" ,ith a WSDC contract$ the S/I is "enerated by the code "enerators. 0o,e(er$ ,hen startin" from Ja(a$ it is the up to a de(eloper to create the S/I. There are t,o basic patterns for creatin" an S/ID .reen field de(elopment ;ou are de(elopin" a ne, ser(ice from the "round up. When startin" fresh$ it is best to start by creatin" the S/I first. ;ou can then distribute the S/I to any de(elopers that are responsible for implementin" the ser(ices and consumers that use the S/I. )ote The recommended ,ay to do "reen field ser(ice de(elopment is to start by creatin" a WSDC contract that defines the ser(ice and its interfaces. Ser(ice enablement In this pattern$ you typically ha(e an e istin" set of functionality that is implemented as a Ja(a class and you ,ant to ser(ice enable it. This means that you ,ill need to do t,o thin"sD

<. )reate an S/I that contains onl* the operations that are "oin" to be e posed as part of the ser(ice. +. &odify the e istin" Ja(a class so that it implements the S/I. )ote ;ou can add the JAX-WS annotations to a Ja(a class$ but that is not recommended. Writing the inter+ace The S/I is a standard Ja(a interface. It defines a set of methods that a class ,ill implement. It can also define a number of member fields and constants to ,hich the implementin" class has access. In the case of an S/I the methods defined are intended to be mapped to operations e posed by a ser(ice. The S/I corresponds to a wsdl:portType element. The methods defined by the S/I correspond to wsdl:operation elements in the wsdl:portType element. 'ip JAX-WS defines an annotation that allo,s you to specify methods that are not e posed as part of a ser(ice. 0o,e(er$ the best practice is to lea(e such methods out of the S/I. package org.apache.cxf; public interface uote!eporter " public uote get uote#$tring ticker%; &

Implementing the interface


Developing a Service using JAX-WS o WSDL First Development Generating the Starting Point Co e !unning "s l#$ava Generate co e %mplementing the Service Generating the implementation co e Generate co e %mplement the operation&s logic '(ample o Java First Development Creating the S'% Writing the inter)ace

%mplementing the inter)ace Annotating the Co e !e*uire Annotations +he '(eb$ervice annotation Annotating the S'% Annotating the service implementation ,ptional Annotations De)ining the -in ing Properties "ith Annotations +he '$)*+,inding annotation De)ining ,peration Properties "ith Annotations +he '(eb-ethod annotation +he '!e.uest(rapper annotation +he '!esponse(rapper annotation +he '(eb/ault annotation +he ')neway annotation '(ample De)ining Parameter Properties "ith Annotations +he '(eb+aram annotation +he '(eb!esult annotation '(ample Generating WSDL '(ample

Developing a Service using JAX-WS ;ou can de(elop a ser(ice usin" one of t,o approachesD Start ,ith a WSDC contract and "enerate Ja(a objects to implement the ser(ice. Start ,ith a Ja(a object and ser(ice enable it usin" annotations.

*or ne, de(elopment the preferred path is to desi"n your ser(ices in WSDC and then "enerate the code 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 spend more time ,or#in" out the e act interface your ser(ice re3uires before you start codin". 0o,e(er$ there are many cases ,here you may need to ser(ice enable an e istin" application. While JAX-WS eases the process$ it does re3uire that you ma#e some chan"es to source code of your application. ;ou ,ill need to add annotations to the source. It also re3uires that you mi"rate your code to Ja(a @.?. WSDL First Development Esin" the WSDC first model of ser(ice de(elopment$ you start ,ith a WSDC document that defines the ser(ice you ,ish to implement. This WSDC document could be obtained from another de(eloper$ a system architect$ a EDDI re"istry$ or you could ,rite it yourself. The document must contain at least a fully specified lo"ical interface before you can be"in "eneratin" code from it.

-nce you ha(e a WSDC document$ the process for de(elopin" a JAX-WS ser(ice is three stepsD <. .enerate startin" point code. +. Implement the ser(ice7s operations. 1. 'ublish the implemented ser(ice. enerating the Starting !oint Code JAX-WS specifies a detailed mappin" from a ser(ice defined in WSDC to the Ja(a classes that ,ill implement that ser(ice. The lo"ical interface$ defined by the ,sdlDportType element$ is mapped to a ser(ice endpoint interface 6S/I8. Any comple types defined in the WSDC are mapped into Ja(a classes follo,in" the mappin" defined by the Ja(a Architecture for X&C 4indin" 6JAX48 specification. The endpoint defined by the ,sdlDser(ice element is also "enerated into a Ja(a class that is used by consumers to access endpoints implementin" the ser(ice. The #sdl2$ava command automates the "eneration of this code. It also pro(ides options for "eneratin" startin" point code for your implementation and an ant based ma#efile to build the application. #sdl2$ava pro(ides a number of ar"uments for controllin" the "enerated code. "unning #sdl2$ava ;ou can "enerate the code needed to de(elop your ser(ice usin" the follo,in" commandD ,sdl+ja(a -ant -impl -ser(er -d outputDir mySer(ice.,sdl The command does the follo,in"D The -ant ar"ument "enerates a Ant ma#efile$ called build. ml$ for your application. The -impl ar"ument "enerates a shell implementation class for each portType element in the WSDC document. The -ser(er ar"ument "enerates a simple main68 to launch your ser(ice as a stand alone application. The -d outputDir ar"ument tells #sdl2$ava to ,rite the "enerated code to a directory called outputDir. mySer(ice.,sdl is the WSDC document from ,hich code is "enerated.

enerated code Table< describes the files "enerated for creatin" a ser(ice. 'able ,enerated Classes +or a Service File portTypeName.ja(a serviceName.ja(a Description The S/I. This file contains the interface your ser(ice implements. ;ou should not edit this file. The endpoint. This file contains the Ja(a class your clients ,ill use to ma#e re3uests

on the ser(ice. The s#eleton implementation class. ;ou ,ill portTypeNameImpl.ja(a modify this file to implement your ser(ice. A basic ser(er main68 that allo,s you to portTypeNameFportTypeNameImpl'ortFSe deploy your ser(ice as a stand alone r(er.ja(a process. %mplementing the Service -nce the startin" point code is "enerated$ you must pro(ide the business lo"ic for each of the operations defined in the ser(ice7s interface. enerating the implementation code ;ou "enerate the implementation class for your ser(ice ,ith #sdl2$ava7s -impl fla". 'ip If your ser(ice7s contract included any custom types defined in X&C Schema$ you ,ill also need to ensure that the classes for the types are also "enerated and a(ailable. enerated code The ser(ice implementation code consists of t,o filesD portTypeName.java is the ser(ice interface6S/I8 for the ser(ice. portTypeNameImpl.ja(a is the class you ,ill use to implement the operations defined for the ser(ice.

%mplement the operation&s logic ;ou pro(ide the business lo"ic for your ser(ice7s operations by completin" the stub methods in portTypeNameImpl.ja(a. *or the most part$ you use standard Ja(a to implement the business lo"ic. If your ser(ice uses custom X&C Schema types$ you ,ill need to use the "enerated classes for each type to manipulate them. There are also some )X* specific A'Is that you can use to access some ad(anced features. (xample *or e ample$ an implementation class for a ser(ice that defined the operations say0i and greet-e may loo# li#e the follo,in"D %mplementation o+ the reeter Service pac#a"e demo.h,.ser(erG import or".apache.helloF,orldFsoapFhttp..reeterG Hja(a .j,s.WebSer(ice6port9ame I 5Soap'ort5$ ser(ice9ame I 5S-A'Ser(ice5$ tar"et9amespace I 5httpD22apache.or"2helloF,orldFsoapFhttp5$ endpointInterface I 5or".apache.helloF,orldFsoapFhttp..reeter58 public class .reeterImpl implements .reeter J

public Strin" "reet&e6Strin" me8 J System.out.println65/ ecutin" operation "reet&e58G System.out.println65&essa"e recei(edD 5 K me K 5Ln58G return 50ello 5 K meG M public Strin" say0i68 J System.out.println65/ ecutin" operation say0iLn58G return 54onjour5G M M Java First Development To create a ser(ice startin" from Ja(a you need to do the follo,in"D <. )reate a Ser(ice /ndpoint Interface 6S/I8 that defines the methods you ,ish to e pose as a ser(ice. 'ip ;ou can ,or# directly from a Ja(a class$ but ,or#in" from an interface is the recommended approach. Interfaces are better for sharin" ,ith the de(elopers ,ho ,ill be responsible for de(elopin" the applications consumin" your ser(ice. The interface is smaller and does not pro(ide any of the ser(ice7s implementation details. +. Add the re3uired annotations to your code. 1. .enerate the WSDC contract for your ser(ice. 'ip If you intend to use the S/I as the ser(ice7s contract$ it is not necessary to "enerate a WSDC contract :. 'ublish the ser(ice. Creating the S(% The ser(ice endpoint interface 6S/I8 is the piece of Ja(a code that is shared bet,een a ser(ice and the consumers that ma#e re3uests on it. When startin" ,ith a WSDC contract$ the S/I is "enerated by the code "enerators. 0o,e(er$ ,hen startin" from Ja(a$ it is the up to a de(eloper to create the S/I. There are t,o basic patterns for creatin" an S/ID .reen field de(elopment ;ou are de(elopin" a ne, ser(ice from the "round up. When startin" fresh$ it is best to start by creatin" the S/I first. ;ou can then distribute the S/I to any de(elopers that are responsible for implementin" the ser(ices and consumers that use the S/I. )ote The recommended ,ay to do "reen field ser(ice de(elopment is to start by creatin" a WSDC contract that defines the ser(ice and its interfaces. Ser(ice enablement In this pattern$ you typically ha(e an e istin" set of functionality that is

implemented as a Ja(a class and you ,ant to ser(ice enable it. This means that you ,ill need to do t,o thin"sD <. )reate an S/I that contains onl* the operations that are "oin" to be e posed as part of the ser(ice. +. &odify the e istin" Ja(a class so that it implements the S/I. )ote ;ou can add the JAX-WS annotations to a Ja(a class$ but that is not recommended. Writing the inter+ace The S/I is a standard Ja(a interface. It defines a set of methods that a class ,ill implement. It can also define a number of member fields and constants to ,hich the implementin" class has access. In the case of an S/I the methods defined are intended to be mapped to operations e posed by a ser(ice. The S/I corresponds to a wsdl:portType element. The methods defined by the S/I correspond to wsdl:operation elements in the wsdl:portType element. 'ip JAX-WS defines an annotation that allo,s you to specify methods that are not e posed as part of a ser(ice. 0o,e(er$ the best practice is to lea(e such methods out of the S/I. The belo, sho,s a simple S/I for a stoc# updatin" ser(ice. Simple S(% pac#a"e or".apache.c fG public interface Nuote%eporter J public Nuote "etNuote6Strin" tic#er8G M %mplementing the inter+ace 4ecause the S/I is a standard Ja(a interface$ the class that implements it is just a standard Ja(a class. If you started ,ith a Ja(a class you ,ill need to modify it to implement the interface. If you are startin" fresh$ the implementation class ,ill need to implement the S/I. The belo, sho,s a class for implementin" the abo(e interface. pac#a"e or".apache.c fG import ja(a.util.!G public class Stoc#Nuote%eporter implements Nuote%eporter J ... public Nuote "etNuote6Strin" tic#er8

J Nuote retOal I ne, Nuote68G retOal.setID6tic#er8G retOal.setOal64oard.chec#6tic#er88GP<Q Date retDate I ne, Date68G retOal.setTime6retDate.toStrin"688G return6retOal8G M

Annotating the Code JAX-WS relies on the annotation feature of Ja(a @. The JAX-WS annotations are used to specify the metadata used to map the S/I to a fully specified ser(ice definition. Amon" the information pro(ided in the annotations are the follo,in"D The tar"et namespace for the ser(ice. The name of the class used to hold the re3uest messa"e. The name of the class used to hold the response messa"e. If an operation is a one ,ay operation. The bindin" style the ser(ice uses. The name of the class used for any custom e ceptions. The namespaces under ,hich the types used by the ser(ice are defined.

"e.uired Annotations In order to create a ser(ice from Ja(a code you are only re3uired to add one annotation to your code. ;ou must add the HWebSer(ice68 annotation on both the S/I and the implementation class. The @WebService annotation The '(eb$ervice annotation is defined by the javax.jws.(eb$ervice interface and it is placed on an interface or a class that is intended to be used as a ser(ice. '(eb$ervice has the follo,in" propertiesD Description Specifies the name of the ser(ice interface. This property is mapped to the name attribute of the ,sdlDportType element that defines the name ser(ice7s interface in a WSDC contract. The default is to append 'ortType to the name of the implementation class. Specifies the tar"et namespace under ,hich the ser(ice is defined. If tar"et9amesp this property is not specified$ the tar"et namespace is deri(ed from ace the pac#a"e name. Specifies the name of the published ser(ice. This property is mapped to the name attribute of the ,sdlDser(ice element that defines the ser(ice9ame published ser(ice. The default is to use the name of the ser(ice7s implementation class. )ote- 9ot allo,ed on the S/I Specifies the E%I at ,hich the ser(ice7s WSDC contract is stored. The ,sdlCocation default is the E%I at ,hich the ser(ice is deployed. endpointInterf Specifies the full name of the S/I that the implementation class !ropert*

ace

port9ame

implements. This property is only used ,hen the attribute is used on a ser(ice implementation class. )ote- 9ot allo,ed on the S/I Specifies the name of the endpoint at ,hich the ser(ice is published. This property is mapped to the name attribute of the ,sdlDport element that specifies the endpoint details for a published ser(ice. The default is the append 'ort to the name of the ser(ice7s implementation class. )ote- 9ot allo,ed on the S/I

Annotating the SEI pac#a"e com.mycompany.demoG import ja(a .j,s.!G /WebService0name12.uote3pdater24 target)amespace12http-55cx+6apache6org24 #sdlLocation12http-55some#here6com5.uote(xampleService7#sdl28 public interface Nuote%eporter J public Nuote "etNuote6HWeb'aram6nameI5tic#er58 Strin" tic#er8G M The HWebSer(ice annotation abo(e does the follo,in"D

.. Specifies that the (alue of the name attribute of the ,sdlDportType element
definin" the ser(ice interface is 3uoteEpdater.

#. Specifies that the tar"et namespace of the ser(ice is httpD22c f.apache.or".


1. Specifies that the ser(ice ,ill use the pre-defined WSDC contract ,hich is published at httpD22some,here.com23uote/ ampleSer(iceR,sdl. Annotating the service implementation In addition to annotatin" the S/I ,ith the '(eb$ervice annotation$ you also ha(e to annotate the ser(ice implementation class ,ith the '(eb$ervice annotation. When addin" the annotation to the ser(ice implementation class you only need to specify the endpointInterface property. As sho,n in belo, the property needs to be set to the full name of the S/I. pac#a"e or".apache.c fG import ja(a .j,s.!G /WebService0endpoint%nter+ace12org6apache6cx+6.uote"eporter24 target)amespace12http-55cx+6apache6org24 port)ame12Stoc9:uote!ort24

service)ame12Stoc9:uote"eporter24 8 public class Stoc#Nuote%eporter implements Nuote%eporter J public Nuote "etNuote6Strin" tic#er8 J ... M M The @SOAPBin ing annotation The HS-A'4indin" annotation is defined by the ja(a .j,s.soap.S-A'4indin" interface. It pro(ides details about the S-A' bindin" used by the ser(ice ,hen it is deployed. If the HS-A'4indin" annotation is not specified$ a ser(ice is published usin" a ,rapped doc2literal S-A' bindin". ;ou can put the HS-A'4indin" annotation on the S/I and any of the S/I7s methods. When it is used on a method$ settin" of the method7s HS-A'4indin" annotation ta#e precedent. The follo,in" table sho,s the properties for the HS-A'4indin" annotation. Description Specifies the style of the S-A' messa"e. If %') style is specified$ each messa"e part ,ithin the S-A' body is a parameter or return (alue and ,ill appear inside a ,rapper element ,ithin the Style.D-)E&/9T soapDbody element. The messa"e parts ,ithin the style 6default8 ,rapper element correspond to operation Style.%') parameters and must appear in the same order as the parameters in the operation. If D-)E&/9T style is specified$ the contents of the S-A' body must be a (alid X&C document$ but its form is not as ti"htly constrained. Ese.CIT/%AC 6default8 Specifies ho, the data of the S-A' messa"e is use Ese./9)-D/D streamed. Specifies ho, the method parameters$ ,hich correspond to messa"e parts in a WSDC contract$ are placed into the S-A' messa"e body. A parameter style of 4A%/ means that each parameter is placed into the messa"e body as a 'arameterStyle.4A%/ parameterSt child element of the messa"e root. A parameter 'arameterStyle.W%A' yle style of W%A''/D means that all of the input '/D 6default8 parameters are ,rapped into a sin"le element on a re3uest messa"e and that all of the output parameters are ,rapped into a sin"le element in the response messa"e. If you set the style to %') you must use the W%A''/D parameter style. package org.eric.demo; !ropert* ;alues

import javax.jws.1; import javax.jws.soap.1; import javax.jws.soap.$)*+,inding.1; @WebService(name="quoteReporter") @SOAPBinding(style=Style RP!"#use=$se %&'(RA%) public interface uote!eporter " ... & The @Web!etho annotation

The HWeb&ethod annotation is defined by the ja(a .j,s.Web&ethod interface. It is placed on the methods in the S/I. The HWeb&ethod annotation pro(ides the information that is normally represented in the ,sdlDoperation element describin" the operation to ,hich the method is associated. The follo,in" table describes the properties of the '(eb-ethod annotation. !ropert* Description operation9a Specifies the (alue of the associated ,sdlDoperation element7s name. me The default (alue is the name of the method. Specifies the (alue of the soapAction attribute of the soapDoperation action element "enerated for the method. The default (alue is an empty strin". Specifies if the method should be e cluded from the ser(ice interface. e clude The default is false. The @"e#$estWrapper annotation The H%e3uestWrapper annotation is defined by the ja(a . ml.,s.%e3uestWrapper interface. It is placed on the methods in the S/I. As the name implies$ H%e3uestWrapper specifies the Ja(a class that implements the ,rapper bean for the method parameters that are included in the re3uest messa"e sent in a remote in(ocation. It is also used to specify the element names$ and namespaces$ used by the runtime ,hen marshallin" and unmarshallin" the re3uest messa"es. The follo,in" table describes the properties of the H%e3uestWrapper annotation. Description Specifies the local name of the ,rapper element in the X&C representation of the re3uest messa"e. The default (alue is the name local9ame of the method or the (alue of the HWeb&ethod annotation7s operation9ame property. tar"et9amesp Specifies the namespace under ,hich the X&C ,rapper element is ace defined. The default (alue is the tar"et namespace of the S/I. Specifies the full name of the Ja(a class that implements the ,rapper class9ame element. 'ip -nly the class9ame property is re3uired. !ropert*

The @"esponseWrapper annotation The H%esponseWrapper annotation is defined by the ja(a . ml.,s.%esponseWrapper interface. It is placed on the methods in the S/I. As the name implies$ H%esponseWrapper specifies the Ja(a class that implements the ,rapper bean for the method parameters that are included in the response messa"e sent in a remote in(ocation. It is also used to specify the element names$ and namespaces$ used by the runtime ,hen marshallin" and unmarshallin" the response messa"es. The follo,in" table describes the properties of the '!esponse(rapper annotation. Description Specifies the local name of the ,rapper element in the X&C representation of the response messa"e. The default (alue is the name local9ame of the method ,ith %esponse appended or the (alue of the HWeb&ethod annotation7s operation9ame property ,ith %esponse appended. tar"et9amesp Specifies the namespace under ,hich the X&C ,rapper element is ace defined. The default (alue is the tar"et namespace of the S/I. Specifies the full name of the Ja(a class that implements the ,rapper class9ame element. 'ip -nly the class9ame property is re3uired. The @WebFa$lt annotation The HWeb*ault annotation is defined by the ja(a . ml.,s.Web*ault interface. It is placed on e ceptions that are thro,n by your S/I. The HWeb*ault annotation is used to map the Ja(a e ception to a ,sdlDfault element. This information is used to marshall the e ceptions into a representation that can be processed by both the ser(ice and its consumers. The follo,in" table describes the properties of the '(eb/ault annotation. !ropert* Description name Specifies the local name of the fault element. tar"et9amesp Specifies the namespace under ,hich the fault element is defined. The ace default (alue is the tar"et namespace of the S/I. Specifies the full name of the Ja(a class that implements the fault9ame e ception. pac#a"e or".apache.c fG import ja(a .j,s.!G import ja(a . ml.,s.!G /WebService0name12.uote"eporter28 public interface Nuote%eporter J /Web<ethod0operation)ame12getStoc9:uote28 !ropert*

/"e.uestWrapper0target)amespace12http-55demo6m*compan*6com5t*pes24 class)ame12$ava6lang6String28 /"esponseWrapper0target)amespace12http-55demo6m*compan*6com5t*pes 24 class)ame12org6eric6demo6:uote28 public Nuote "etNuote6Strin" tic#er8G M

Java Web services- JAX= and JAX-WS in Axis2


The ori"inal Apache A is ,as based on the first Ja(a standard for Web ser(ices$ JAX%'). This turned out not to be a "reat approach$ because JAX-%') constrained the internal desi"n of the A is code and contributed to both performance issues and a lac# of fle ibility. JAX-%') also made some assumptions about the direction of Web ser(ices de(elopment that turned out to be ,ron". 4y the time the A is+ effort ,as started$ a replacement for JAX-%') ,as already in the ,or#s$ so A is+ ,as desi"ned to be fle ible enou"h to implement support for the replacement Web ser(ices standard on top of the base frame,or#. %ecent (ersions of A is+ ha(e implemented support for both the JAX4 +. Ja(a X&C data-bindin" standard and the JAX-WS +. Ja(a Web ser(ices standard that replaced JAX-%'). This article sho,s ho, to use JAX4 and JAX-WS ,ith A is+ and identifies some of the limitations of A is+7s current support for these standards.

JAX= in Axis2 A is+ implements support for JAX4 +. as one of the data-bindin" alternati(es you can choose ,hen "eneratin" code from a Web Ser(ices Description Can"ua"e 6WSDC8 ser(ice definition ,ith WSDC+Ja(a. 6See 5Ja(a Web Ser(icesD A is+ Data 4indin"5 for a discussion of the other main alternati(es.8 As ,ith most of the other alternati(es$ "eneratin" code from WSDC usin" JAX4 +. creates both a set of lin#a"e classes and a set of data model classes. The lin#a"e classes$ includin" a client-side stub and a ser(er-side messa"e recei(er$ interface bet,een your application code and A is+. The data model classes represent the actual messa"e data. JAX4 +. uses annotations in the data model classes to control ho, data is con(erted to and from X&C. The annotations approach allo,s you to use different JAX4 implementations at run time ,ithout needin" to chan"e your source code or recompile your classes. It7s up to the JAX4 implementation to access the annotation information from the data model classes and apply these annotations ,hen con(ertin" to and from X&C.

Using the CXF Servlet

The )X* ser(let$ ,hich acts as an adapter for the Web ser(ice endpoints. The )X* ser(let is the easiest method for deployin" Web ser(ices into a ser(let container. Deployed WA% file S Ser(ice pro(iders are deployed to the ser(let container in a Web Archi(e 6WA%8 file. The deployed WA% file containsD o the compiled code for the ser(ice pro(ider bein" deployed o o the WSDC file definin" the ser(ice the *use Ser(ices *rame,or# confi"uration file This file$ called c f-ser(let. ml$ is standard *use Ser(ices *rame,or# confi"uration file that defines all of the endpoints contained in the WA%. o the Web application deployment descriptor

All *use Ser(ices *rame,or# Web applications usin" the standard )X* ser(let need to load the or".apache.c f.transport.ser(let.)X*Ser(let class. )X* ser(let S The )X* ser(let is a standard ser(let pro(ided by *use Ser(ices *rame,or#. It acts as an adapter for Web ser(ice endpoints and is part of the *use Ser(ices *rame,or# runtime. The )X* ser(let is implemented by the or".apache.c f.transport.ser(let.)X*Ser(let class.

Deplo*ment steps To deploy a *use Ser(ices *rame,or# endpoint to a ser(let container you mustD

.. 4uild a WA% that contains your application and all the re3uired support files.
+. Deploy the WA% file to your ser(let container. =uilding a WA" To deploy your application to a ser(let container$ you must build a WA% file. The WA% file7s (2,-I3/ folder should include the follo,in"D c f-ser(let. ml S a *use Ser(ices *rame,or# confi"uration file specifyin" the endpoints that plu" into the )X* ser(let. When the )X* ser(let starts up$ it reads the jaxws:endpoint elements from this file$ and initialiTes a ser(ice endpoint for each one. See Ser(let confi"uration file for more information. ,eb. ml S a standard ,eb application file that instructs the ser(let container to load the org.apache.cxf.transport.servlet.45/$ervlet class. 'ip A reference (ersion of this file is contained in your InstallDir2etc directory. ;ou can use this reference copy ,ithout ma#in" chan"es to it. classes S a folder includin" your Web ser(ice implementation class and any other classes re3uired to support the implementation. ,sdl S a folder includin" the WSDC file that defines the ser(ice you are deployin". lib S a folder includin" any JA%s re3uired by your application.

Servlet con+iguration +ile The cxf-servlet.xml file is a *use Ser(ices *rame,or# confi"uration file that confi"ures the endpoints that plu" into the )X* ser(let. When the )X* ser(let starts up it reads the jaxws:endpoint elements in this file and initialiTes a ser(ice endpoint for each one. / ample =.< sho,s a simple cxf-servlet.xml file.

(xample >6,6 CXF Servlet Con+iguration File UR ml (ersionI5<.?5 encodin"I5ET*-A5RV Ubeans mlnsI5httpD22,,,.sprin"frame,or#.or"2schema2beans5 mlnsD siI5httpD22,,,.,1.or"2+??<2X&CSchema-instance mlnsDja ,sI5httpD22c f.apache.or"2ja ,s5 mlnsDsoapI5httpD22c f.apache.or"2bindin"s2soap5 siDschemaCocationI5 httpD22,,,.sprin"frame,or#.or"2schema2beans httpD22,,,.sprin"frame,or#.or"2schema2beans2sprin"-beans-+.?. sd httpD22c f.apache.or"2bindin"s2soap httpD22c f.apache.or"2schemas2confi"uration2soap. sd httpD22c f.apache.or"2ja ,s httpD22c f.apache.or"2schemas2ja ,s. sd5V Uja ,sDendpoint idI5helloF,orld5 implementorI5demo.h,.ser(er..reeterImpl5 ,sdlCocationI5W/4-I9*2,sdl2helloF,orld.,sdl5 addressI52helloF,orld5V Uja ,sDfeaturesV Ubean classI5or".apache.c f.feature.Co""in"*eature52V U2ja ,sDfeaturesV U2ja ,sDendpointV U2beansV

The code sho,n in / ample =.< is e plained as follo,sD

The Sprin" beans element is re3uired at the be"innin" of e(ery *use Ser(ices *rame,or# confi"uration file. It is the only Sprin" element that you need to be familiar ,ith. The jaxws:endpoint element defines a ser(ice pro(ider endpoint. The jaxws:endpoint element has the follo,in" attributesD id S Sets the endpoint id. implementor S Specifies the class implementin" the ser(ice. %mportant This class needs to be included in the WA%7s W/4I9*2classes folder. ,sdlCocation S Specifies the WSDC file that contains the ser(ice definition. %mportant The WSDC file location is relati(e to the WA%7s W/4I9*2,sdl folder. address S Specifies the address of the endpoint as defined in the ser(ice7s WSDC file that defines ser(ice that is bein" deployed.

ja ,sDfeatures S Defines features that can be added to your endpoint.

*or more information on confi"urin" a ja ,sDendpoint element$ see Esin" the ja ,sDendpoint /lement. Web application con+iguration ;ou must include a web.xml deployment descriptor file that instructs the ser(let container to load the )X* ser(let. / ample =.+ sho,s a web.xml file. It is not necessary to chan"e this file. A reference copy is located in the InstallDir6etc directory. (xample >626 A #eb6xml Deplo*ment Descriptor File UR ml (ersionI5<.?5 encodin"I5ET*-A5RV UWD-)T;'/ ,eb-app 'E4CI) 5-22Sun &icrosystems$ Inc.22DTD Web Application +.122/95 5httpD22ja(a.sun.com2dtd2,eb-appF+F1.dtd5V U,eb-appV Udisplay-nameVc fU2display-nameV UdescriptionVc fU2descriptionV User(letV User(let-nameVc fU2ser(let-nameV Udisplay-nameVc fU2display-nameV UdescriptionVApache )X* /ndpointU2descriptionV User(let-classVor".apache.c f.transport.ser(let.)X*Ser(letU2ser(let-classV Uload-on-startupV<U2load-on-startupV U2ser(letV User(let-mappin"V User(let-nameVc fU2ser(let-nameV Uurl-patternV2ser(ices2!U2url-patternV U2ser(let-mappin"V Usession-confi"V Usession-timeoutV=?U2session-timeoutV U2session-confi"V U2,eb-appV

-uil ing Clients o WSDL#Java generate Client o JAX-WS Pro(/ o JAX-WS Dispatch AP%s o Simple Fronten Client Pro(/ o D/namic Client

D*namicClientFactor* and JaxWsD*namicClientFactor*

)X* pro(ides t,o factory classes for dynamic classes. If your ser(ice is defined in terms of JAX-WS concepts$ you should use the Ja WsDynamic)lient*actory. If you do not ,ant or need JAX-WS semantics$ use the Dynamic)lient*actory. Ja WsDynamic)lient*actory dcf I Ja WsDynamic)lient*actory.ne,Instance68G )lient client I dcf.create)lient65echo.,sdl58G -bjectPQ res I client.in(o#e65echo5$ 5test echo58G System.out.println65/cho responseD 5 K resP?Q8G &any WSDCs ,ill ha(e more comple types thou"h. In this case the Ja WsDynamic)lient*actory ta#es care of "eneratin" Ja(a classes for these types. *or e ample$ ,e may ha(e a 'eople ser(ice ,hich #eeps trac# of people in an or"aniTation. In the sample belo, ,e create a 'erson object that ,as "enerated for us dynamically and send it to the ser(er usin" the add'erson operationD Ja WsDynamic)lient*actory dcf I Ja WsDynamic)lient*actory.ne,Instance68G )lient client I dcf.create)lient65people.,sdl5$ classCoader8G -bject person I Thread.currentThread68."et)onte t)lassCoader68.load)lass65com.acme.'erson58.ne,I nstance68G &ethod m I person."et)lass68."et&ethod65set9ame5$ Strin".class8G m.in(o#e6person$ 5Joe Schmoe58G client.in(o#e65add'erson5$ person8G The Ja WsDynamic)lient*actory sets the Thread conte t )lassCoader to a ne, )lassCoader that contains the classes for the "enerated types. If you need the ori"inal )lassCoader$ ma#e sure you sa(e it prior to callin" create)lient. ?elloWorld Ja WsDynamic)lient*actory dcf I Ja WsDynamic)lient*actory.newInstance68G 22)lient client I dcf.create)lient652,sdls20elloWorld.,sdl58G )lient client I dcf.create)lient65httpD22localhostDA?AA2)X*Tutorial20elloWorldR,sdl58G -bjectPQ res I client.in(o#e65say0i5$ 5test echo58G System.out.println65/cho responseD 5 K resP?Q8G StudentDetails Ja WsDynamic)lient*actory dcf I Ja WsDynamic)lient*actory.newInstance68G )lient client I dcf.create)lient65httpD22localhostDA?AA2)X*Tutorial2)han"eStudentR,sdl58G -bject student I Thread.currentThread68."et)onte t)lassCoader68.load)lass65com.student.Student58.n e,Instance68G &ethod method I student."et)lass68."et&ethod65set9ame5$ Strin".class8G method.in(o#e6student$ 5Tumuluri %a(i Kumar58G -bjectPQ res I client.in(o#e65chan"e9ame5$ student8G &ethod method< I student."et)lass68."et&ethod65"et9ame58G System.out.println65/cho responseD 5 K resP?Q8G System.out.println65/cho responseD 5 K method<.in(o#e6student88G

De(elopin" a Ser(ice usin" JAX-WS WSDC *irst De(elopment .eneratin" the Startin" 'oint )ode o %unnin" ,sdl+ja(a o .enerated code Implementin" the Ser(ice o .eneratin" the implementation code o .enerated code o Implement the operation7s lo"ic o / ample Developing a Service using JAX-WS WSDL First Development Esin" the WSDC first model of ser(ice de(elopment$ you start ,ith a WSDC document that defines the ser(ice you ,ish to implement. This WSDC document could be obtained from another de(eloper$ a system architect$ a EDDI re"istry$ or you could ,rite it yourself. The document must contain at least a fully specified lo"ical interface before you can be"in "eneratin" code from it. -nce you ha(e a WSDC document$ the process for de(elopin" a JAX-WS ser(ice is three stepsD <. .enerate startin" point code. +. Implement the ser(ice7s operations. 1. 'ublish the implemented ser(ice. JAX-WS specifies a detailed mappin" from a ser(ice defined in WSDC to the Ja(a classes that ,ill implement that ser(ice. The lo"ical interface$ defined by the #sdl-port'*pe element$ is mapped to a ser(ice endpoint interface 6S/I8. Any comple types defined in the WSDC are mapped into Ja(a classes follo,in" the mappin" defined by the Java Architecture +or X<L =inding 0JAX=8 speci+ication. The endpoint defined by the #sdl-service element is also "enerated into a Ja(a class that is used by consumers to access endpoints implementin" the ser(ice. The #sdl2$ava command automates the "eneration of this code. It also pro(ides options for "eneratin" startin" point code for your implementation and an ant based ma#efile to build the application. #sdl2$ava pro(ides a number of ar"uments for controllin" the "enerated code. ;ou can "enerate the code needed to de(elop your ser(ice usin" the follo,in" commandD ,sdl+ja(a -ant -impl -ser(er -d outputDir mySer(ice.,sdl The command does the follo,in"D The -ant ar"ument "enerates a Ant ma#efile$ called build. ml$ for your application.

The -impl ar"ument "enerates a shell implementation class for each portType element in the WSDC document. The -ser(er ar"ument "enerates a simple main68 to launch your ser(ice as a stand alone application. The -d outputDir ar"ument tells #sdl2$ava to ,rite the "enerated code to a directory called outputDir. mySer(ice.,sdl is the WSDC document from ,hich code is "enerated.

enerated code Table< describes the files "enerated for creatin" a ser(ice. 'able ,enerated Classes +or a Service File

Description The S/I. This file contains the interface portTypeName.ja(a your ser(ice implements. ;ou should not edit this file. The endpoint. This file contains the Ja(a serviceName.ja(a class your clients ,ill use to ma#e re3uests on the ser(ice. The s#eleton implementation class. ;ou ,ill portTypeNameImpl.ja(a modify this file to implement your ser(ice. A basic ser(er main68 that allo,s you to portTypeNameFportTypeNameImpl'ortFSe deploy your ser(ice as a stand alone r(er.ja(a process. %mplementing the Service -nce the startin" point code is "enerated$ you must pro(ide the business lo"ic for each of the operations defined in the ser(ice7s interface. enerating the implementation code ;ou "enerate the implementation class for your ser(ice ,ith #sdl2$ava7s -impl fla". enerated code The ser(ice implementation code consists of t,o filesD portTypeName.java is the ser(ice interface6S/I8 for the ser(ice. portTypeNameImpl.java is the class you ,ill use to implement the operations defined for the ser(ice.

%mplement the operation&s logic ;ou pro(ide the business lo"ic for your ser(ice7s operations by completin" the stub methods in portTypeNameImpl.java. *or the most part$ you use standard Ja(a to implement the business lo"ic. If your ser(ice uses custom X&C Schema types$ you ,ill need to use the "enerated classes for each type to manipulate them. There are also some )X* specific A'Is that you can use to access some ad(anced features.

Java First Development To create a ser(ice startin" from Ja(a you need to do the follo,in"D <. )reate a Ser(ice /ndpoint Interface 6S/I8 that defines the methods you ,ish to e pose as a ser(ice. 'ip ;ou can ,or# directly from a Ja(a class$ but ,or#in" from an interface is the recommended approach. Interfaces are better for sharin" ,ith the de(elopers ,ho ,ill be responsible for de(elopin" the applications consumin" your ser(ice. The interface is smaller and does not pro(ide any of the ser(ice7s implementation details. +. Add the re3uired annotations to your code. 1. .enerate the WSDC contract for your ser(ice. 'ip If you intend to use the S/I as the ser(ice7s contract$ it is not necessary to "enerate a WSDC contract :. 'ublish the ser(ice. Creating the S(% The ser(ice endpoint interface 6S/I8 is the piece of Ja(a code that is shared bet,een a ser(ice and the consumers that ma#e re3uests on it. When startin" ,ith a WSDC contract$ the S/I is "enerated by the code "enerators. 0o,e(er$ ,hen startin" from Ja(a$ it is the up to a de(eloper to create the S/I. There are t,o basic patterns for creatin" an S/ID .reen field de(elopment ;ou are de(elopin" a ne, ser(ice from the "round up. When startin" fresh$ it is best to start by creatin" the S/I first. ;ou can then distribute the S/I to any de(elopers that are responsible for implementin" the ser(ices and consumers that use the S/I. )ote The recommended ,ay to do "reen field ser(ice de(elopment is to start by creatin" a WSDC contract that defines the ser(ice and its interfaces. Ser(ice enablement In this pattern$ you typically ha(e an e istin" set of functionality that is implemented as a Ja(a class and you ,ant to ser(ice enable it. This means that you ,ill need to do t,o thin"sD <. )reate an S/I that contains onl* the operations that are "oin" to be e posed as part of the ser(ice. +. &odify the e istin" Ja(a class so that it implements the S/I. )ote ;ou can add the JAX-WS annotations to a Ja(a class$ but that is not

recommended. Writing the inter+ace The S/I is a standard Ja(a interface. It defines a set of methods that a class ,ill implement. It can also define a number of member fields and constants to ,hich the implementin" class has access. In the case of an S/I the methods defined are intended to be mapped to operations e posed by a ser(ice. The S/I corresponds to a wsdl:portType element. The methods defined by the S/I correspond to wsdl:operation elements in the wsdl:portType element. 'ip JAX-WS defines an annotation that allo,s you to specify methods that are not e posed as part of a ser(ice. 0o,e(er$ the best practice is to lea(e such methods out of the S/I. The belo, sho,s a simple S/I for a stoc# updatin" ser(ice. Simple S(% pac#a"e or".apache.c fG public interface Nuote%eporter J public Nuote "etNuote6Strin" tic#er8G M %mplementing the inter+ace 4ecause the S/I is a standard Ja(a interface$ the class that implements it is just a standard Ja(a class. If you started ,ith a Ja(a class you ,ill need to modify it to implement the interface. If you are startin" fresh$ the implementation class ,ill need to implement the S/I. The belo, sho,s a class for implementin" the abo(e interface. %mplementation +or S(% pac#a"e or".apache.c fG import ja(a.util.!G public class Stoc#Nuote%eporter implements Nuote%eporter J ... public Nuote "etNuote6Strin" tic#er8 J Nuote retOal I ne, Nuote68G retOal.setID6tic#er8G retOal.setOal64oard.chec#6tic#er88GP<Q Date retDate I ne, Date68G retOal.setTime6retDate.toStrin"688G return6retOal8G

M M Annotating the Code JAX-WS relies on the annotation feature of Ja(a @. The JAX-WS annotations are used to specify the metadata used to map the S/I to a fully specified ser(ice definition. Amon" the information pro(ided in the annotations are the follo,in"D The tar"et namespace for the ser(ice. The name of the class used to hold the re3uest messa"e. The name of the class used to hold the response messa"e. If an operation is a one ,ay operation. The bindin" style the ser(ice uses. The name of the class used for any custom e ceptions. The namespaces under ,hich the types used by the ser(ice are defined. 'ip &ost of the annotations ha(e sensible defaults and do not need to be specified. 0o,e(er$ the more information you pro(ide in the annotations$ the better defined your ser(ice definition. A solid ser(ice definition increases the li#ely hood that all parts of a distributed application ,ill ,or# to"ether. "e.uired Annotations In order to create a ser(ice from Ja(a code you are only re3uired to add one annotation to your code. ;ou must add the HWebSer(ice68 annotation on both the S/I and the implementation class. The @WebService annotation The '(eb$ervice annotation is defined by the javax.jws.(eb$ervice interface and it is placed on an interface or a class that is intended to be used as a ser(ice. '(eb$ervice has the follo,in" propertiesD Description Specifies the name of the ser(ice interface. This property is mapped to the name attribute of the ,sdlDportType element that defines the name ser(ice7s interface in a WSDC contract. The default is to append 'ortType to the name of the implementation class. Specifies the tar"et namespace under ,hich the ser(ice is defined. If tar"et9amesp this property is not specified$ the tar"et namespace is deri(ed from ace the pac#a"e name. Specifies the name of the published ser(ice. This property is mapped to the name attribute of the ,sdlDser(ice element that defines the ser(ice9ame published ser(ice. The default is to use the name of the ser(ice7s implementation class. )ote- 9ot allo,ed on the S/I Specifies the E%I at ,hich the ser(ice7s WSDC contract is stored. The ,sdlCocation default is the E%I at ,hich the ser(ice is deployed. endpointInterf Specifies the full name of the S/I that the implementation class ace implements. This property is only used ,hen the attribute is used on a !ropert*

port9ame

ser(ice implementation class. )ote- 9ot allo,ed on the S/I Specifies the name of the endpoint at ,hich the ser(ice is published. This property is mapped to the name attribute of the ,sdlDport element that specifies the endpoint details for a published ser(ice. The default is the append 'ort to the name of the ser(ice7s implementation class. )ote- 9ot allo,ed on the S/I 'ip ;ou do not need to pro(ide (alues for any of the HWebSer(ice annotation7s properties. 0o,e(er$ it is recommended that you pro(ide as much information as you can.

Annotating the SEI The S/I re3uires that you add the HWebSer(ice annotation. Since the S/I is the contract that defines the ser(ice$ you should specify as much detail as you can about the ser(ice in the HWebSer(ice annotation7s properties. The code belo, sho,s the interface defined abo(e ,ith the '(eb$ervice annotation. %nter+ace #ith the /WebService Annotation pac#a"e com.mycompany.demoG import ja(a .j,s.!G HWebSer(ice6nameI53uoteEpdater5$ tar"et9amespaceI5httpD22c f.apache.or"5$ ,sdlCocationI5httpD22some,here.com23uote/ ampleSer(iceR,sdl58 public interface Nuote%eporter J public Nuote "etNuote6HWeb'aram6nameI5tic#er58 Strin" tic#er8G M The HWebSer(ice annotation abo(e does the follo,in"D

.. Specifies that the (alue of the name attribute of the ,sdlDportType element
definin" the ser(ice interface is 3uoteEpdater.

#. Specifies that the tar"et namespace of the ser(ice is httpD22c f.apache.or". 0. Specifies that the ser(ice ,ill use the pre-defined WSDC contract ,hich is
published at httpD22some,here.com23uote/ ampleSer(iceR,sdl. The HWeb'aram annotation is necessary as ja(a interfaces do not store the 'arameter name in the .class file. So if you lea(e out the annotation your parameter ,ill be named ar"?. Annotating the service implementation In addition to annotatin" the S/I ,ith the '(eb$ervice annotation$ you also ha(e to annotate the ser(ice implementation class ,ith the '(eb$ervice annotation. When addin" the annotation to the ser(ice implementation class you only need to specify the endpointInterface property. As sho,n in belo, the property needs to be set to the full name of the S/I.

Annotated Service %mplementation Class pac#a"e or".apache.c fG import ja(a .j,s.!G HWebSer(ice6endpointInterfaceI5or".apache.c f.3uote%eporter5$ tar"et9amespaceI5httpD22c f.apache.or"5$ port9ameI5Stoc#Nuote'ort5$ ser(ice9ameI5Stoc#Nuote%eporter5$ 8 public class Stoc#Nuote%eporter implements Nuote%eporter J public Nuote "etNuote6Strin" tic#er8 J ... M M @ptional Annotations While the '(eb$ervice annotation is sufficient for ser(ice enablin" a Ja(a interface or a Ja(a class$ it does not pro(ide a lot of information about ho, the ser(ice ,ill be e posed as an endpoint. The JAX-WS pro"rammin" model uses a number of optional annotations for addin" details about your ser(ice$ such as the bindin" it uses$ to the Ja(a code. ;ou add these annotations to the ser(ice7s S/I. 'ip The more details you pro(ide in the S/I$ the easier it ,ill be for de(elopers to implement applications that can use the functionality it defines. It ,ill also pro(ide for better "enerated WSDC contracts. De%ining the Bin ing Properties &ith Annotations If you are usin" a S-A' bindin" for your ser(ice$ you can use JAX-WS annotations to specify a number of the bindin"s properties. These properties correspond directly to the properties you can specify in a ser(ice7s WSDC contract. The @SOAPBin ing annotation The HS-A'4indin" annotation is defined by the ja(a .j,s.soap.S-A'4indin" interface. It pro(ides details about the S-A' bindin" used by the ser(ice ,hen it is deployed. If the HS-A'4indin" annotation is not specified$ a ser(ice is published usin" a ,rapped doc2literal S-A' bindin". ;ou can put the HS-A'4indin" annotation on the S/I and any of the S/I7s methods. When it is used on a method$ settin" of the method7s HS-A'4indin" annotation ta#e precedent. The follo,in" table sho,s the properties for the HS-A'4indin" annotation. !ropert* style ;alues Style.D-)E&/9T 6default8 Description Specifies the style of the S-A' messa"e. If %') style is specified$ each messa"e part ,ithin the

S-A' body is a parameter or return (alue and ,ill appear inside a ,rapper element ,ithin the soapDbody element. The messa"e parts ,ithin the ,rapper element correspond to operation Style.%') parameters and must appear in the same order as the parameters in the operation. If D-)E&/9T style is specified$ the contents of the S-A' body must be a (alid X&C document$ but its form is not as ti"htly constrained. Ese.CIT/%AC 6default8 Specifies ho, the data of the S-A' messa"e is use Ese./9)-D/D streamed. Specifies ho, the method parameters$ ,hich correspond to messa"e parts in a WSDC contract$ are placed into the S-A' messa"e body. A parameter style of 4A%/ means that each parameter is placed into the messa"e body as a 'arameterStyle.4A%/ parameterSt child element of the messa"e root. A parameter 'arameterStyle.W%A' yle style of W%A''/D means that all of the input '/D 6default8 parameters are ,rapped into a sin"le element on a re3uest messa"e and that all of the output parameters are ,rapped into a sin"le element in the response messa"e. If you set the style to %') you must use the W%A''/D parameter style. An S/I that uses rpc2literal S-A' messa"es is as follo,sD Speci+*ing an "!C5L%'("AL S@A! =inding pac#a"e or".eric.demoG import ja(a .j,s.!G import ja(a .j,s.soap.!G import ja(a .j,s.soap.S-A'4indin".!G HWebSer(ice6nameI53uote%eporter58 HS-A'4indin"6styleIStyle.%')$ useIEse.CIT/%AC8 public interface Nuote%eporter J ... M De%ining Operation Properties &ith Annotations When the runtime maps your Ja(a method definitions into X&C operation definitions it fills in details such asD ,hat the e chan"ed messa"es loo# li#e in X&C. if the messa"e can be optimiTed as a one ,ay messa"e. the namespaces ,here the messa"es are defined. annotation

The @Web!etho

The HWeb&ethod annotation is defined by the ja(a .j,s.Web&ethod interface. It is placed on the methods in the S/I. The HWeb&ethod annotation pro(ides the

information that is normally represented in the ,sdlDoperation element describin" the operation to ,hich the method is associated. The follo,in" table describes the properties of the '(eb-ethod annotation. !ropert* Description operation9a Specifies the (alue of the associated ,sdlDoperation element7s name. me The default (alue is the name of the method. Specifies the (alue of the soapAction attribute of the soapDoperation action element "enerated for the method. The default (alue is an empty strin". Specifies if the method should be e cluded from the ser(ice interface. e clude The default is false. The @"e#$estWrapper annotation The H%e3uestWrapper annotation is defined by the ja(a . ml.,s.%e3uestWrapper interface. It is placed on the methods in the S/I. As the name implies$ H%e3uestWrapper specifies the Ja(a class that implements the ,rapper bean for the method parameters that are included in the re3uest messa"e sent in a remote in(ocation. It is also used to specify the element names$ and namespaces$ used by the runtime ,hen marshallin" and unmarshallin" the re3uest messa"es. The follo,in" table describes the properties of the H%e3uestWrapper annotation. Description Specifies the local name of the ,rapper element in the X&C representation of the re3uest messa"e. The default (alue is the name local9ame of the method or the (alue of the HWeb&ethod annotation7s operation9ame property. tar"et9amesp Specifies the namespace under ,hich the X&C ,rapper element is ace defined. The default (alue is the tar"et namespace of the S/I. Specifies the full name of the Ja(a class that implements the ,rapper class9ame element. 'ip -nly the class9ame property is re3uired. The @"esponseWrapper annotation The H%esponseWrapper annotation is defined by the ja(a . ml.,s.%esponseWrapper interface. It is placed on the methods in the S/I. As the name implies$ H%esponseWrapper specifies the Ja(a class that implements the ,rapper bean for the method parameters that are included in the response messa"e sent in a remote in(ocation. It is also used to specify the element names$ and namespaces$ used by the runtime ,hen marshallin" and unmarshallin" the response messa"es. The follo,in" table describes the properties of the '!esponse(rapper annotation. !ropert* local9ame Description Specifies the local name of the ,rapper element in the X&C representation of the response messa"e. The default (alue is the name of the method ,ith %esponse appended or the (alue of the !ropert*

HWeb&ethod annotation7s operation9ame property ,ith %esponse appended. tar"et9amesp Specifies the namespace under ,hich the X&C ,rapper element is ace defined. The default (alue is the tar"et namespace of the S/I. Specifies the full name of the Ja(a class that implements the ,rapper class9ame element. 'ip -nly the class9ame property is re3uired. The @WebFa$lt annotation The HWeb*ault annotation is defined by the ja(a . ml.,s.Web*ault interface. It is placed on e ceptions that are thro,n by your S/I. The HWeb*ault annotation is used to map the Ja(a e ception to a ,sdlDfault element. This information is used to marshall the e ceptions into a representation that can be processed by both the ser(ice and its consumers. The follo,in" table describes the properties of the '(eb/ault annotation. !ropert* Description name Specifies the local name of the fault element. tar"et9amespa Specifies the namespace under ,hich the fault element is defined. ce The default (alue is the tar"et namespace of the S/I. Specifies the full name of the Ja(a class that implements the fault9ame e ception. %mportant The name property is re3uired. *i &eD fault9ame is defined as bean9ame by the Sun Ja(a // @ SDK at httpD22ja(a.sun.com2ja(aee2@2docs2api2ja(a 2 ml2,s2Web*ault.html. The @One&a' annotation The H-ne,ay annotation is defined by the ja(a .j,s.-ne,ay interface. It is placed on the methods in the S/I that ,ill not re3uire a response from the ser(ice. The H-ne,ay annotation tells the run time that it can optimiTe the e ecution of the method by not ,aitin" for a response and not reser(in" any resources to process a response. E(ample The belo, sho,s an S/I ,hose methods are annotated. S(% #ith Annotated <ethods pac#a"e or".apache.c fG import ja(a .j,s.!G import ja(a . ml.,s.!G HWebSer(ice6nameI53uote%eporter58 public interface Nuote%eporter J

HWeb&ethod6operation9ameI5"etStoc#Nuote58 H%e3uestWrapper6tar"et9amespaceI5httpD22demo.mycompany.com2types5$ class9ameI5ja(a.lan".Strin"58 H%esponseWrapper6tar"et9amespaceI5httpD22demo.mycompany.com2types5$ class9ameI5or".eric.demo.Nuote58 public Nuote "etNuote6Strin" tic#er8G

De%ining Parameter Properties &ith Annotations The method parameters in the S/I correspond to the ,sdlDmessa"e elements and their ,sdlDpart elements. JAX-WS pro(ides annotations that allo, you to describe the ,sdlDpart elements that are "enerated for the method parameters. The @WebParam annotation The HWeb'aram annotation is defined by the ja(a .j,s.Web'aram interface. It is placed on the parameters on the methods defined in the S/I. The HWeb'aram annotation allo,s you to specify the direction of the parameter$ if the parameter ,ill be placed in the S-A' header$ and other properties of the "enerated ,sdlDpart. The follo,in" table describes the properties of the '(eb+aram annotation. !ropert* ;alues Description Specifies the name of the parameter as it appears in the WSDC. *or %') bindin"s$ this is name of the ,sdlDpart representin" the parameter. *or document bindin"s$ this is the local name of the X&C element representin" the parameter. 'er the JAX-WS specification$ the default is argN$ ,here N is replaced ,ith the Tero-based ar"ument inde 6i.e.$ arg0$ arg1$ etc.8 Specifies the namespace for the parameter. It is only used ,ith document bindin"s ,here the parameter maps to an X&C element. The defaults is to use the ser(ice7s namespace.

name

tar"et9amesp ace

mode

header part9ame

&ode.I9 6default8 &ode.-ET Specifies the direction of the parameter. &ode.I9-E T false Specifies if the parameter is passed as part of the S-A' 6default8 header. true Specifies the (alue of the name attribute of the ,sdlDpart element for the parameter ,hen the bindin" is document.

The @Web"es$lt annotation The HWeb%esult annotation is defined by the ja(a .j,s.Web%esult interface. It is placed on the methods defined in the S/I. The HWeb%esult annotation allo,s you to specify the properties of the "enerated ,sdlDpart that is "enerated for the method7s return (alue.

The follo,in" table describes the properties of the '(eb!esult annotation. Description Specifies the name of the return (alue as it appears in the WSDC. *or %') bindin"s$ this is name of the ,sdlDpart representin" the return name (alue. *or document bindin"s$ this is the local name of the X&C element representin" the return (alue. The default (alue is return. Specifies the namespace for the return (alue. It is only used ,ith tar"et9amesp document bindin"s ,here the return (alue maps to an X&C element. ace The defaults is to use the ser(ice7s namespace. header Specifies if the return (alue is passed as part of the S-A' header. Specifies the (alue of the name attribute of the ,sdlDpart element for part9ame the return (alue ,hen the bindin" is document. E(ample The ne t e ample sho,s an S/I that is fully annotated. Full* Annotated S(% pac#a"e or".apache.c fG import import import import import ja(a ja(a ja(a ja(a ja(a .j,s.!G . ml.,s.!G .j,s.soap.!G .j,s.soap.S-A'4indin".!G .j,s.Web'aram.!G !ropert*

HWebSer(ice6nameI53uote%eporter58 HS-A'4indin"6styleIStyle.%')$ useIEse.CIT/%AC8 public interface Nuote%eporter J HWeb&ethod6operation9ameI5"etStoc#Nuote58 H%e3uestWrapper6tar"et9amespaceI5httpD22demo.mycompany.com2types5$ class9ameI5ja(a.lan".Strin"58 H%esponseWrapper6tar"et9amespaceI5httpD22demo.mycompany.com2types5$ class9ameI5or".eric.demo.Nuote58 HWeb%esult6tar"et9amespaceI5httpD22demo.mycompany.com2types5$ nameI5updatedNuote58 public Nuote "etNuote6 HWeb'aram6tar"et9amespaceI5httpD22demo.mycompany.com2types5$ nameI5stoc#Tic#er5$ modeI&ode.I98 Strin" tic#er 8G M enerating WSDL -nce you ha(e annotated your code$ you can "enerate a WSDC contract for your ser(ice usin" the $ava2#sdl command.

(xample The ne t e ample sho,s the WSDC contract "enerated for the S/I sho,n abo(eD enerated WSDL +rom an S(% UR ml (ersionI5<.?5 encodin"I5ET*-A5RV U,sdlDdefinitions tar"et9amespaceI5httpD22demo.eric.or"25 mlnsDtnsI5httpD22demo.eric.or"25 mlnsDns<I55 mlnsD sdI5httpD22,,,.,1.or"2+??<2X&CSchema5 mlnsDns+I5httpD22demo.eric.or"2types5 mlnsDsoapI5httpD22schemas. mlsoap.or"2,sdl2soap25 mlnsD,sdlI5httpD22schemas. mlsoap.or"2,sdl25V U,sdlDtypesV U sdDschemaV U sDcomple Type nameI53uote5V U sDse3uenceV U sDelement nameI5ID5 typeI5 sDstrin"5 min-ccursI5?52V U sDelement nameI5time5 typeI5 sDstrin"5 min-ccursI5?52V U sDelement nameI5(al5 typeI5 sDfloat52V U2 sDse3uenceV U2 sDcomple TypeV U2 sdDschemaV U2,sdlDtypesV U,sdlDmessa"e nameI5"etStoc#Nuote5V U,sdlDpart nameI5stoc#Tic#er5 typeI5 sdDstrin"5V U2,sdlDpartV U2,sdlDmessa"eV U,sdlDmessa"e nameI5"etStoc#Nuote%esponse5V U,sdlDpart nameI5updatedNuote5 typeI5tnsD3uote5V U2,sdlDpartV U2,sdlDmessa"eV U,sdlDportType nameI53uote%eporter5V U,sdlDoperation nameI5"etStoc#Nuote5V U,sdlDinput nameI5"etNuote5 messa"eI5tnsD"etStoc#Nuote5V U2,sdlDinputV U,sdlDoutput nameI5"etNuote%esponse5 messa"eI5tnsD"etStoc#Nuote%esponse5V U2,sdlDoutputV U2,sdlDoperationV U2,sdlDportTypeV U,sdlDbindin" nameI53uote%eporter4indin"5 typeI5tnsD3uote%eporter5V UsoapDbindin" styleI5rpc5 transportI5httpD22schemas. mlsoap.or"2soap2http52V U,sdlDoperation nameI5"etStoc#Nuote5V UsoapDoperation styleI5rpc52V U,sdlDinput nameI5"etNuote5V UsoapDbody useI5literal52V U2,sdlDinputV U,sdlDoutput nameI5"etNuote%esponse5V UsoapDbody useI5literal52V U2,sdlDoutputV U2,sdlDoperationV U2,sdlDbindin"V U,sdlDser(ice nameI53uote%eporterSer(ice5V U,sdlDport nameI53uote%eporter'ort5 bindin"I5tnsD3uote%eporter4indin"5V

UsoapDaddress locationI5httpD22localhostDB???23uote%eporterSer(ice52V U2,sdlDportV U2,sdlDser(iceV U2,sdlDdefinitionsV

CXF @vervie#

JAX-WS Support )X* implements the JAX-WS A'Is ,hich ma#e buildin" ,eb ser(ices easy. JAX-WS encompasses many different areasD .eneratin" WSDC from Ja(a classes and "eneratin" Ja(a classes from WSDC 'ro(ider A'I ,hich allo,s you to create simple messa"in" recei(in" ser(er endpoints Dispatch A'I ,hich allo,s you to send ra, X&C messa"es to ser(er endpoints

Spring %ntegration Sprin" is a first class citiTen ,ith Apache )X*. )X* supports the Sprin" +.? X&C synta $ ma#in" it tri(ial to declare endpoints ,hich are bac#ed by Sprin" and inject clients into your application. Aegis Databinding Ae"is Databindin" 6+.?. 8 is our o,n databindin" library that ma#es de(elopment of code-first ,eb ser(ices incredibly easy. Enli#e JAX4$ you don7t need annotations at all. It also ,or#s correctly ,ith a (ariety of datatypes such as Cists$ &aps$ Dates$ etc. ri"ht out of the bo . If you7re buildin" a prototype ,eb ser(ices that7s really in(aluable as it means you ha(e to do (ery little ,or# to "et up and runnin" 6and one of the primary reasons X*ire ,as started a ,hile bac#8 WS-A Support

)X* supports a (ariety of ,eb ser(ice specifications includin" WS-Addressin"$ WS'olicy$ WS-%eliable&essa"in" and WS-Security. 'ransports )X* ,or#s ,ith many different transports. )urrently )X* includes support for 0TT'$ J&S$ and Cocal 6that is$ 5in-JO&58 transports. The local transport is uni3ue in that it ,ill not ,or# across machines$ but simply sends messa"es in memory. ;ou can also confi"ure the local transport to a(oid serialiTation by usin" the -bject bindin" or the colocation feature if desired. ;ou can also ,rite your o,n transport. =indings 4indin"s map a particular ser(ice7s messa"es to a particular protocol. )X* includes support for se(eral different bindin"s. The S-A' bindin"$ ,hich is the default$ maps messa"es to S-A' and can be used ,ith the (arious WS-! modules inside )X*. The 'ure X&C bindin" a(oids serialiTation of a S-A' en(elope and just sends a ra, X&C messa"e. There is also an 0TT' 4indin" ,hich maps a ser(ice to 0TT' usin" %/STful semantics.

<essage %nterception and <odi+ication &any times you may ,ant to pro(ide functionality for your application that ,or#s at a lo, le(el ,ith X&C messa"es. This commonly occurs throu"h functionality referred to as 0andlers or Interceptors. 0andlers2Interceptors are useful forD 'erformin" authentication based on 0eaders 'rocessin" custom headers Transformin" a messa"e 6i.e. (ia XSCT or .Xip8 %edirectin" a messa"e .ettin" access to the ra, I2- or X&C stream

JA)*WS +an lers If you are usin" the JAX-WS frontend$ JAX-WS supports the concept of lo"ical and protocol handlers. 'rotocol handlers allo, you to manipulate the messa"e in its ra,$ often X&C-based$ form - i.e. a SAAJ S-A'&essa"e. Co"ical handlers allo, you to manipulate the messa"e after its already been bound from the protocol to the JAX4 object that your ser(ice ,ill recei(e. See this article to learn more about JAX-WS handlers. 'ransmitting =inar* Data )X* pro(ides facilities to transmit binary data efficiently (ia a standard called &T-&. 9ormally binary data inside an X&C messa"e must be 4ase=: encoded. This results in processin" o(erhead and increases messa"e siTe by 1?Y. If you use &T-&$ )X* ,ill send2recei(e &I&/ messa"es ,ith the messa"e stored as a &I&/ attachment$

just li#e email. This results in much more efficient communication and allo,s you to transmit messa"es much lar"er than memory. WS-A )X* pro(ides support for a (ariety of WS-! specifications. WS-Addressin" WS-'olicy WS-Security WS-%eliable&essa"in"

)X* pro(ides you ,ith many options to build ser(ices. This "uide is meant to "i(e you a 3uic# o(er(ie, of those options and help you orient yourself 3uic#ly ,ith )X*. Different Types -f Ser(ices JAX-WS Annotated Ser(ices from Ja(a JAX-WS Annotated Ser(ices from WSDC JAX-WS 'ro(iders Ja(ascript

Di++erent '*pes o+ Services )X* support three major types of ser(icesD S-A' - this pa"e summariTes the options for creatin" S-A' ser(ices. %/ST-ful - %/ST support is described here. )-%4A

JAX-WS Annotated Services +rom Java The JAX-WS A'Is include a set of annotations ,hich allo, you to build ser(ices usin" annotated classes. These ser(ices are based on a sin"le class ,hich contains a set of operations. 0ere7s a simple e ampleD HWebSer(ice public class 0ello J public Strin" say0i6Strin" name8 J return 50ello 5 K nameG M M JAX-WS includes many more annotations as ,ell such asD

HWeb&ethod - allo,s you to customiTe the operation name$ e clude the operation from inclusion in the ser(ice$ etc HWeb'aram - allo,s you to customiTe a parameter7s name$ namespace$ direction 6I9 or -ET8$ etc HWeb%esult - allo,s you to customiTe the return (alue of the ,eb ser(ice call

Data is marshalled from X&C to Ja(a and (ice (ersa (ia the JAX4 data-bindin". Ser(ices are publish (ia one of t,o meansD The JAX-WS standard /ndpoint A'Is )X*7s X&C confi"uration format - i.e. Uja ,sDendpoint ... 2V

&ore InformationD A simple JAX-WS ser(ice$ De(elopin" a JAX-WS Ser(ice 6"oes into much more depth8$ Writin" a ser(ice ,ith Sprin" JAX-WS Annotated Services +rom WSDL If you ha(e e istin" WSDCs for your ser(ice or ,ish to ,rite your WSDC first and then "enerate classes$ )X* has many tools to help you do this. The WSDC+Ja(a tool ,ill "enerate a JAX-WS annotated ser(ice and ser(er stub from your WSDC. ;ou can run it one of three ,aysD The command line The &a(en 'lu"in With the WSDC+Ja(a A'I

9ote that )X* "enerally restricts WSDC support to WSI-4'$ not the full WSDC <.< specification. There is also a Simple *rontend that allo,s you to create ser(ices ,ithout usa"e of Ja(a annotations$ usin" X&C confi"uration files instead. JAX-WS !roviders JAX-WS 'ro(iders allo, you to create ser(ices ,hich ,or# at the messa"e le(el - as opposed to the operation le(el as ,ith annotated classes. The ha(e a sin"le operation 5in(o#e5 ,hich recei(es either the messa"e payload 6i.e. the S-A' 4ody8 or the ,hole messa"e itself 6i.e. the S-A' /n(elope8. 0ere7s a simple e ampleD HWebSer(ice'ro(ider public class 0ello'ro(ider J public Source in(o#e6Source re3uest8 J return ....G M M Ser(ices are publish (ia one of t,o meansD

The JAX-WS standard /ndpoint A'Is )X*7s X&C confi"uration format - i.e. Uja ,sDendpoint ... 2V

&ore InformationD De(elopin" a JAX-WS Ser(ice Javascript )X* pro(ides a Ja(ascript module ,hich allo,s you to build ser(ices in Ja(ascript ,ith the Ja(a %hino library. -ne ad(anta"e of this is that you can use /:X to interact more easily ,ith the X&C. *or more information see the Ja(aScript pa"e.

AX%S2 (ngine
Installing Axis2 engine on Tomcat
9o, to install the A is+ en"ine copy a is+.,ar into Tomcat7s ,ebapps directory. 9o, start the Tomcat ser(er. 'esting the Axis2 %nstallation Try usin" this httpD22localhostDA?A?2a is+. ;our bro,ser ,ill display the A is+ home pa"e and it should loo# li#eD

Developing Web service


The de(elopment of Web ser(ices is easy process. ;ou can start from the WSDC file6Contract +irst approach8 or from the Ser(ice code6Code +irst approach8. &ost de(eloper prefers the code first approach. We ,ill start ,ith the source and create the Web ser(ice. 0ere are the steps in(ol(ed in creatin" the ne, Web ser(ices ,ith code first approach in Apache A is+ <. De(elop the Ser(ice )lass +. De(elop the ser(ice descriptor e.". ser(ices. ml 1. )ompile and Ser(ice class and create the Web ser(ices achie(e file 6.aar8 Web Services Descriptor

In A is+ the ser(ice confi"uration file used is services6xml. The ser(ices. ml file must present in the <('A-%)F directory of the ser(ice achie(e. ;ou can ha(e multiple ser(ices in the ser(ices. ml file. The User(iceV...U2ser(iceV ta" is used to confi"ure the Web ser(ice. User(ice V UW-- )onfi"uration of the ser(ice --V U2ser(iceV 0ere is the services6xml file for our applicationD User(iceV Uparameter nameI5Ser(ice)lass5 loc#edI5false5V# com a)is* +s service.?elloWorldServiceU2parameterV Uoperation nameI5say0ello5V Umessa"e%ecei(er classI5org6apache6axis26rpc6receivers6"!C<essage"eceiver 52V U2operationV U2ser(iceV -ur ser(ice class is com a)is* +s service.?elloWorldService and the messa"e recei(er is org6apache6axis26rpc6receivers6"!C<essage"eceiver6 The operation ,e are e posin" is sa*?ello6

Compiling and building the service archieve .o to the C-BWor9spacesB(uropaBAxis2'utorialB directory and compile the ja(a class usin" follo,in" commandD C-BWor9spacesB(uropaBAxis2'utorialB C$avac net5roseindia5A6$ava )reate the ser(ice achie(e usin" the follo,in" commandD

C-BWor9spacesB(uropaBAxisFirst!ro$BsrcC$ar -cv+ ?elloWorldAxis6aar com <('A-%)F added mani+est adding- com50in 1 D8 0out1 D80stored DE8 adding- com5axis250in 1 D8 0out1 D80stored DE8 adding- com5axis25#s50in 1 D8 0out1 D80stored DE8 adding- com5axis25#s5service50in 1 D8 0out1 D80stored DE8 adding- com5axis25#s5service5?elloWorldService6class0in 1 F2D8 0out1 GH>8 0de+lated GGE8

adding- com5axis25#s5service5?elloWorldService6$ava0in 1 2D,8 0out1 ,GG8 0de+lated 2FE8 ignoring entr* <('A-%)F5 adding- <('A-%)F5services6xml0in 1 2I,8 0out1 ,IG80de+lated JJE8 C-BWor9spacesB(uropaBAxis2'utorialB V Deplo*ing the Web Services 9o, copy the 0elloWorldSer(ice.aar into ,ebapps2a is+2W/4-I9*2ser(ices directory and restart the Tomcat. The Apache A is+ en"ine ,ill deploy the ser(ice on the ser(er. 9o, open the bro,ser and bro,ser the url httpD22localhostDA?A?2a is+2ser(ices2listSer(ices.

You might also like