JSON web service with Java and Axis2

I have recently met a client who asking me to rebuild their legacy product using Java web service.
They want it modular and easy to use. The first thing crossed my mind is using restful approach.

But there is only thing that bothers me, Java restful approach is using XML!, I would prefer a simpler way to communicate, easy to understand and parsed data, so Jsonit is. I start google-ing a little and came across this excellent blog Json web service with Java and Axis2?
href=”http://www.marcusschiesser.de/2009/01/building-a-json-web-service-with-java-and-axis2/”>Building a Json web service with Java and Axis2.

I read the blog but it seem there some minor problem which they(he and the blog commenter) already solved.

So I am not here to revise on anything just to sum it up so it will be easier for you to build a Json web service with Java and Axis2.
I am using Java 1.7 and Apache Tomcat 7.0.

The steps are not so different with my reference blog, but I have minor modification on the steps.
1. Download the Axis2 war that includes jetisson patch and DynamicRespondHandler Axis2 Module here

Note that the Axis2 above is pre-configure,but still I would like to show what the changes are:
– Added module reference to the axis2.xml file

<br />&lt;module ref="DynamicResponseHandler"/&gt;<br />

- Added Json Message formatters

<br />&lt;messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/&gt;<br />&lt;messageFormatter contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/&gt;<br />

- Added Json Message builders

<br />&lt;messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder"/&gt;<br />&lt;messageBuilder contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/&gt;<br />

2. Download you favorite Java application server, in this case I am using Apache Tomcat 7.0.
3. Deploy Axis2 war to your application server, in my case I just copy the Axis2 war to Tomcat`s webapps folder.
4. Start your application server and open this URL using your web browser (your URL might slightly different then mine, depend on your HTTP port setting on your application server):

http://localhost:8080/axis2/services/Version/getVersion?response=application/json
your browser should shows this:

So that is the start, I hopefully can post more about this in the future. Cheers.

Reference: JSON web service with Java and Axis2 from our JCG partner Djaka Pribadi Maulana at the A.K.A Self notes blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


3 + = ten



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close