I'm using a Mule schema validation filter to validate an incoming XML file against a given scheme. Below is my configuration for the schema component:
我正在使用Mule模式验证过滤器来验证传入的XML文件与给定的方案。下面是我对模式组件的配置:
<mulexml:schema-validation-filter schemaLocations="${app.home}/classes/schemas/Library.xsd" doc:name="Schema Validation"/>
< mulexml:schema-validation-filter schemalocation = " $ { app.home } /类/模式/库。xsd文档:name = "模式验证" / >
The issue I'm having is that when a file fails to validate against the schema, Mule silently blocks the message from continuing - i.e. no error/exception is thrown. Through a little experimentation I discovered that if I add the following to my log4j.properties file, I can see the 'errors' in the schema validation:
我遇到的问题是,当一个文件无法对模式进行验证时,Mule会无声地阻止消息的继续——也就是说,不会抛出错误/异常。通过一些实验,我发现如果我在log4j中添加以下内容。属性文件,我可以看到模式验证中的“错误”:
log4j.logger.org.mule.module.xml.filters.SchemaValidationFilter=DEBUG
log4j.logger.org.mule.module.xml.filters.SchemaValidationFilter =调试
Since these errors are 'DEBUG' level logs and no actual exception is thrown, my flow doesn't revert to the exception strategy I've configured.
由于这些错误是“调试”级别的日志,并且没有抛出任何实际异常,所以我的流不会恢复到我配置的异常策略。
So the question I have is...
所以我的问题是……
Is there something I can do here to make Mule revert to an exception strategy if there is an error in the schema validation? I've included a copy below of the debug logs that I see when a file fails to validate. Thanks in advance.
如果模式验证中出现错误,我是否可以做点什么来让Mule恢复到异常策略?我在下面包含了一个调试日志的副本,当文件失败时,我将看到它。提前谢谢。
DEBUG 2014-04-15 11:19:20,705 [[processes].orderInputFileConnector.receiver.01] org.mule.module.xml.filters.SchemaValidationFilter: SchemaValidationFilter rejected a message because it apparently failed to validate against the schema.
org.xml.sax.SAXParseException: cvc-pattern-valid: Value 'string' is not facet-valid with respect to pattern '[A-Z]{2}' for type 'countryISOA2'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.elementLocallyValidType(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.processElementContent(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.finishNode(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at org.mule.module.xml.filters.SchemaValidationFilter.accept(SchemaValidationFilter.java:107)
at org.mule.routing.MessageFilter.accept(MessageFilter.java:89)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:42)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:95)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
at org.mule.construct.AbstractPipeline$1.process(AbstractPipeline.java:112)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:95)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:54)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:26)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:70)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:65)
at org.mule.construct.AbstractPipeline$3.process(AbstractPipeline.java:204)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.SimpleMessageProcessorChain.doProcess(SimpleMessageProcessorChain.java:47)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.SimpleMessageProcessorChain.doProcess(SimpleMessageProcessorChain.java:47)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:54)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:26)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:70)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:65)
at org.mule.transport.AbstractMessageReceiver.routeEvent(AbstractMessageReceiver.java:473)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:226)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:208)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:200)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:187)
at org.mule.transport.file.FileMessageReceiver.moveAndDelete(FileMessageReceiver.java:560)
at org.mule.transport.file.FileMessageReceiver.access$400(FileMessageReceiver.java:62)
at org.mule.transport.file.FileMessageReceiver$2.process(FileMessageReceiver.java:410)
at org.mule.transport.file.FileMessageReceiver$2.process(FileMessageReceiver.java:406)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:20)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:34)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:18)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:58)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:48)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:54)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:44)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:44)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:52)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:32)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:17)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:113)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:34)
at org.mule.transport.file.FileMessageReceiver.processWithoutStreaming(FileMessageReceiver.java:405)
at org.mule.transport.file.FileMessageReceiver.processFile(FileMessageReceiver.java:397)
at org.mule.transport.file.FileMessageReceiver.poll(FileMessageReceiver.java:238)
at org.mule.transport.AbstractPollingMessageReceiver.performPoll(AbstractPollingMessageReceiver.java:219)
at org.mule.transport.PollingReceiverWorker.poll(PollingReceiverWorker.java:84)
at org.mule.transport.PollingReceiverWorker.run(PollingReceiverWorker.java:53)
at org.mule.work.WorkerContext.run(WorkerContext.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
UPDATE
更新
Following the answer provided by @RyanCarter (which worked), I've also found the following solution which doesn't give any errors inside of Mule Studio. It involves defining the Schema Validation Filter globally and referencing it inside a message filter like so:
根据@RyanCarter提供的答案(已经成功了),我还找到了以下解决方案,它不会在Mule Studio中出现任何错误。它涉及到全局定义模式验证过滤器,并在消息过滤器中引用它,如下所示:
<mulexml:schema-validation-filter name="myValidator".../>
<flow>
<message-filter throwOnUnaccepted="true">
<filter ref="myValidator"/>
</message-filter>
3 个解决方案
#1
8
You can wrap the schema-validation-filter in a message-filter and set throwOnUnaccepted to "true":
您可以将模式验证过滤器封装到消息过滤器中,并将throwonunacceptance设置为“true”:
<message-filter throwOnUnaccepted="true">
<mulexml:schema-validation-filter... />
</message-filter>
You can then use an exception-strategy to handle the exception.
然后可以使用异常策略来处理异常。
#2
1
The purpose of the filter is to stop the processing if the condition is no satisfied. They usually don't throw exception and disrupt the flow. If you have to get the exception and handle it then try using errorHandler-ref
property in the filter and point it to the spring bean that can handle the error.
过滤器的目的是在条件不满足时停止处理。它们通常不会抛出异常并中断流。如果您必须获得异常并处理它,那么请尝试在过滤器中使用errorHandler-ref属性,并将其指向可以处理错误的spring bean。
<mulexml:schema-validation-filter errorHandler-ref="" ></mulexml:schema-validation-filter>
Hope this helps.
希望这个有帮助。
#3
-1
If you want to use errorHandler-ref="" in schema validation just create a java component which implements ErrorHandler. In java component you can handle any kind of validation error and process accordingly. Here is the code snippet
如果希望在模式验证中使用ErrorHandler -ref="",只需创建一个实现ErrorHandler的java组件。在java组件中,您可以处理任何类型的验证错误并相应地进行处理。下面是代码片段
<mulexml:schema-validation-filter
schemaLocations="abc.xsd"
errorHandler-ref="Bean" returnResult="true" doc:name="Schema Validation"
name="xmlvalidation" schemaLanguage="http://www.w3.org/2001/XMLSchema" />
created BEAN in Mule as -
在Mule中创建了-
<spring:beans>
<spring:bean id="Bean" name="Bean" class="com.training.ErrorHandler"/>
</spring:beans>
create one java class and implement "org.xml.sax.ErrorHandler" like as below -
创建一个java类并实现“org.xml.sax”。错误处理器"像下面-
package com.training;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class ErrorHandler implements org.xml.sax.ErrorHandler{
public ErrorHandler() {
super();
// TODO Auto-generated constructor stub
}
@Override
public void warning(SAXParseException exception) throws SAXException {
System.out.println("do something here");
}
@Override
public void error(SAXParseException exception) throws SAXException {
System.out.println("do something here");
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
System.out.println("do something here");
}
}
}
#1
8
You can wrap the schema-validation-filter in a message-filter and set throwOnUnaccepted to "true":
您可以将模式验证过滤器封装到消息过滤器中,并将throwonunacceptance设置为“true”:
<message-filter throwOnUnaccepted="true">
<mulexml:schema-validation-filter... />
</message-filter>
You can then use an exception-strategy to handle the exception.
然后可以使用异常策略来处理异常。
#2
1
The purpose of the filter is to stop the processing if the condition is no satisfied. They usually don't throw exception and disrupt the flow. If you have to get the exception and handle it then try using errorHandler-ref
property in the filter and point it to the spring bean that can handle the error.
过滤器的目的是在条件不满足时停止处理。它们通常不会抛出异常并中断流。如果您必须获得异常并处理它,那么请尝试在过滤器中使用errorHandler-ref属性,并将其指向可以处理错误的spring bean。
<mulexml:schema-validation-filter errorHandler-ref="" ></mulexml:schema-validation-filter>
Hope this helps.
希望这个有帮助。
#3
-1
If you want to use errorHandler-ref="" in schema validation just create a java component which implements ErrorHandler. In java component you can handle any kind of validation error and process accordingly. Here is the code snippet
如果希望在模式验证中使用ErrorHandler -ref="",只需创建一个实现ErrorHandler的java组件。在java组件中,您可以处理任何类型的验证错误并相应地进行处理。下面是代码片段
<mulexml:schema-validation-filter
schemaLocations="abc.xsd"
errorHandler-ref="Bean" returnResult="true" doc:name="Schema Validation"
name="xmlvalidation" schemaLanguage="http://www.w3.org/2001/XMLSchema" />
created BEAN in Mule as -
在Mule中创建了-
<spring:beans>
<spring:bean id="Bean" name="Bean" class="com.training.ErrorHandler"/>
</spring:beans>
create one java class and implement "org.xml.sax.ErrorHandler" like as below -
创建一个java类并实现“org.xml.sax”。错误处理器"像下面-
package com.training;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class ErrorHandler implements org.xml.sax.ErrorHandler{
public ErrorHandler() {
super();
// TODO Auto-generated constructor stub
}
@Override
public void warning(SAXParseException exception) throws SAXException {
System.out.println("do something here");
}
@Override
public void error(SAXParseException exception) throws SAXException {
System.out.println("do something here");
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
System.out.println("do something here");
}
}
}