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

validation

Created by dsosnoski. Last edited by dsosnoski, 355 days ago. Viewed 2,764 times. #8
attachments
handler.zip (16503)
validate.mar (5909)
Here's a module you can use for schema validation of messages going in and out of an Axis2 service. It only works at present if you're using Java 5 (Java 6 should also work, but I haven't tried it). To use it, drop the validate.mar file into the modules directory of your Axis2 server repository (the webapps/axis2/WEB-INF/modules directory of your Tomcat installation, when deploying Axis2 as a war file on Tomcat). Then for each service you want to have validated, add the following lines to the services.xml file inside your service .aar file (I don't know if order matters, but I generally add module information following the <operation> definitions):

<module ref="validate"/>
    <parameter name="validationSchema">file:///home/.../schema.xsd</parameter>

Where the value of the "validationSchema" parameter is the URL to access the schema definition for your service. Note that you must have a separate schema file for this as of now, though in the future it may support automatic schema extraction from WSDL. Note also that schemas are cached for efficiency, so if you redeploy your service with a different schema you need to either restart your Axis2 server or change the schema name in order to make sure it is reloaded.

Validation information is output to the log, so in order to use this you need to have logging enabled. The validator outputs at the "INFO" logging level, and with logging enabled you should see messages of this form in the log:

2007-05-17 23:38:05,209 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'getItem' body element for service LibraryServer
2007-05-17 23:38:05,346 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'getItemResponse' body element for service LibraryServer
2007-05-17 23:38:05,552 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'getTypes' body element for service LibraryServer
2007-05-17 23:38:05,569 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'getTypesResponse' body element for service LibraryServer
2007-05-17 23:38:05,695 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'addItem' body element for service LibraryServer
2007-05-17 23:38:05,710 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'addItemResponse' body element for service LibraryServer
2007-05-17 23:38:05,791 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'addItem' body element for service LibraryServer
2007-05-17 23:38:05,947 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'addItem' body element for service LibraryServer
2007-05-17 23:38:05,955 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'addItemResponse' body element for service LibraryServer
2007-05-17 23:38:06,085 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'getItemsByType' body element for service LibraryServer
2007-05-17 23:38:06,097 INFO  com.sosnoski.axis2.handler.ValidateHandler - Successfully validated 'getItemsByTypeResponse' body element for service LibraryServer

If there's a validation error the validator will dump the entire message to the log. It will also dump the entire message to the log if "DEBUG" logging level is enabled for the validator class, which you can do in the log4j.properties file with a line of the type:

# Set the validation logger to DEBUG
log4j.logger.com.sosnoski.axis2.handler=DEBUG

Testing this helped me find some subtle bugs in the JiBX code generation for Axis2, so if you're using it with JiBX you'll want to upgrade to the latest version of the axis2-jibx.jar. You can find these for the 1.1.1 and 1.2 releases of Axis2 at axis2-jibx. You'll also want to use the JiBX jar files available on the same page, replacing those in your Axis2 installation (including your Axis2 server lib directory).

Find this module useful? It's one of the examples from my >>Axis2 training class. If you're interested in learning more about working with Axis2, >>Contact me to enquire about arranging a class for your organization.

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