This document describes using JiBX data binding with Axis2. JiBX differs from the other data binding techniques supported by Axis2 in that it allows you to use your own Java data objects (as opposed to Java data objects generated from a schema definition). JiBX also provides a nicer form of unwrapped Web services interface than is supported by the other data binding techniques. On the downside, JiBX requires more setup than the other data binding techniques - in particular, you need to come up with a set of data classes and a binding definition in order to work with JiBX in Axis2.
JiBX support for Axis2 and Web services in general is continuing to evolve. This page covers the basics of using JiBX with Axis2 as of the current release. Check the JiBX Axis2 Wiki page for updated information about using JiBX with Axis2.
JiBX data binding supports fast and flexible conversions between plain old Java objects (POJOs) and XML. JiBX uses a mapped binding approach that's based on binding definition documents you provide. This approach let's you customize the way your Java objects are converted to and from XML. You can even define multiple bindings to use the same Java objects with different XML representations. These features make JiBX especially useful if you're developing a Web service based on existing Java code, or when you need to support multiple XML representations for a Web service (as when you're using versioned schema definitions).
Axis2 supports using JiBX with your Web services, including generating the necessary linkage code for both client and server sides. However, the Axis2 support for JiBX does not currently include code generation from the schema for a Web service - you need to provide your own data classes and JiBX binding definition, and you also need to make sure that the binding definition matches the XML structures defined for your Web service. The JiBX project provides some basic tools to help with code generation from schema, binding generation from Java classes, and schema generation from the combination of Java classes and a binding definition. In the future, improved versions of these tools will be integrated directly into the Axis2 framework support, but for now you're on your own with this part of the setup.
You can use JiBX data binding both to expose existing Java code as a service, and to build a client for an existing service. This document runs through the sequence of steps involved for each of these cases, just to help users understand the basic approach to working with JiBX in Axis2. You can find full instructions on the standard JiBX parts of this sequence on the JiBX Web site.
Axis2 support for JiBX currently only works with the document-literal (doc/lit) form of Web services definitions. Doc/lit Web services generally use particular schema elements as input and output from each operation, and the Axis2 support for JiBX assumes this structure (which is also the structure required for compatibility with the WS-I Basic Profile).
A popular subset of doc/lit Web services use a form called "wrapped". Wrapped doc/lit Web services define service operations that correspond to method calls, using input and output element names based on the method name and embedding the actual parameter values for the method call within the input element.
When used with Axis2, JiBX supports both general doc/lit and wrapped service definitions. Wrapped service definitions can be "unwrapped" during code generation to provide a greatly simplified interface. JiBX unwrapping of service definitions is not compatible with the unwrapping support for other data binding frameworks used with Axis2, but most users will find the JiBX approach easy and convenient. See the JiBX Unwrapped Example and the JiBX Document/Literal Example pages for a detailed comparison of the two forms of service interface.
Here's the sequence of steps for using JiBX with Axis2 to expose existing Java code as a Web service:
If you use a wrapped interface for your Web service you can expose method calls in your existing code directly as operations in the service. In this case you normally just use your existing data objects with JiBX data binding, and add schema definitions for the wrapper elements. See the JiBX Unwrapped Example page for more details on how this works.
If you use a non-wrapped interface for your Web service you need to define classes to hold the data input and output from each operation. In this case these holder classes need to be included in the JiBX binding definition. See the JiBX Document/Literal Example page for more details on this case.
Here's the sequence of steps for using JiBX with Axis2 to implement a client for an existing Web service (or the actual service, when you've been supplied with the WSDL your service is to implement):
As with the starting from Java case, there are some differences in the handling depending on whether your service definition fits the wrapped form. See the JiBX Unwrapped Example and JiBX Document/Literal Example pages for more details.
To run the WSDL2Java tool for JiBX data binding you need:
If you want to use the unwrapped form of interface you also need to specify the -uw option to WSDL2Java. In this case your JiBX binding definition must include abstact mappings for all the complex objects which correspond to method parameters, and each abstract mapping must specify a type-name attribute that matches the schema complexType used in the WSDL. You can also use formats in the binding definition to define the handling of schema simpleTypes. Schema types corresponding to Java primitives and simple objects with built-in JiBX conversions are handled automatically, and if all the parameter and return values in your wrapped WSDL are of these types you don't even need a JiBX binding definition. This is the one case where the -Ebindingfile {file} parameter is not needed.
If you're not unwrapping the interface, you must use a JiBX binding definition and it must include a concrete mapping for each element used as input or output by any operation.
Work is in-progress on better tools to support generating Java classes and corresponding JiBX binding definitions from an input schema, and also for generating binding+schema generation from existing code. These features will be integrated into the Axis2 JiBX support when they are available. Check the JiBX project site for updates on JiBX, and the JiBX Axis2 Wiki page for updated information about using JiBX with Axis2.