Quantcast
Channel: web – Imran Tariq's Blog
Viewing all articles
Browse latest Browse all 33

Generate Java Axis 2 WebService CLIENT/SERVER

$
0
0

This is compete guide/tutorial to build axis 2 web service server/client side code and interaction of both.
It all works for me and I got successfull call to webservice and get response.
We will use axis2 eclipse plugins and WAR file for this purpose. We will use eclipse/IBM RAD as our IDE.

IDE

Eclipse / IBM RAD

Axis Plugin for eclipse
———————–
Axis2_Codegen_Wizard_1.3.0
Axis2_Service_Archiver_1.3.0

Axis2 WAR
———
axis_v1.4.war

Installing Axis2 WAR
——————–
I use websphere 7.0 server for this. Install axis2 WAR file on your server. After installing make sure its running.
Check its services and their wsdl file if any.
Some axis2 WAR files, given on axis2 websites did not work. You may need to add necessary jars file and change the class loader from parent to self first.
Make sure you are using same axis2 jar versions in all you plugins, code etc.

Installing Axis2 Plugin in eclipse
—————————-
Place both axis2 plugin “Axis2_Codegen_Wizard_1.3.0” and “Axis2_Service_Archiver_1.3.0” in eclipse plugins folder.
Restart eclipse and make sure eclipse read these plugin by checking file–>new–>other–>Axis2 Wizard. You will find both plugins there.
During the usage of these plugins if you find they are not working then reinstall them or try using other eclipse IDE.

TroublShooting
————–
Make sure all your directory paths are real i.e. they should not inclide and special character, else you can be caught in
unrealistic plugin behaviour.

Creating Concrete/DTO Classes
—————————–
Create a Java Project. Create classes having data members. Create a controller class that will have implemented methods.
Export its jar file to some folder. Now right click on your controller class and go to new–>other–>Axis2 Wizard–>Axis2 CodGen plugin.
Select option “Generate wsdl from java source file”. Click “next”. Add you exported jar file.
Your contoller class name will be visible in class name field. If its not then enter name there. Try loading class.
Add necessary jars that are required for build path. After class loading click next.
Leave these fields as it is or change them as you want and click next.

Give output folder path and finish.
This will generate wsdl file.

Generate Server Side Code from WSDL
———————————–
Go to file–>new–>other–>Axis2 Wizard–>Axis2 CodGen plugin.
Select option “Generate source code from java source file”. Click “next”. Give your wsdl file path and click next.
In the next screen from select custom from drop down box in “Codegen Option”. Check “Generate Server Side Code”.
Also check other check boxes below “Generate services.xml and Generate interface for skeleton”. Click next.
Give output path and click finish. It will generate server side code. It will also generate wsdl and services.xml in resources folder.
These will be useful in generating .aar file.

Implementing Server Side code
—————————–
Create new Java Project. Copy generated source code in it.
Write implementation logic for your methods probably be found in something like *Skeleton.java class. Export jar file of this server side code.

Generate .aar file
——————
This file will be generated and deployed in axis2 WAR file.
Go to file–>new–>Axis2 Wizard–>Axis2 Service Archiver. Give you class files location of sever side code. click next.
Give wsdl file path generated during generation of server side code. You will found it in resources folder. Click next.
Add exported jar file of server side code. Click next.
Give path of service.xml file generated during server side code generation in resources folder. Click next.
Give output file path and finish.

Installing .aar file in axis2 WAR
———————————
put generated .aar file in axis2 war–>WEB-INF–>Services folder. Reinstall/update axis2 WAR file on server.
Now hit axis2 services URL to make sure its properly deployed. It should be displaying wsdl file on your web browser.

Generate Client Side code
————————-
Go to file–>new–>other–>Axis2 Wizard–>Axis2 CodGen plugin.
Select option “Generate source code from java source file”. Click “next”.
Give your original wsdl file path generating from concrete/dto classes and click next.
In next screen click next leaving all fields as it is. Click next.
Give output path and click finish. It will generate client side code.

Implementing Server Side code
—————————–
Create new Java Project. Copy generated client source code in it.
Create a test class having main method in it. Create new instance of class named something like *Stub.java
Call your original methods from this instance after proper implementation and parameters.
If you get any exception related connection or URI then check your wsdl uri in *Stub.java class.
After proper calling you will get response.


Viewing all articles
Browse latest Browse all 33

Trending Articles