|
|
We will start with a simple Java class which will be turned into a service with the necessary packaging. Next a client will be created using the code generated by the WSDL2Java code which will be used to invoke the service we created. You will have to download Apache Axis2-Nightly build Satandard Binary Distribution to try this out and the source code of both client and service are available here. Now simply follow the steps below.
/**
* The service implementation class
*/
public class SimpleService {
/**
* The echo method which will be exposed as the
* echo operation of the web service
*/
public String echo(String value) {
return value;
}
}
---------------------------------------------------------------
save as - SimpleService.java
---------------------------------------------------------------
<service>The "service" element encapsulates the information about a single service. Within the "service" element there should be a parameter specifying the service implementation Java class. The parameter is specified as a "parameter" element as shown below.
<parameter name="ServiceClass"
locked="false">SimpleService</parameter>
<operation name="echo">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>
<parameter name="ServiceClass" locked="false">SimpleService</parameter>The second child element of the "service" element "operation" element describes the operation and the message receiver that is to be used for that operation. For this service we set the "name" attribute of the "operation" element to the name of the method that we wish to expose as a Web service operation. Hence we set it to "echo":
<operation name="echo">Axis2 provides a MessageReceiver based on Java reflection and the "messageReceiver" element declaring that org.apache.axis2.rpc.receivers.RPCMessageReceiver should be used.
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
[Linux]Now compile the SimpleService.java class and move the SimpleService.class file to the temp directory.
mkdir temp
[Windows]
md temp
javac SimpleService.java -d temp/Create a META-INF directory within the "temp" directory and copy the service.xml file into the META-INF directory. Change directory to the "temp" directory and use the "jar" command as follows to create the service archive named SimpleService.aar.
jar -cvf SimpleService.aar *
This tutorial will use the org.apache.axis2.transport.http.SimpleHTTPServer to host the SimpleService.aar Axis2 service archives are placed in a directory named "services" in a repository directory. The structure of an example repository directory is shown below.

Now create the my-axis2-repo directory structure and copy the SimpleService.aar file into the "services" directory. This example does not require the axis2.xml to be available in the "conf" directory. Now we have to start the SimpleHTTPserver using the above my-axis2-repo directory as the repository directory. The axis2-std-SNAPSHOT-bin distribution comes with a "bin" directory which contains a Linux shell script and a Windows batch file to start the SimpleHTTPServer: http-server.sh and http-server.bat Start the server pointing to my-axis2-repo directory:
[Linux]The following output will be shown in the console:
sh http-server.sh /path/to/my-axis2-repo
[Windows]
http-server.bat drive:\path\to\my-axis2-repo
[SimpleHTTPServer] StartingNow when we point a browser to http://localhost:8080/ the SimpleHTTPServer will respond with a list of available services and the SimpleService will be listed there.
[SimpleHTTPServer] Using the Axis2 Repository /home/ruchith/Desktop/
ibm-workshop/axis2-repo
[SimpleHTTPServer] Listening on port 8080
[JAM] Warning: You are running under a pre-1.5 JDK.
JSR175-style source annotations will not be available
[SimpleHTTPServer] Started

[Linux]This generates two .java files and we will be using the org.apache.axis2.SimpleServiceStub to invoke the "echo" operation of the service. Now lets create a new Client.java class which uses the org.apache.axis2.SimpleServiceStub. For simplicity lets create the Client.java file in the same package as the generated code (i.e.org.apache.axis) and save it along with the other generated code.
$ sh WSDL2Java.sh -uri http://localhost:8080/axis2/services/
SimpleService?wsdl -o /path/to/my/client/code/
[Windows]
WSDL2Java.bat -uri http://localhost:8080/axis2/services/
SimpleService?wsdl -o /path/to/my/client/code/
package org.apache.axis2;
import org.apache.axis2.SimpleServiceStub.EchoResponse;
public class Client {
public static void main(String[] args) throws Exception {
SimpleServiceStub stub = new SimpleServiceStub();
//Create the request
SimpleServiceStub.Echo request = new SimpleServiceStub.Echo();
request.setParam0("Hello world");
//Invoke the service
EchoResponse response = stub.echo(request);
System.out.println("Response : " + response.get_return());
}
}
----------------------------------------------------------------
save as - Client.java
----------------------------------------------------------------
Now to we can compile and run the client code. Its is important to note that the classpath must have all the jars in the "lib" directory of the axis2-std-1.0-RC1-bin distribution when compiling and running the client.
The following command will compile the client's source to a "temp" directory
$ javac -extdirs /path/to/axis2-RC1-std-bin/lib/ org/apache/axis2/*.java -d temp/
We can run the client program as shown below from the "temp" directory:
$ java -Djava.ext.dirs=/path/to/axis2-RC1-std-bin/lib/ org.apache.axis2.Client
The output will be :
Response : Hello world
sh http-server.sh /path/to/my-axis2-repo -p9090
Now when we run the client once again we can view the messages.

Thanks All
Thanks Fernando,you save me a
client with axis2-1.5.3
Some issues when running with axis2-1.5
Thanks
I am using the complete
I am using the complete
Javac cannot find source files
Solved.
Broken link
old but nonetheless
HelloWorld with Axis
Problems with creating stubs
problem with client code
Using the tutorial with Tomcat5.5
POJO File Access
Strangely...
Solution to Problems Using Tomcat
did you manage to do it
Anonymous internal server error inside Axis2
Unable to run the Code from the command Line
Using nightly build - SimpleServiceStub issues
Echo Static Class not generated
.
setMessage still doesn't do it.
setParam0 should be changed to setArgs0
wsdl problems
Re: wsdl problems
Need REST client example code
error while running the client program
Problem in Client.java
Re: Problem in Client.java
Auto Generated SimpleServiceStub.java Missing EchoResponse Class
Problem Persists in Nightly Build
same problem
Problem in running the client
Re: Problem in Client.java
How to get call service through web browser
Re: How to get call service through web browser
hi,
RE: hi
axis 2 error: incoming message does not contain security header
Service with Parameter
wsdl parser error
that's prolly happening cos
now getting a ClassNotFoundException
probably a classpath error!
ClassNotFoundException : ExtensionUtility
getting a 'DeploymentException'
Re: getting a 'DeploymentException'