ServiceMix Validation
The ServiceMix Validation component provides schema validation of documents using JAXP 1.3 and XMLSchema or RelaxNG.
| Availability
Note that this component is only available in releases >= 3.3. |
Installation
Installing the servicemix-validation component can be done in several ways:
- drop the installer zip in an hotdeploy directory monitored by ServiceMix
- using ant tasks
Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.
Creation
You can use Maven to create a service unit.
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-validation-service-unit \
-DgroupId=com.mycompany.myproduct \
-DartifactId=mycomponent.artifact
or simply use the smx-arch tool from ServiceMix's bin folder.
Endpoints
<validation:endpoint service="test:myAddressValidationService"
endpoint="addressValidationEndpoint"
schemaResource="classpath:address.xsd"
handlingErrorMethod="FAULT_FLOW" />
| Message Exchange Pattern
The endpoint can handle all MEPs. |
The following table shows the additional configuration possibilities of the endpoint.
| endpoint attributes
Name |
Type |
Description |
Default |
schema |
Class |
javax.xml.validation.Schema |
null |
schemaLanguage |
String |
the schema language |
http://www.w3.org/2001/XMLSchema |
schemaSource |
Class |
javax.xml.transform.Source |
null |
schemaResource |
String |
path to schema resource |
null |
handlingErrorMethod |
String |
the error handling mode |
FAULT_JBI |
errorHandlerFactory |
Class |
org.apache.servicemix.validation.handler.MessageAwareErrorHandlerFactory |
CountingErrorHandlerFactory |
|
For all xbean file endpoint configuration take a look at Xml schemas
The schemaResource
The schema resource can be defined in different ways:
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:
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
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:
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
You can the configure your endpoint to use your factory and handler instead the standard ones.
Example:
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:
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:
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)