Sparkles

that were shone when I got tempered!

Create / Build / Package and Deploy web service(s) with Axis2

leave a comment »

Create a java project using the created WSDL mentioned post Create a WSDL for a WebService

Initially the project structure will be like mentioned below.

1_pub_projectstructure

Generate the server code using Axis2CodeGen pluggin :

Select File > Select New > Click Other…

Select Axis2 Code Generator under the Axis2 Wizrds and Click Next

Select Generate the Java Source code from the WSDL file option and Click Next

Provide the WSDL file location eg : /rezsystem/workspace/MathService/src/gradethree/wsdl/GradeThreeMath.wsdl Use Browse button if you need.

Select
CodeGen Option : custom
Generate Service Side Code
Generate a default services.xml
Generate interface for Skeleton

Provide an Output Path (eg : /home/namal/Desktop/WORKS/WS/Math/Grade3). Use Browse button if needed.

Click Finish.

Take generated files to the project

This will generate the files mentioned in the LHS of the below image. Put those files in to the project as mentioned in the RHS.
Here, I have added resources and the server code to a seperate package (gradethree) since I have an intension to add another WebService within this same Project. You need to modify the package declarations in the Server Code and the services.xml

2_pub_folder_structure

Implement the logics in the GradeThreeMathSkeleton class.

eg : for Addition Operation


public gradethree.org.tempuri.AdditionResponse Addition(gradethree.org.tempuri.AdditionRequest additionRequest0){

AdditionResponse additionResponse = new AdditionResponse();

int operand1 = additionRequest0.getOperand1();
int operand2 = additionRequest0.getOperand2();

additionResponse.setResult(operand1+operand2);
additionResponse.setRemarks("This is enough for Grade Three Addition!");

return additionResponse;

}

Packaging : Generate the aar and jar files using the build.xml

Ant task :

<echo>Building GradeThreeMath AAR</echo>
<delete dir="${classes}/META-INF" />
<copy toDir="${classes}/META-INF" failonerror="false">
<fileset dir="${resources}/gradethree">
<include name="*.xml" />
<include name="*.wsdl" />
<include name="*.xsd" />
</fileset>
</copy>

<jar destfile="${lib}/GradeThreeMath.aar">
<fileset dir="${classes}">
<include name="META-INF/**" />
</fileset>
</jar>

<jar destfile="${lib}/GradeThreeMath.jar">
<fileset dir="${classes}">
<include name="gradethree/**" />
</fileset>
</jar>

So, this will return the GradeThreeMath.jar and GradeThreeMath.aar as follows.

3_pub-packaging

 

Deploy :

You can deploy them as mentioned below
4_pub-dployment

Start the server.

WSDL : http://localhost:8081/axis2/services/GradeThreeMath?wsdl

You can test the service using the SOAP UI with above WSDL as below

5_pub_soapui

You can add another service also within the same project, build/package with another ant task and deploy as mentioned in the below project.

6_pbl

Project lin : https://github.com/namalfernandolk/MathService.git

Advertisements

Written by Namal Fernando

October 25, 2016 at 9:09 am

Posted in WebServices

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Ruth's Reflections

Contemplations from quakey quirky Christchurch

TED Blog

The TED Blog shares interesting news about TED, TED Talks video, the TED Prize and more.

Ziplok

Learn and discover simple things

Meihta Dwiguna Saputra's Knowledge Base

~In learning you will teach and in teaching you will (re)learn~

The Java Blog

Thoughts, tips and tricks about the Java programming language

Sparkles

that were shone when I got tempered!

%d bloggers like this: