...
Services can be deployed as *.aar files, as you can see here, but their contents must be arranged in a specific way. For example, the structure of this service will be as follows:- StockQuoteService
- META-INF
- services.xml
- lib
- samples
- quickstart
- service
- pojo
- StockQuoteService.class
Here, the name of the service is StockQuoteService, which is specified in the services.xml file and corresponds to the top-level folder of this service. Compiled Java classes are placed underneath this in their proper place based on the package name. The lib directory holds any service-specific JAR files needed for the service to run (none in this case) besides those already stored with the Axis2 WAR file and the servlet container's common JAR directories. Finally, the META-INF directory contains any additional information about the service that Axis2 needs to execute it properly. The services.xml file defines the service itself and links the Java class to it (See Code Listing 3).
Code Listing 3: The Service Definition File<service name="StockQuoteService" scope="application">
<description>
Stock Quote Sample Service
</description>
<messageReceivers>
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-only"
/>
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-out"
/>
</messageReceivers>
<parameter name="ServiceClass">
samples.quickstart.service.pojo.StockQuoteService
</parameter>
</service>
Here the service is defined, along with the relevant messageReceiver types for the different message exchange patterns.
...
Note the directory structure contained at AXIS2_HOME/samples/quickstart (the services.xml file is from the first section of this guide):- quickstart
- README.txt
- build.xml
- resources
- META-INF
- services.xml
- src
- samples
- quickstart
- service
- pojo
- StockQuoteService.java
Note that you can generate a WSDL from the quickstart directory by typing:ant generate.wsdl
However, creating StockQuoteService.wsdl is optional. It can be the version generated directly from the Java class, or a customized version of that file, and that services.xml is the same file referenced earlier in this document.
Now build the project by typing ant generate.service in the quickstart directory, which creates the following directory structure:- quickstart/build/classes
- META-INF
- services.xml
- samples
- quickstart
- service
- pojo
- StockQuoteService.class
If you want to deploy the service in an exploded directory format, rename the classes directory to StockQuoteService, and copy it to the webapps/axis2/WEB-INF/services directory in your servlet engine. Otherwise, copy the build/StockQuoteService.aar file to the webapps/axis2/WEB-INF/services directory in your servlet engine. Then check to make sure that the service has been properly deployed by viewing the list of services at:http://localhost:8080/axis2/services/listServices
You can also checkout the WSDL at:http://localhost:8080/axis2/services/StockQuoteService?wsdl
And the schema at:http://localhost:8080/axis2/services/StockQuoteService?xsd
Once the URLs are working, quickly test the service. Try pointing your browser to the following URL:http://localhost:8080/axis2/services/StockQuoteService/getPrice?symbol=IBM
You will get the following response:<ns:getPriceResponse xmlns:ns="http://pojo.service.quickstart.samples/xsd"><ns:return>42</ns:return></ns:getPriceResponse>
If you invoke the update method as,http://localhost:8080/axis2/services/StockQuoteService/update?symbol=IBM&price=100
and then execute the first getPrice URL, you will see that the price has got updated.
Building the Service using AXIOM
...
Note the directory structure contained at /samples/quickstartaxiom:- quickstartaxiom
- README.txt
- build.xml
- resources
- META-INF
- services.xml
- StockQuoteService.wsdl
- src
- samples
- quickstart
- service
- axiom
- StockQuoteService.java
- clients
- AXIOMClient.java
Since AXIOM is a little different, you're going to need a different services.xml file from the one used for POJO. Define it, as shown in Code Listing 4.
Code Listing 4: The Service Definition File.<service name="StockQuoteService" scope="application">
<description>
Stock Quote Service
</description>
<operation name="getPrice">
<messageReceiver/>
</operation>
<operation name="update">
<messageReceiver/>
</operation>
<parameter name="ServiceClass">samples.quickstart.service.axiom.StockQuoteService</parameter>
</service>
Note that it's almost the same, except that the operations are explicitly defined in the service.xml file, and the MessageReceivers are now RawXML.
...
Also, note the directory structure shown in the Creating a service with AXIOM section, duplicated below for completeness.- quickstartaxiom
- README.txt
- build.xml
- resources
- META-INF
- services.xml
- StockQuoteService.wsdl
- src
- samples
- quickstart
- service
- axiom
- StockQuoteService.java
- clients
- AXIOMClient.java
The above referenced AXIOMClient.java class is defined as follows, shown in Code Listing 9.
Code Listing 9: The AXIOMClient class using AXIOMpackage samples.quickstart.clients;
...
OMElement value2 = fac.createOMElement("price", omNs);
value2.addChild(fac.createOMText(value2,
Double.toString(price)));
method.addChild(value2);
return method;
}
public static void main(String\[\] args) \ {
Wiki Markup
try \ {
OMElement getPricePayload = getPricePayload("WSO");
OMElement updatePayload = updatePayload("WSO", 123.42);
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
...
import samples.quickstart.service.adb.StockQuoteServiceStub;unmigrated-wiki-markup
public class ADBClient\{
public static void main(java.lang.String args\[\])\{
try\{
StockQuoteServiceStub stub =
new StockQuoteServiceStub
("http://localhost:8080/axis2/services/StockQuoteService");
getPrice(stub);
update(stub);
getPrice(stub);
...
public class XMLBEANSClient{unmigrated-wiki-markup
public static void main(java.lang.String args\[\])\{
try\{
StockQuoteServiceStub stub =
new StockQuoteServiceStub
("http://localhost:8080/axis2/services/StockQuoteService");
getPrice(stub);
update(stub);
getPrice(stub);
...
import samples.quickstart.service.jibx.StockQuoteServiceStub;unmigrated-wiki-markup
public class JiBXClient\{
public static void main(java.lang.String args\[\])\{
try\{
StockQuoteServiceStub stub =
new StockQuoteServiceStub
("http://localhost:8080/axis2/services/StockQuoteService");
getPrice(stub);
update(stub);
getPrice(stub);
...