This post explains how you can develop, deploy and access web services using Axis2 from scratch. This is going to be a very basic tutorial. We are not going to use any IDE or building tools like Maven. But, by doing so, we can understand each and every aspects of developing, deploying and consuming web services. Next part of this tutorial explains how we can do the same thing easily using Maven.
We are going to develop a hello world web service using Apache Axis2. Apache Axis2 is nothing but a web service engine. You can develop, deploy and access web services using Axis2.
2. Extract it to a convenient directory. Let's call it AXIS2_HOME.
You will get the following structure under your AXIS2_HOME.
That's it. You have installed it.
Point the browser URL to http://localhost:8080/axis2/services/
You will see all the deployed services.
If you click on one service, you can get access to it's WSDL.
Create a folder structure as bellow,
Create a class "HelloService.java" as bellow and save under "Service" directory.
Create a service descriptor "Services.xml" as bellow and save under "Service/target/META-INF" directory.
Run the following command from "Service" directory to compile the HelloService.java and move HelloService.class to target directory.
We are going to develop a hello world web service using Apache Axis2. Apache Axis2 is nothing but a web service engine. You can develop, deploy and access web services using Axis2.
Installation
1. Download the latest Axis2 binary distribution here.2. Extract it to a convenient directory. Let's call it AXIS2_HOME.
You will get the following structure under your AXIS2_HOME.
That's it. You have installed it.
Running the Axis2 server
In your terminal, navigate to "AXIS2_HOME/bin" directory and run the following command.sh axis2server.shIf your server starts successfully, you will get something similar as below in your terminal.
Deploying services
"AXIS2_HOME/repository/services" is the deployment directory in Axis2. You have to copy your axis2 service (yourService.aar) to this directory.Point the browser URL to http://localhost:8080/axis2/services/
You will see all the deployed services.
If you click on one service, you can get access to it's WSDL.
Developing an Axis2 service
Okay, let's develop our hello world axis2 service and deploy it.Create a folder structure as bellow,
Create a class "HelloService.java" as bellow and save under "Service" directory.
Create a service descriptor "Services.xml" as bellow and save under "Service/target/META-INF" directory.
Run the following command from "Service" directory to compile the HelloService.java and move HelloService.class to target directory.
javac HelloService.java -d target/Run the following command from "Service/target" directory to package your service.
jar -cvf HelloService.aar *
Point the browser URL to http://localhost:8080/axis2/services/.
You will see that your HelloService is listed under deployed services.
Developing a client
Having our service up and running, lets develop a client to consume our service.Lets use wsdl2java tool to generate client stubs which will allow you to access the service.
You don't have to download wsdl2java separately. It is shipped with Axis2 itself. You can find it at "AXIS2_HOME/bin/wsdl2java.sh".
Create a directory "Client".
In your terminal, navigate to "Client" directory, and run the following command to generate client stubs using wsdl2java.
sh AXIS2_HOME/bin/wsdl2java.sh -uri http://localhost:8080/axis2/services/HelloService?wsdl
Two classes (HelloServiceStub.java and HelloServiceCallbackHandler.java) will be generated inside your "Client" directory in the following package hierarchy.
These two classes allow you to access the service that we have deployed earlier. Lets create our client.
Create a class "Client.java" inside the same package as the above two classes,
Lets compile client codes. Create a directory "target" inside your "Client" directory. In your terminal run the following command from your "Client" directory. It will compile all java files and move .class files to target directory.
javac -extdirs AXIS2_HOME/lib/ src/org/apache/ws/axis2/*.java -d target/Please note that we are setting all required jars to our class path in the above command.
Lets run our client. In your terminal, navigate to "Client/target" directory and run the following command.
java -Djava.ext.dirs=AXIS2_HOME/lib/ org.apache.ws.axis2.Client
You will get the following output in your terminal.
Response : Hello Raj
That's it. You have successfully implemented, deployed and consumed an axis2 service.
No comments:
Post a Comment