Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Warning
titleWarning

This component has been deprecated in favor to servicemix-validation component.

The validation component provides schema validation of documents using JAXP 1.3 and XMLSchema or RelaxNG.

The component is pretty simple and straightforward; its configured with a schema document and optionally an error handler factory implementing the MessageAwareErrorHandlerFactory interface. This factory produces an error handler which conforms to the MessageAwareErrorHandler interface.  If the inbound document is valid, it continues on its way to the ultimate destination. Otherwise a fault is returned in the message exchange.

ServiceMix configuration using the default error handler:

Code Block
xml
xml
<sm:activationSpec componentName="SchemaValidator" service="foo:SchemaValidator" endpoint="SchemaValidator">
    <sm:component>
        <bean class="org.apache.servicemix.components.validation.ValidateComponent">
            <property name="schemaResource" value="classpath:org/apache/servicemix/components/validation/schema.xsd"/>
        </bean>
    </sm:component>
</sm:activationSpec>

The default error handler simply counts the number of warnings, errors and fatal errors and if the number of errors and fatal errors is greater than zero then a fault message is returned. Another implementation is available which will capture the messages and output them in an xml format as below:

Code Block
xml
xml
<rootPath xmlns="namespace">
    <warning><![CDATA[ warning message ]]></warning>
    <error><![CDATA[ error message ]]></error>
    <fatalError><![CDATA[ fatal error message ]]></fatalError>
</rootPath>

Each warning, error or fatal error message will produce a node as shown above. The rootPath represents an arbitrarily deep node path at which to locate the message nodes. The root element also has a default xml namespace attached to it. The ServiceMix configuration for this component is outlined below:

Code Block
xml
xml
<sm:activationSpec componentName="SchemaValidator" service="foo:SchemaValidator" endpoint="SchemaValidator">
    <sm:component>
        <bean class="org.apache.servicemix.components.validation.ValidateComponent">
            <property name="schemaResource" value="classpath:org/apache/servicemix/components/validation/schema.xsd"/>
            <property name="errorHandlerFactory" ref="messageAggregatingErrorHandlerFactory"/>
        </bean>
    </sm:component>
</sm:activationSpec>

And here is the bean definition for the MessageAggregatingErrorHandler (Valid for ServiceMix 3.1 only):

Code Block
xml
xml
<bean id="messageAggregatingErrorHandlerFactory" class="org.apache.servicemix.components.validation.MessageAggregatingErrorHandlerFactory">
    <property name="rootPath" value="Fault/payload/messages"/>
    <property name="namespace" value="http://www.servicemix.org/fault"/>
    <property name="includeStackTraces" value="false"/>
</bean>

Only the first two properties are mandatory, the includeStackTraces property will default to false and is included in the above configuration to highlight it's use.  If it is set to true the error handler will output stacktraces of the error messages into the fault xml.