Mule: xml schema-validation-filter where custom errorHandler fails

I am using filter-validation-checkers inside the cpu chain on a thread and I want to set my own error handler so that I can store invalid XML strings, but the problem is that my "schemaErrorHandler" is NEVER executed.

Note. My own resource editor, which is set up similarly to the one below, has no problem.

I've already tried to wrap the filter-validator-filter from the message filter and remove the throwOnUnaccepted = "true" atribbute from it, but the schemaErrorHandler never gets executed.

Is this a bug or am I missing something? Also no JIRA related to this was found.

XML

    <processor-chain>
        <message-filter onUnaccepted="TextValidator">
            <mxml:is-xml-filter />
        </message-filter>
        <message-filter throwOnUnaccepted="true">
            <mxml:schema-validation-filter errorHandler-ref="schemaErrorHandler" resourceResolver-ref="schemaResourceResolver" schemaLocations="mySchema.xsd"/>
        </message-filter>
    </processor-chain>

    <spring:bean id="schemaResourceResolver" name="schemaResourceResolver" class="my.app.SchemaResourceResolver"/>
    <spring:bean id="schemaErrorHandler" name="schemaErrorHandler" class="my.app.SchemaErrorHandler"/>

      

SchemaErrorHandler.java

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class SchemaErrorHandler implements ErrorHandler {

private List<Object> allErrors = new ArrayList<>();

public List<Object> getAllErrors() {
    return allErrors;
}

public void setAllErrors(List<Object> allErrors) {
    this.allErrors = allErrors;
}

@Override
public void error(SAXParseException arg0) throws SAXException {
    System.out.println(arg0.getMessage());
    allErrors.add(arg0);

}

@Override
public void fatalError(SAXParseException arg0) throws SAXException {
    System.out.println(arg0.getMessage());
    allErrors.add(arg0);
}

@Override
public void warning(SAXParseException arg0) throws SAXException {
    System.out.println(arg0.getMessage());
    allErrors.add(arg0);
}

}

      

+3


source to share


1 answer


you need to use a different approach to do the work of the thread. Attaching example xml

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
    xmlns:http="http://www.mulesoft.org/schema/mule/http"     xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core     http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http     http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml     http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<spring:beans>
    <spring:bean id="schemaErrorHandler" name="schemaErrorHandler"
        class="SchemaErrorHandler" />
</spring:beans>

<flow name="xml_schemaFlow1" doc:name="xml_schemaFlow1">
    <file:inbound-endpoint path="/home/anil/deleteme/xsd/file"
        responseTimeout="10000" doc:name="File" />



    <message-filter name="asdf" onUnaccepted="invalidRelationXmlFlow"
        doc:name="Message">
        <mulexml:schema-validation-filter
            schemaLocations="/home/anil/deleteme/xsd/xsd/abc.xsd"
            errorHandler-ref="schemaErrorHandler" returnResult="true"
            doc:name="Schema Validation">
        </mulexml:schema-validation-filter>
    </message-filter>



    <echo-component doc:name="Echo" />
</flow>

<flow name="invalidRelationXmlFlow" doc:name="invalidRelationXmlFlow">
    <logger level="INFO" doc:name="Logger" message="hello"/>

</flow>

      



This will give you a mule warning, but will work. well. If the file validation fails, invalidRelationXmlFlow will be called.

0


source







All Articles