How to use Axis2 JSON

Some time back, I implemented JSON support for Axis2 and I’ve explained about the architecture and usage of it here. But in addition to the details provided in this article, there is something that I’ve missed. I’m going to explain it in this post.

When I was implementing this feature for Axis2, the main objective was to make it easy and efficient to get the incoming JSON string from the service. That’s why I’ve used OMSourcedElementImpl with an OMDataSource. When a message comes in, JSONOMBuilder creates an OMSourcedElementImpl using JSONDataSource. So the OMElement is not built until someone forcefully do that and the JSON string can be directly accessed from the JSONDataSource without converting it to XML.

Due to this decision, the OMElement built from the incoming JSON message doesn’t know the namespace of the incoming payload. Therefore, if you try to dispatch a JSON message from the RPCMessageReceiver, it will be failed providing “namespace mismatch” error. Therefore, only the RawXMLInOutMessageReceiver can be used for JSON services. So you have to get an OMElement as the parameter for the method.

You can have a look at the JSONIntegrationTest to have an idea about this. All the other important steps are provided in the above article.

Apache Axis2/Java Performance Results

Few days back, I did a performance test on Axis2/Java to compare performances of different kinds of services that can be created using Axis2. I used a service using ADB databinding, another service using Jaxbri databinding and another service using JAXWS. For simple scenarios, I tested for POJO services as well.

Test setup

* Services hosted on Tomcat 6
* Axis2 version : Trunk
* Apache bench
* Concurrency level : 30
* Measure : Requests per second
* JDK : 1.6
* OS : Ubuntu 9.04
* Memory : 8GB

Scenario 01 : Echo Integer

Five digit integer was used.


Scenario 02 : Echo String

Length of the string was varied to create 1KB, 5KB and 10KB payloads.


Scenario 03 : Echo complex type

An array of complex type objects were echoed. Class hierarchy consists of three levels. Tested for ADB, Jaxbri and JAXWS services using the same WSDL. Payload size was varied by increasing the number of elements in the array.

echo complex type

How to generate your JAXWS service from a WSDL using wsimport

If you have a WSDL file and want to generate a JAXWS service/client, this post will help you. You can use the wsimport tool which is shipped with JDK (1.5 onwards).

Install JDK on your machine and just try “wsimport” command in a shell. It will show you the help.

Here are the options it provides.

Usage: wsimport [options] <WSDL_URI>

where [options] include:
-b <path> specify jaxws/jaxb binding files or additional schemas (Each <path> must have its own -b)
-B<jaxbOption> Pass this option to JAXB schema compiler
-catalog <file> specify catalog file to resolve external entity references supports TR9401, XCatalog, and OASIS XML Catalog format.
-d <directory> specify where to place generated output files
-extension allow vendor extensions – functionality not specified by the specification.  Use of extensions may result in applications that are not portable or may not interoperate with other implementations
-help display help
-httpproxy:<host>:<port> specify a HTTP proxy server (port defaults to 8080)
-keep keep generated files
-p <pkg> specifies the target package
-quiet suppress wsimport output
-s <directory> specify where to place generated source files
-target <version> generate code as per the given JAXWS specification version. version 2.0 will generate compliant code for JAXWS 2.0 spec.
-verbose output messages about what the compiler is doing
-version print version information
-wsdllocation <location> @WebServiceClient.wsdlLocation value

wsimport stock.wsdl -b stock.xml -b stock.xjb
wsimport -d generated

Just as shown in the above 2nd example, generate .java files as well if you want to create a service out of this. Among these generate classes, there is a generated interface of you web service. Just implement that interface and that is your web service class. Then add the @WebService annotation at the top as follows.

serviceName = “ComplexService”,
targetNamespace = “;,
portName = “ComplexServiceHttpSoap11Endpoint”,
wsdlLocation = “ComplexService.wsdl”,
endpointInterface = “org.apache.axis2.complex.ComplexServicePortType”)

These details should be according to your WSDL’s definitions.