ServiceMix Validation
The ServiceMix Validation component provides schema validation of documents using JAXP 1.3 and XMLSchema or RelaxNG.
Maven Archetype
You can use Maven servicemix-validation-service-unit archetype to create a Validation service unit:
Code Block |
---|
mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-validation-service-unit \ -DarchetypeVersion=2010.01 \ -DgroupId=your.group.id \ -DartifactId=your.artifact.id \ -Dversion=your-version |
Once you've customized the service unit, simply install the SU:
Code Block |
---|
mvn install |
Info | ||
---|---|---|
Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
|
Endpoint Configuration
A Validation endpoint expects messages coming from the NMR and validate message payload using given schema.
Note | ||
---|---|---|
| ||
The endpoint can handle all MEPs. |
Code Block | ||||
---|---|---|---|---|
| ||||
<validation:endpoint service="test:myAddressValidationService" endpoint="addressValidationEndpoint" schemaResource="classpath:address.xsd" handlingErrorMethod="FAULT_FLOW" /> |
Info | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||
|
The schemaResource
The schema resource can be defined in different ways:
No Format |
---|
script="classpath:mySchema.xsd" OR script="file:///home/lhein/mySchema.xsd" |
The errorHandlerFactory
You can specify your own error handling factory which will be used to create an error handler for the validation.
All factories have to implement the interface org.apache.servicemix.validation.handler.MessageAwareErrorHandlerFactory. This interface
describes only one method:
Wiki Markup |
---|
{snippet:id=interface|lang=java|url=servicemix/smx3/trunk/deployables/serviceengines/servicemix-validation/src/main/java/org/apache/servicemix/validation/handler/MessageAwareErrorHandlerFactory.java} |
This method createMessageAwareErrorHandler() creates the error handler for validating the xml.
The MessageAwareErrorHandler is also a interface defining the methods needed for call back while validating a xml:
Wiki Markup |
---|
{snippet:id=interface|lang=java|url=servicemix/smx3/trunk/deployables/serviceengines/servicemix-validation/src/main/java/org/apache/servicemix/validation/handler/MessageAwareErrorHandler.java} |
You can the configure your endpoint to use your factory and handler instead the standard ones.
Example:
No Format |
---|
<validation:endpoint service="test:service3" endpoint="endpoint" schemaResource="classpath:schema.xsd" handlingErrorMethod="FAULT_FLOW"> <property name="errorHandlerFactory"> <bean class="org.apache.servicemix.validation.handler.MessageAggregatingErrorHandlerFactory"> <property name="rootPath" value="Fault/payload/messages"/> <property name="namespace" value="http://www.servicemix.org/fault"/> <property name="includeStackTraces" value="false"/> </bean> </property> </validation:endpoint> |
Available factories / handlers
CountingErrorHandlerFactory / CountingErrorHandler
This one is just counting warnings, errors and fatal errors. Depending on the set handlingErrorMethod it will throw an exception or deliver a fault string containing a xml like this:
No Format |
---|
<result> <warning>10</warning> <error>2</error> <fatal>0</fatal> </result> |
As you can see this factory / handler is just counting problems in the xml and delivers the result back.
MessageAggregatingErrorHandlerFactory / MessageAggregatingErrorHandler
This one captures messages from the validator and delivers them to the caller like this:
No Format |
---|
<rootPath xmlns="namespace"> <warning><![CDATA[ warning message ]]></warning> <error><![CDATA[ error message ]]></error> <fatalError><![CDATA[ fatal error message ]]></fatalError> </rootPath> |
handlingErrorMethod
There are 2 modes existing:
- FAULT_JBI - this is the default. A jbi exception is thrown on validation errors (depending on used MEP)
- FAULT_FLOW - the validation result will be sent in out / fault message (depending on used MEP)