blob: 827d31ba98cfa074b3563e9123d98293b1caf0d2 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>Axis 2.0 User's Guide</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/axis-docs.css" type="text/css" rel="stylesheet" />
<style type="text/css">
.style1 {font-family: "Courier New", Courier, mono}
.style2 {font-size: 14px}
.style3 {color: #990000}
.style4 {
font-family: "Courier New", Courier, mono;
font-size: 14px;
color: #990000;
<h1 align="center"><a name="_Toc96697849">Axis 2.0 User's Guide </a></h1>
<p>&nbsp; </p>
<h3><a name="_Toc96698076"></a>Introduction </h3>
<p>Welcome to Axis 2.0, the next generation of Apache Axis !!! This User Guide will help you to understand what you will get from Axis 2.0 and how to get started. </p>
<p>We hope you will benefit from the power of Axis 2.0. </p>
<h3><a name="_Toc96698077"></a>What is Axis 2.0 ? </h3>
<p>Before we start, its highly recommended to read <a href="">Axis 1.x User's guide </a>, if you are new to Axis. </p>
<p>Axis 2.0 is the next generation of Apache Axis. In late August 2004, during the Axis Summit held in Colombo, Sri Lanka, a new architecture was introduced to have a much more flexible, efficient and configurable Axis. Even though the architecture is new, some of the well established concepts from Axis 1.x, like handlers are preserved in Axis 2.0 also. Axis 2.0 comes with lots of new features, enhancements and new industry specification implementations. </p>
<p>After months of continued discussion and coding effort in this direction, Axis 2.0 now delivers the following key features: </p>
<li><strong>Speed</strong>. Axis uses its own object model and StAX (streaming) parsing to achieve significantly greater speed than earlier versions of Apache AXIS. </li>
<li><strong>Low memory foot print</strong>. Axis 2.0 was designed ground-up keeping low memory foot print in mind. </li>
<li><strong>AXIOM</strong>. Axis 2.0 comes with its own light-weight object model, AXIOM, for message processing which is extensible, high performance and developer convenient </li>
<li><strong>Hot Deployment.</strong> One can now hot deploy web services and handlers. </li>
<li><strong>Asynchronous Web Services</strong>. Axis 2.0 now support asynchronous web services invocation and asynchronous web services. </li>
<li><strong>Flexibility</strong>. The Axis architecture gives the developer complete freedom to insert extensions into the engine for custom header processing, system management, or anything else you can imagine. </li>
<li><strong>Stability</strong>. Axis defines a set of published interfaces which change relatively slowly compared to the rest of Axis. </li>
<li><strong>Component-oriented deployment</strong>. You can easily define reusable networks of Handlers to implement common patterns of processing for your applications, or to distribute to partners. </li>
<li><strong>Transport framework</strong>. We have a clean and simple abstraction for designing transports (i.e., senders and listeners for SOAP over various protocols such as SMTP, FTP, message-oriented middleware, etc), and the core of the engine is completely transport-independent. </li>
<li><strong>WSDL support.</strong> Axis 2.0 supports the <a href="">Web Service Description Language </a>, version 1.1 and 2.0, which allows you to easily build stubs to access remote services, and also to automatically export machine-readable descriptions of your deployed services from Axis. </li>
<p>We hope you enjoy using Axis. Please note that this is an open-source effort - if you feel the code could use some new features or fixes, please get involved and lend a hand! The Axis developer community welcomes your participation . </p>
<p>Let us know what you think! </p>
<p>Please send feedback about the package to &quot; <a href=""> </a>&quot; and make sure to prefix the subject of the mail with “[Axis2]”. </p>
<h3><a name="_Toc96698078"></a>What's in this release? </h3>
<p>This release includes the following features: </p>
<li>SOAP 1.1/1.2 compliant engine </li>
<li>Flexible configuration / deployment system with hot deployment support </li>
<li>HTTP servlet-based transport </li>
<li>Handler framework </li>
<li>AXIOM with complete SOAP specific API support </li>
<li>Client synchronous/asynchronous model </li>
<li>Basic XML in / XML out scenario support </li>
<li>WSDL 1.1 and 2.0 compliant Component Model </li>
<li>Examples, including a client and server for the one-way, two-way and synchronous, asynchronous web services invocation </li>
<h3><a name="_Toc96698079"></a>What's still to do? </h3>
<p>Please see a list of what we think needs doing - and please consider helping out if you're interested &amp; able! </p>
<li>Encoding/data binding </li>
<li>JAX-RPC support </li>
<li>WSDL Based code (server/client) code generator </li>
<li>MTOM attachments support </li>
<li>Server side sync/async support </li>
<li>Complete XML infoset support for AXIOM </li>
<h2><a name="_Toc96698080"></a>Installation Guide </h2>
<h3><a name="_Toc96698081"></a>Introduction </h3>
<p>Axis 2.0 can be downloaded as a <a href="releases.html">zipped binary </a> or the <a href="cvs-usage.html">source </a>. This section describes how Axis2 can be installed either as a standalone server or as part of a J2EE compliant servlet container. </p>
<h3><a name="_Toc96698082"></a>Prerequisites </h3>
<p>Axis2 requires the Java Runtime Environment to be properly installed. Axis is developed to be run on JRE 1.4 and upwards but it has not been fully tested with the latest JRE 1.5. Hence it is safe to run Axis with Java 1.4. If the JRE is not already in place it must be installed to proceed further. For instructions on setting up the JRE in different operating systems, please visit <a href=""> </a>. </p>
<p>All the required jars are shipped with the binary distribution and if the source distribution is used, running the maven build will automatically download the required jars for you. </p>
<p>Following sections describe how each type of distribution needs to be installed. Since the process with the source distribution is similar to the binary distribution after building, the first section explains the process of building Axis from source. If you have the binary distribution you can skip the build sections and directly go to the binary installation section. </p>
<h3><a name="_Toc96698083"></a>Building Axis2 from source </h3>
<h4><a name="_Toc96698084"></a>Setting up the Environment and the tools </h4>
<p>The Axis2 build is based on <a href="">Maven </a>. Hence the prerequisite to build Axis2 from source is to have Maven installed. Even though extensive instruction guides are available at the Maven site, this guide also contains the “easiest path” for quick environment setting. Advanced users who wish to know more about Maven can visit <a href="">here </a>. </p>
<p>For Windows users the easiest way is to download the windows installer package. Once the installer package is run, all the necessary environment variables will be properly set. Once Maven is installed, the success of the installation can be tested by typing “maven –version” in the command prompt. </p>
<p>&nbsp; </p>
<p align="center"><img width="477" height="211" src="images/clip_image002.jpg"></p>
<p>&nbsp; </p>
<p>For Linux users the tar ball or the zip archive is the best options. (Unfortunately there is no rpm as such that can be easily installed) Once the archive is downloaded expand it to a directory of choice and set the environment variable “MAVEN_HOME” and add MAVEN_HOME/bin to the path as well. More instructions for installing Maven in UNIX based operating systems can be found <a href="">here </a>. </p>
<p>Once maven is properly installed it's all that is needed to start building Axis2. </p>
<h4><a name="_Toc96698085"></a>The Axis source distribution </h4>
<p>The <a href="releases.html">source distribution </a> is available as a zipped archive or a tar ball. All the necessary build scripts are included with the source distribution. Once the source archive is expanded into a directory of choice, moving to the particular directory and typing maven will build the axis jar file. </p>
<p align="center"><img width="540" height="292" src="images/clip_image004.jpg"></p>
<p>Once the command completes, the binaries (jar files in this case) can be found at a newly created “target” directory. </p>
<p><strong>Note – For the first Maven build (if the maven repository is not built first) it will take a while since required jars need to be downloaded. However this is a once only process and will not affect any successive builds. </strong></p>
<p><strong> </strong>The default maven build will however build only the Axis2 jar file. To obtain a WAR (Web Archive), “maven war” command should be issued. This will create a complete WAR with the name axis2.war inside the target directory. </p>
<p>Once this build step is complete, the binaries are ready to be deployed. </p>
<h3><a name="_Toc96698086"></a>Installing Axis2 in a Servlet container </h3>
<p>Installation of the WAR is quite simple. It's a matter of dropping the war in the webapps folders and most servlet containers will automatically install the war. However some servlet containers may require a restart in order to capture the new web application. Please refer your servlet container documentation for more information about this. </p>
<p>Once the WAR is successfully installed it can be tested by pointing the web browser to the <strong>http:// &lt;host :port&gt;/ axis2. </strong>It should produce the following page. </p>
<p align="center"><strong><img src="images/clip_image006.jpg"></strong></p>
<p><strong>&nbsp; </strong>To ensure that everything is fine and smooth, a probing of the system can be done through the validate link. If the validation fails then the war has failed to install properly or some essential jars are missing. At such a situation the documentation of the particular servlet container should be consulted to find the problem. The following page is a successful validation. Note the statement “core axis libraries are present”. </p>
<p align="center"><img src="images/clip_image008.jpg"></p>
<p>The axis web application also provides an interface to upload services. Once a service is created according to the service specification (see the service jar file format structure) that jar file can be uploaded using the upload page. </p>
<p align="center"><img src="images/clip_image010.jpg"></p>
<p>&nbsp; </p>
<p>The uploaded jar files will be stored in the default service directory. For Axis2 this will be the &lt;webapps&gt;/axis2/WEB-INF/services directory. Once a service is uploaded it will be instantly installed. </p>
<p>Since Axis2 supports hot deployment one can drop the service jar directly through the file system to the above mentioned services directory and it will also cause the service to be automatically installed without the container being restarted. </p>
<p>To check the successful installation of a service <strong><em>available services link </em></strong> is provided. The services and the operations of successfully installed services will be displayed in the available services page. </p>
<p align="center"><img src="images/clip_image012.jpg"></p>
<p>To test run an uploaded service, instructions are provided in the samples guide about running the sample clients. However whether the service is
present can be checked by pointing the browser to <b>http://&lt;host&gt;:&lt;port&gt;/axis2/services/&lt;service name&gt;</b>.
<!-- This should provide a page similar to the following -->
<!-- Image goes here -->
<!--<h3><a name="_Toc96698087"></a>Running the Axis2 standalone server </h3>
<p>Since a J2EE servlet container can be heavy in certain cases, a simple socket server is provided with Axis2. </p>
Start scripts are inluded in the bin directory of the binary distribution.</p>
<p>For windows</p>
<p class="command">&gt;start.bat </p>
<p>For Linux</p>
<p class="command">$</p>
<p>This will start the simple axis server in the default port (8080). To start the server in a non default port
the server script can be used. The sever script however needs two parameters, the repository location and the port.</p>
<p>For windows</p>
<p class="command">&gt;server <i>repository directory</i> <i>port</i> </p>
<p>For Linux</p>
<p class="command">$server <i>repository directory</i> <i>port</i> </p>
Note - the directory entered as the repository loacation needs to have a services directory inside. This is
absolutely required and AXIS will not create it automatically in the case of the simple axis server.
</b></p> -->
<h2><a name="_Toc96697863"></a>Samples </h2>
<p>There are three sample programs, which are listed below, that will be explained in this user guide and the relevant code can be found in the source directory under ../modules/samples/src/java/userguide/sample1. </p>
<li>Case1: Echo Synchronous call. </li>
<li>Case2: Echo Synchronous call with a phased handler. </li>
<li>Case3: Echo Asynchronous call at the client side. </li>
<p>For the above three cases the sample will make use of two web services(namely sample1, sample1WithHandler) and two client applications. The diagram shows how the two services and the two client applications are used to come up with the three cases mentioned above.</p>
<p align="center"><img src="images/cases.jpg" width="467" height="246"></p>
<p> Axis2 M1 currently does not support the data binding, thus in the samples the operation that will be supported will be the echoing of xml without data binding. The message that will be sent and echoed will be the following.</p>
<pre class="style1 style2 style3">&lt;soapenv:Envelope xmlns:soapenv="" xmlns:sample1=""&gt;
&nbsp;&nbsp;&nbsp;&nbsp; &lt;soapenv:Header/&gt;
&nbsp;&nbsp;&nbsp;&nbsp; &lt;soapenv:Body&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;sample1:echo&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;sample1:Text&gt;Axis2 Echo String&lt;/sample1:Text&gt; &nbsp;
&nbsp;&nbsp;&nbsp; &lt;/soapenv:Body&gt;
<p>The Sample1 can be located at the src/samples/userguide/sample1 directory and it will have (or eventually have after the build) the following files. </p>
<table width="756" align="center" border="1" cellpadding="0" cellspacing="0">
<td width="138" align="center" valign="top"><p align="center">Directory </p></td>
<td width="245" valign="top"><p align="center">File </p></td>
<td width="371" valign="top"><p align="center">Description </p></td>
<td valign="top"><p>modules/samples</p></td>
<td valign="top"><p>build.xml </p></td>
<td valign="top"><p>Ant build file to compile, deploy and run the sample </p></td>
<td valign="top"><p>modules/samples/src </p></td>
<td valign="top"><p> </p></td>
<td valign="top"><p>Actual web service </p></td>
<td colspan="3" valign="top"><p>&nbsp; </p></td>
<td valign="top"><p>&nbsp; </p></td>
<td valign="top"><p> </p></td>
<td valign="top"><p>Echo Synchronous client. The same client will be used for Echo Synchronous call with a phased handler. </p>
<p>&nbsp; </p></td>
<td colspan="3" valign="top"><p>&nbsp; </p></td>
<td valign="top"><p>&nbsp; </p></td>
<td valign="top"><p> </p></td>
<td valign="top"><p>A handler that will log when it gets called. </p></td>
<td colspan="3" valign="top"><p>&nbsp; </p></td>
<td valign="top"><p>&nbsp; </p></td>
<td valign="top"><p> </p></td>
<td valign="top"><p>Echo client with client side Asynchronous call </p></td>
<td valign="top"><p>&nbsp; </p></td>
<td valign="top"><p> </p></td>
<td valign="top"><p>The callback that will be called after the completion of the Asynchronous call. </p></td>
<td valign="top"><p>&nbsp; </p></td>
<td valign="top"><p> </p></td>
<td valign="top"><p>A client Utility class that will generate a SOAPEnvelope.</p></td>
<td colspan="3" valign="top"><p>&nbsp; </p></td>
<td valign="top"><p>modules/samples/conf </p></td>
<td valign="top"><p>service.xml </p></td>
<td valign="top"><p>The deployment descriptor for the service sample1. </p></td>
<td valign="top"></td>
<td valign="top"><p>service4withhandler.xml </p></td>
<td valign="top"><p>The deployment descriptor for the service sample1WithHandler. </p></td>
<td valign="top"><p>modules/samples/</p>
<p>build/services </p></td>
<td valign="top"><p>sample1.jar </p></td>
<td valign="top"><p>The deployable jar that is created after building the sample. </p></td>
<td valign="top"></td>
<td valign="top"><p>sample1WithHandler.jar </p></td>
<td valign="top"><p>The deployable jar of the web service sample1WithHandler that is created after building this sample.</p></td>
<td valign="top"><p>modules/samples/</p>
<p>build/lib </p>
<td valign="top"><p>sample1-all.jar </p></td>
<td valign="top"><p>The jar that bundles the server side and client side code. </p></td>
<h3><a name="_Toc96698089"></a>Pre-Conditions </h3>
<p>Axis2 should be installed (see the Installation guide above). For simplicity samples will assume the servlet container is Tomcat. </p>
<p>AXIS_HOME environment variable be set. (Rationale: The compile time and runtime libraries required in the classpath for the samples will be picked up form the deployed Asix2.) </p>
<p align="center"><img width="384" height="430" src="images/clip_image014.jpg"></p>
<p>Apache Ant should be installed and should be available in the path. It can be checked whether Ant is properly installed by simply typing ant in the command prompt. Please refer<a href=""></a>.</p>
<p align="center"><img src="images/ant.jpg" width="648" height="130"></p>
<h2>Building the sample</h2>
<p>The sources that are required for the running the samples can be compiled and packaged using the following ant task provided in the build.xml. Thus to build the samples the user can open a command prompt and change directory to modules\samples where the build.aml is located and type </p>
<p>>ant compile</p>
<p>or simply</p>
<p align="center"><img src="images/clip_image018.jpg" width="575" height="296"></img></p>
<p>The compilation will result in building three jar files; two of which are deployable services and the other is the compiled classes required for running the samples.</p>
<li>sample1.jar – Deployable web service that will be used for Case1 and Case3 (Packaged to modules/samples/build/services)</li>
<li>sample1Withhandler.jar – Deployable web service that will be used for Case2 (Packaged to modules/samples/build/services)</li>
<li>sample1-all.jar – Compiled sources required for running the client applications (Packaged to modules/samples/build/lib)</li>
<p>Once the sample is compiled once, all the required jar files for deploying and running all three Cases of the sample will be compiled and packaged.</p>
<h3><a name="_Toc96698091"></a>Sample1- Case1 : Echo Synchronous call </h3>
<p>The sample1 - Case1: Echo synchronous call is intended to demonstrate the synchronous web service call in Axis2 with both the client side and server side running Axis2. In the next few steps the user will be walked through in: </p>
<li>Compiling and building a web service </li>
<li>Deploying </li>
<li>Running the client </li>
<p>It is assumed that the sample is already compiled. Please refer "Building Sample1" above.</p>
<h4><strong>Deploying the sample </strong></h4>
<p>Before deploying the sample, it is necessary to package the web service. The actual web service implementation is the and it is necessary to write a service.xml so that the necessary statistics about the service will be available to the Axis2 engine at the runtime. </p>
<pre class="style1 style2 style3">&lt;service provider=&quot;org.apache.axis.providers.RawXMLProvider&quot; style=&quot;rpc&quot;&gt;
&nbsp;&nbsp;&lt;java:implementation class=&quot;userguide.sample1.EchoXML&quot; xmlns:java=&quot;;/&gt;
&nbsp;&nbsp;&lt;operation name=&quot;echo&quot; qname=&quot;echo&quot;/&gt;
&lt;/service&gt; </pre>
<p>Above service.xml provides five required types of information. </p>
<li>Provider – Provider that will invoke the service. </li>
<li>Style - Style of the operations of the service. </li>
<li>Implementation – Actual web service implementation class, in this case EchoXML. </li>
<li>Operation – The operations that the web service implementation supports or needs to be exposed. </li>
<p>Once the service.xml and the web service (in this case EchoXML) is ready it is necessary to package it to a jar. Actually with the above </p>
<p>&gt;ant compile </p>
<p>The web service will get packaged into the build\services directory. Now the user can deploy the service by one of the following methods. Since Axis2 supports the hot deployment of services can be deployed while the container is up and running. For option 2 below actually requires the container to be online. </p>
<p>&gt;ant deploy </p>
<p align="center"><img src="images/clip_image018.jpg" width="575" height="296"></p>
<p>&nbsp; </p>
<p>&#149;&nbsp; Uploading the jar using the web interface provided in the <strong>http:// &lt;host :port&gt;/ axis2 </strong>location. Please refer the Installation guide for further information. </p>
<p>&#149;&nbsp; Manually copying the sample1.jar in build\services to the AXIS_HOME\WEB-INF\services directory. </p>
<p><strong>The service will be deployed with the packaged jar file name. If the jar file is sample1.jar the service will be deployed with the name “sample1”. </strong></p>
<p>Point to note here is that above ant task is going to deploy two services </p>
<li>sample1 – Required for this(Case1) and the EchoAsync Call examples(Case1 and Case3). </li>
<li>sample1WithHandler – required for Echo Synchronous call with a phased handler(Case2). </li>
<p>If the servlet container is now running the user can go check to see whether the above services are deployed. Please refer the installation guide for further information on checking the deployed services. </p>
<p align="center"><img width="647" height="434" src="images/clip_image020.jpg"></p>
<h4><strong>Running the sample </strong></h4>
<p>The sample provides a simple synchronous client in the class. First the user must start the servlet container and run the client by simply typing </p>
<p>&gt;ant echo </p>
<p>in the command prompt. If all goes well the user will get the following output where the program will print the request SOAP message and the response SOAP message, which will be same as the request message. </p>
<p align="center"><img width="648" height="269" src="images/clip_image022.jpg"></p>
<h3><a name="_Toc96698092"></a>Sample1 - Case2: Echo Synchronous call with a phased handler. </h3>
<p>This example will go one step forward from the example above and will deploy a web service with a Logging handler. The client application will not change, of course with an exception; the Endpoint Reference will be changed to refer the new service <strong>“Sample1WithHandler” </strong>. </p>
<p>There is a Handler ( that is introduced in this case and it will basically log the fact that it got called. The code can be found in </p>
<pre class="style1 style2 style3">public void invoke(MessageContext msgContext) throws AxisFault {
&nbsp;&nbsp;;Incoming message From &quot;+msgContext.getTo().getAddress());
public void revoke(MessageContext msgContext){
&nbsp;&nbsp;;Incoming message Revoked at the server &quot;+msgContext.getTo().getAddress() );
} </pre>
<p>It is assumed that the sample is compiled. Please refer "Building Sample" above.</p>
<h4><strong>Deploying the sample </strong></h4>
<p>The implementation of the web service will be EchoXML, operation will be echo and the provider will be org.apache.axis.providers.RawXMLProvider, which are similar to that of the <strong>“Echo Synchronous call” </strong>. The difference is that there will be a handler that will be added in the server side. For further discussion refer the following service.xml which will be used in deploying the service. </p>
<pre class="style1 style2 style3">&lt;service provider=&quot;org.apache.axis.providers.RawXMLProvider&quot; style=&quot;rpc&quot;&gt;
&nbsp;&lt;java:implementation class=&quot;userguide.sample1.EchoXML&quot; xmlns:java=&quot;;/&gt; &nbsp;&nbsp; </pre><pre class="style1 style2 style3">&nbsp;&nbsp;&lt;inflow&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;handler name=&quot;LoggingHandler&quot; class=&quot;userguide.sample1.LoggingHandler&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;order phase=&quot;Logging&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;handler name=&quot;LoggingHandler&quot; class=&quot;userguide.sample1.LoggingHandler&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;order phase=&quot;Logging&quot;/&gt;
&nbsp;&nbsp;&lt;operation name=&quot;echo&quot; qname=&quot;echo&quot;/&gt;
&lt;/service&gt; </pre>
<p>In extra this service.xml has defined three elements </p>
<li>inflow </li>
<li>outflow </li>
<li>faultflow </li>
<p>These refer to the flows of the Axis2 server and further information of each could be found in the Architecture Guide. Using these elements the deployer can specify what handlers should go into which each flow. It can be further explained by referring to the entries in the above service.xml. In the above descriptor for the inflow and the faultfow there is a handler element that is added. At the deployment time, Axis2 will incorporate that handler to both the inflow and the fault flow. Since there is no such entry for the outflow no handler will be associated with the outflow. </p>
<p>Handler should specify the implementation class and the phase that it belongs to. In this case the handler belong to the <strong>Logging </strong> phase and this phase name should be one of that is defined in the <strong>server.xml </strong>(not service.xml). So this <strong>Logging </strong> phase should be defined there in the server.xml which is located in AXIS_HOME/ axis2/WEB-INF. The following is the default server.xml that is shipped with axis2.war. </p>
<pre class="style1 style9 style2 style3">&lt;server name=&quot;AxisJava2.0&quot;&gt;
&nbsp;&nbsp;&lt;parameter name=&quot;hotdeployment&quot; locked=&quot;xsd:false&quot;&gt;true&lt;/parameter&gt;
&nbsp;&nbsp;&lt;parameter name=&quot;hotupdate&quot; locked=&quot;xsd:false&quot;&gt;true&lt;/parameter&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;transport name=&quot;http&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;transport name=&quot;smtp&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phase name=&quot;global&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phase name=&quot;transport&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phase name=&quot;Logging&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phase name=&quot;module&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;phase name=&quot;service&quot;/&gt;
&lt;/server&gt; </pre>
<p>Since the Logging phase is there in the default server.xml the user who runs these samples need not edit the server.xml at all. </p>
<p>Nevertheless deploying the sample is very easy and it can be done in any of the three methods described in the <strong>“Echo Synchronous call” </strong> case. Infact had the use typed </p>
<p>&gt;ant deploy </p>
<p>and deployed the service in the <strong>“Echo Synchronous call” </strong> case then this service too will be deployed. The relevant jar file is <strong>sample1WithHandler.jar </strong> and will be packed to \build\services directory if the user wants to deploy it manually or upload using the web application. </p>
<h4><strong>Running the sample </strong></h4>
<p>In this case the client side is similar to that of <strong>“Echo Synchronous call” </strong>. The changes are happening in the server side in this case. The same can be used to invoke the service by changing the command line arguments. Refer the ant target for details </p>
<pre class="style4">&lt;target name= &quot;echo&quot; depends= &quot;compile&quot; &gt;
&nbsp;&nbsp;&lt;java classname= &quot;userguide.sample1.SynchronousClient&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;classpath refid= &quot;classpath.runtimelibraries&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg value= &quot;8080&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg value= &quot;/axis2/services/sample1&quot; /&gt;
&lt;target name= &quot;echoWithHandler&quot; &gt;
&nbsp;&nbsp;&lt;java classname= &quot;userguide.sample1.SynchronousClient&quot; &gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;classpath refid= &quot;classpath.runtimelibraries&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg value= &quot;8080&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg value= &quot;/axis2/services/sample1WithHandler&quot; /&gt;
&lt;/target&gt; </pre>
<p>To run the sample first the user must start the servlet container and run the client by simply typing </p>
<p>&gt;ant echoWithHandler </p>
<p>in the command prompt. If all goes well the user will get the following output where the program will print the request SOAP message and the response SOAP message, which will be same as the request message. </p>
<p align="center"><img width="648" height="265" src="images/clip_image024.jpg"></p>
<p>The service <strong>“sample1withhandler” </strong> will run its logging handler as it gets called and it will log the call as the handler gets called in the inflow. This logged information can be found in the server logs. </p>
<h3><a name="_Toc96698093"></a>Sample1 - Case3: Echo Asynchronous call. </h3>
<p>In this case the example focuses on calling a synchronous web service in an asynchronous manner in the client side. If this example is compared with the first example, which is <strong>“Echo Synchronous call” </strong>, the server side is identical for both the cases. The difference will be in the web service client that will be used. </p>
<p>In this case the client will make a web service call and it will register a call back handler and sends the message out. The difference will be that the client application that is doing the web service call will not hang till the response. Rather it will get returned and once the response returns the client will get notified by way of the registered callback (This is one of the two methods this can be done in Axis 2.0. Refer <a href="ClientAPI.html">Client Api Tutorial </a> for more information). </p>
<p>The callback handler that will be used is and the client program is </p>
<p>It is assumed that the sample is already compiled. Please refer the "Building Sample1" above. </p>
<p>On the other hand the Case3 uses the <strong>sample1</strong> web service. Thus if the user has already deployed sample1 web service in Case1 above then there is no requirement of deploying again. Please refer Case1 deploying to deploy the required service above.</p>
<h4><strong>Running the sample </strong></h4>
<p>The class to run is and it will intialise the web service call. It will register a call back in this case an instance of the ClientEchoCallbackHandler and then client will sleep to keep the thread alive. Eventually when the response is received the callback handler will be called(if all goes well onComplete() method will be called), in this case the ClientEchoCallbackHandler instance that was registered. </p>
<p>Inside the ClientEchoCallbackHandler it will print the received SOAP message. Please refer the code. </p>
<p>To run the client one can simply type </p>
<p>&gt;ant echoAsync </p>
<p>and it will give the following output. </p>
<p align="center"><img width="648" height="277" src="images/clip_image026.jpg"></p>
<p>&nbsp; </p>
<h2><a name="_Toc96698094"></a>Writing your own Service and a client </h2>
<h3><a name="_Toc96698095"></a>Writing a New Service </h3>
<p>Writing a new Web Service in Axis2-M1 requires you to do following steps </p>
<p><strong>&#149;&nbsp; Writing a new Web Service implementation class </strong></p>
<p>Axis2 M1 does not support data binding and supports only the XML level messaging. The default provider (do not worry about this if you do not know what it is) only supports the java methods having the return type as OMElement and only parameter as an OMElement. </p>
<p>The OMElement is a Streaming representation of XML Message Element Information Item (Even though the user sees the OMElement as a tree based DOM/JDOM like node, it reads the information from the stream only when its absolutely required.). For more information refer the <a href="OMTutorial.html">OM Tutorial </a>. </p>
<pre class="style4">public class &lt;class-name&gt;{
&nbsp;&nbsp;public OMElelemnt &lt;method-name&gt;(OMEllemnt){
&nbsp;&nbsp;&nbsp;&nbsp;&lt;business logic&gt;
} </pre>
<p><strong>&#149;&nbsp; Write the service.xml file </strong></p>
<p>the following XML snippet is a very simple service.xml file. </p>
<pre class="style4">&lt;service provider=&quot;org.apache.axis.providers.RawXMLProvider&quot; style=&quot;rpc&quot;&gt;
&nbsp;&nbsp;&lt;java:implementation class=&quot;&lt;implementation-classname&gt;&quot; xmlns:java=&quot;;/&gt;
&nbsp;&nbsp;&lt;operation name=&quot;&lt;method-name&gt;&quot; qname=&quot;&lt;method-name&gt;&quot;/&gt; ...
&lt;/service&gt; </pre>
<p>Here the org.apache.axis.providers.RawXMLProvider is the default provider for the Apache Axis2 M1, the provider can be changed by specifying the relevant parameter. Note that &lt;method-name&gt; should be replaced by the relevant method name. </p>
<p><strong>&#149;&nbsp; Create an archive with the service.xml file and with class files </strong></p>
<p>Compile the the Web Service implementation class and any other supporting class. Archive them in to a jar file. Place the service.xml file in the META-INF directory. </p>
<p>Name of the archive would be the name of the service. For example if the service name is echo the archive should be echo.jar or echo.aar ( <strong>a</strong>xis <strong>ar</strong>chive) </p>
<p><strong>&#149;&nbsp; Deploy the archive in the Axis2 </strong></p>
<p>While the Axis2 is running copy the archive to the services folder in the repository directory or use web upload method. (in the case of a Servlet container this directory is axis/WEB-INF/services/). Axis will automatically pick the archive and deploy the service. </p>
<p>To make this whole process user-friendly, Axis2 is shipped with a service creation GUI tool. It is
a "wizard interface" and also provides the facility for users to automatically create a very simple
service.xml as well. The tool start script can be found in the bin directory.
<h3><a name="_Toc96698096"></a>Writing a Client for the Axis2-M1 </h3>
<p>Axis2 M1 supports HTTP transport only. Axis2-M1 supports the following interaction patterns. </p>
<p>&#149;&nbsp; Blocking invocation of type in-out (request/response) </p>
<p>&#149;&nbsp; Non blocking invocation of type in-out (Without a separate Listener) </p>
<p>for more information about the interaction patterns, visit the <a href="ClientAPI.html">Client API Tutorial </a>. </p>
<p>To invoke the web service, user needs to build the the SOAPEnvelope himself. The SOAPEnvelope can be built by the following code. </p>
<pre class="style4">OMFactory fac = OMFactory.newInstance();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
OMElement omElement = .....
envelope.getBody().addChild(omElement); </pre>
<p>OMElement can be build using one of the following methods; </p>
<li>Create a OM by building the OM tree <br>
<span class="style4">fac.createOMElement(method, ns);</span></li>
<li>Create a OM Element from a XML file
<pre class="style4">XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(file)); <br>
OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMFactory.newInstance(), parser); <br>
<p>for more information in handling the OM objects please read the <a href="OMTutorial.html">OM Tutorial </a>. </p>
<h4><a name="_Toc96698097"></a>Synchronous Client </h4>
<p>Invoking the synchronous web service call can be done with the following code. </p>
<pre class="style4">EndpointReference targetEPR = <strong>new </strong>EndpointReference(AddressingConstants.WSA_TO, &quot;; + (EngineUtils.TESTING_PORT) + &quot;/axis/services/echo&quot; );
Call call = <strong>new </strong>Call();
SOAPEnvelope responseEnv = call.sendReceive(envelope); </pre>
<p>&#149;&nbsp; The Endpoint Reference (EPR) is the To location of the web service. </p>
<p>&#149;&nbsp; call.setTo() method registers the created EPR with the call object. </p>
<p>&#149;&nbsp; call.sendRecieve() method invokes the web service at the location specified by the EPR using the given SOAP Message. </p>
<h4><a name="_Toc96698098"></a>Asynchronous Client </h4>
<p>Invoking the asynchronous web service call can be done with the following code. </p>
<pre class="style4">EndpointReference targetEPR = <strong>new </strong>EndpointReference(AddressingConstants.WSA_TO, &quot;; + (EngineUtils.TESTING_PORT)+ &quot;/axis/services/echo&quot; );
Call call = <strong>new </strong>Call();
call.setListenerTransport(Constants.TRANSPORT_HTTP, <strong>true </strong>);
SOAPEnvelope responseEnv = call.sendReceiveAsync(envelope,callback); </pre>
<p>&#149;&nbsp; The Endpoint Reference (EPR) is the To location of the web service. </p>
<p>&#149;&nbsp; call.setTo() method registers the created EPR with the call object. </p>
<p>&#149;&nbsp; call.sendRecieveAsync() method invokes the web service at the location specified by the EPR using the given SOAP Message. </p>
<p>&#149;&nbsp; The LitenerTransport is type of the trasport to be used. Axis2-M1 only supports the http and the second parameter express the should the seperate listener is to be started or not. Axis-M1 supports only the true for this. </p>
<p>&#149;&nbsp; callback it the Callback to handle the response e.g. </p>
<pre class="style1 style2 style3">Callback callback = <strong>new </strong> Callback() {
<strong>&nbsp;&nbsp;public void </strong>onComplete(AsyncResult result) {
&nbsp;&nbsp;&nbsp;&nbsp;//process the result
<strong>&nbsp;&nbsp;public void </strong>reportError(Exception e) {
&nbsp;&nbsp;&nbsp;&nbsp;//handler error
<p>&nbsp; </p>
<p>&nbsp; </p>