Tips and tricks for using JiBX
start > axis2-jibx > example

example

Created by dsosnoski. Last edited by dsosnoski, 358 days ago. Viewed 8,663 times. #13
attachments
jibx-library.zip (18194)
The Axis2 1.1.1 distribution includes a trivial example of using JiBX in the quick start guide, along with some more detailed discussion of how JiBX bindings work with the WSDL2Java code generation in the "JiBX Data Binding" section of the documentation (at branch11/xdocs/1_1/jibx/jibx-codegen-integration.html from the root of your Axis2 1.1.1 installation).

I've attached a more detailed example of JiBX unwrapped handling, which you can try for yourself. This one uses two different namespaces (as with many WSDLs), one for the wrapper elements and one for the actual application data. It also includes a Fault demonstration (which has some confusing aspects, discussed at Axis2 Faults). The example application is a library service, which maintains information about books of various types. See Library Service for details of the service and unwrapped API.

To try the example, download the attachment and unzip it on your system. You'll also need the Axis2 1.1.1 and the JiBX 1.1.3 distributions installed on your system, a recent version of the Ant build tool, and an Axis2 1.1.1 server installation on a web server (such as Tomcat). Then just follow these steps:

  • Inside the unzipped root directory you'll find a build.properties file. Edit this to set the appropriate locations for the Axis2 1.1.1 and JiBX 1.1.3 installations on your system.
  • Open a console to the unzipped root directory. Execute "ant" from this console to run the basic build. This will go through several build steps, and if everything goes correctly will finish with "BUILD SUCCESSFUL" and an execution time.
  • Start the web server for your Axis2 server, then use the Axis2 Administration page to upload the generated jibx-library.aar file from the root directory of the example to the Axis2 server. If you have "hot deploy" enabled in the Axis2 server (the default), you're done with this step; if you've disabled "hot deploy", you'll need to restart the web server before going on.
  • If your Axis2 server is not at the URL >>http://localhost:8080/axis2 you also need to edit the supplied build.xml file. Near the end of the file there are a pair of commented lines:
<!--      <arg value="localhost"/>
      <arg value="8800"/>  -->
These are normally used to change the port used for accessing the service in order to capture the message exchange using Tcpmon or a similar tool, but can also be used to specify the Axis2 server host and port. Just uncomment these lines (by removing the "<!--" at the start, and the "-->" at the end, being careful to only modify these two specific lines!) and change the values as appropriate to your system.
  • Give the Axis2 server a moment to activate the uploaded service, then back in the example root directory console, execute "ant run". You should see the following output:
run:
     [java] Retrieved 'Infinity Beach'
     [java] Retrieved 3 types:
     [java]  'java' with 3 books
     [java]  'scifi' with 3 books
     [java]  'xml' with 2 books
     [java] Added 'The Dragon Never Sleeps'
     [java] Failed adding 'This Should Not Work' with ISBN '0445203498' - matches existing title 'The Dragon Never Sleeps'
     [java] Asynchronous operation took 102 millis
     [java] Retrieved 4 books of type 'scifi':
     [java]  'Infinity Beach'
     [java]  'Aristoi'
     [java]  'Roadmarks'
     [java]  'The Dragon Never Sleeps'
The example includes WSDL, JiBX bindings, and code for everything. The start of the build.xml file gives a description of the directory structure used by the example, and also includes comments about the various steps involved in the build.

Most of the code is fairly straight-forward, but the Fault handling part can be very confusing. See Axis2 Faults for details on this part of the example.

For this example I chose to use two separate binding definitions corresponding to the different namespaces used in the WSDL. The main binding definition, binding.xml, just includes the separate wsdl-binding.xml and types-binding.xml. You don't need to separate out the bindings in this way, but it's convenient when you're using multiple namespaces.

You can compare the JiBX client, ADB client, and XMLBeans client code for this example to see how the client programming style is effected by the choice of data binding framework. The ADB client and XMLBeans client pages also have zip files attached for the corresponding versions of the example, to you can try them out for yourself. As with this JiBX version, you'll need to modify the build.properties file for each example to build correctly on your system.

The different versions of the example also include Eclipse projects for the clients and servers. To use these, just import each existing project into your Eclipse workspace. These projects rely on a User Library definition for Axis2 which includes all the files in the Axis2 distribution /lib directory. To set this up, you'll need to go open the Eclipse Preferences dialog to the Java/Build Path/User Libraries page, create the new library, and add all the jars to that library.

Need more help? I (Dennis Sosnoski) am going to be making a training trip to the U.S. in June, and one to Australia in July. On these trips I'll be providing training classes for corporate clients covering Axis2 and JiBX as well as the more general issues of moving organizations to a SOA approach (see the SOA for Developers page for more details on the latter). These examples are actually material taken from my >>Axis2 training class, so they serve as a sample of what you can expect from the training. Feel free to >>contact me to enquire about arranging a stop with your organization.

no comments
snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt