Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

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

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;
}

Wiki Markuppublic static void main(String\[\] args) \ {
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);

...