Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated Validation wiki entry to provide documentation on new error handling implementation

...

The component is pretty simple and straightforward; its configured with a schema document as followsand optionally an error handler implementing 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
Wiki Markup
{snippet:id=example|lang=xml|url=http://svn.apache.org/repos/asf/incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/example.xml}schema.xsd"/>
            <property name="errorHandler" ref="messageAggregatingErrorHandler"/>
        </bean>
    </sm:component>
</sm:activationSpec>

And here is the bean definition for the MessageAggregatingErrorHandler:

Code Block
xml
xml

<bean id="messageAggregatingErrorHandler" class="org.apache.servicemix.components.validation.MessageAggregatingErrorHandler">
    <constructor-arg index="0" value="Fault/payload/messages"/>
    <constructor-arg index="1" value="http://www.servicemix.org/fault"/>
    <constructor-arg index="2" value="false"/>
</bean>
</beans>

Constructor arg zero is the rootPath;
constructor arg one is the namespace; and
constructor arg two is an optional boolean value that if true will output stacktraces of the error messages into the fault xml.