Using AXIS2 to pass JSON data

Source: Internet
Author: User

Axis2 is currently the most popular WebService engine. WebService are used in a number of different scenarios. For example, you can use WebService to publish a method for a server-side Java class to be invoked using a different client. This can effectively integrate a variety of different technologies to complete the application system. WebService is also often used in SOA to exchange data for various parts of the SOA. This article focuses on how to use the AXIS2 engine to deliver JSON data.

The blogger himself is looking for articles about Web service because of the project needs. But because bloggers are not familiar with the web, many of them are based on online tutorials. There may be many places that are wrong. And I ask you to Haihan.

First, according to the "Axis2 WebService Novice Super-Detailed tutorial" This document set up the AXIS2 development environment. Then I want the server to pass the JSON data, and then find the following two data: "JSON Web Service with Java and Axis2" and "Building a JSON Web service with Java and Axis2"

These two articles are written by foreigners, the content is similar, but not detailed enough, not to explain the specific operation. The following one is written by the Chinese people "Axis2 and Android JSON (Gson) communication Data", this document method is also in accordance with the above two articles of the method, specifically to explain the operation of each step. This article on this basis, will be described below each step, and will be part of the data uploaded to the Baidu cloud disk, convenient for you to download.

Step one: Follow the 1 method to install the AXIS2 in a methodical manner. The required download of the Axis.war package and eclipse of the two plug-ins will be placed in the Baidu cloud disk.
: Http://pan.baidu.com/s/13ThAk

Step two: Download the Dynamicresponsehandler (Wso2dynamic-response-1.5.mar) module and copy it to web-inf/modules in the WebService project. Add the Wso2dynamic-response-1.5.mar to the Modules.list file.
: http://pan.baidu.com/s/1gm56z

Step three: Download Jettison 1.2 and Jettison-1.2-patched.jar, put the module in Web-inf/lib, delete the Jettison-1.0-rc2.jar.
: In the package that is downloaded in the second step.

Fourth step: Locate the Tomcat\webapps\axis2\web-inf\conf\axis2.xml file and add the XML

<module ref="DynamicResponseHandler"/>

Fifth step: Add the JSON message format in Axis2.xml, it must be in the <messageFormatters> tag, the original tag is in the original tag Riga, if not the original tag is added:

<messageFormatters>

<messageformattercontenttype= "Application/json" class= "Org.apache.axis2.json.JSONMessageFormatter"/>

<messageformattercontenttype= "Application/json/badgerfish" class= " Org.apache.axis2.json.JSONBadgerfishMessageFormatter "/>

</messageFormatters>

Sixth step: Add JSON message compilation in Axis2.xml, it must be the <messageBuilders> tag, the original tag is added in the original label, if not the original tag is added:

<messageBuilders>

<messagebuildercontenttype= "Application/json" class= "Org.apache.axis2.json.JSONOMBuilder"/>

<messagebuildercontenttype= "Application/json/badgerfish" class= " Org.apache.axis2.json.JSONBadgerfishOMBuilder "/>

</messageBuilders>

After performing the above steps, open the Tomcat server and enter the test Url:http://localhost:8080/axis2/services/version/getversion?response=application/json in the browser

The browser will return the following: The value returned is:

{"return":"Hi - the Axis2version is 1.6.2"}

This completes the JSON value configuration of the AXIS2.

Using AXIS2 to pass JSON data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.