2014-04-15 5 views
6

Ich benutze einen Mule-Schema-Validierungsfilter, um eine eingehende XML-Datei gegen ein bestimmtes Schema zu validieren. Im Folgenden finden Sie meine Konfiguration für die Schemakomponente:Mule - Wie man Mule dazu bringt, eine Ausnahme auszulösen, wenn die XML-Schema-Validierung fehlschlägt

<mulexml:schema-validation-filter schemaLocations="${app.home}/classes/schemas/Library.xsd" doc:name="Schema Validation"/>

Das Problem, das ich habe, ist, dass, wenn eine Datei gegen das Schema zu validieren fehlschlägt, Mule leise die Blöcke Nachricht aus fort - dh kein Fehler/Ausnahme: geworfen. Durch ein wenig Experimentieren entdeckte ich, dass, wenn ich die folgende meiner log4j.properties Datei hinzufügen, kann ich die ‚Fehler‘ in der Schemavalidierung sehen:

log4j.logger.org.mule.module.xml.filters.SchemaValidationFilter=DEBUG

Da diese Fehler ‚DEBUG‘ Level-Protokolle sind und Es wird keine tatsächliche Ausnahme ausgelöst. Mein Ablauf wird nicht auf die von mir konfigurierte Ausnahmestrategie zurückgesetzt.

So ist die Frage, die ich habe, ist ...

Gibt es etwas, was ich hier tun kann, um Mule auf eine Ausnahme Strategie zu machen zurück, wenn ein Fehler in dem Validierungsschema ist? Ich habe unten eine Kopie der Debug-Protokolle eingefügt, die ich sehe, wenn eine Datei nicht validiert werden kann. Danke im Voraus.

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

die von @RyanCarter vorgesehen Antwort verfolgt (was gearbeitet hat), habe ich auch festgestellt, die folgende Lösung, die keine Fehler innerhalb von Mule Studio nicht geben. Es geht um die Schemavalidierung Filter global definiert, und es in einem Nachrichtenfilter Referenzierung wie so:

<mulexml:schema-validation-filter name="myValidator".../> 

<flow>   
    <message-filter throwOnUnaccepted="true"> 
     <filter ref="myValidator"/> 
    </message-filter> 

Antwort

8

können Sie wickeln die Schema-Validierungs-Filter in einem Nachrichtenfilter und setzen throwOnUnaccepted auf "true":

<message-filter throwOnUnaccepted="true"> 
    <mulexml:schema-validation-filter... /> 
</message-filter> 

Sie können dann eine Ausnahme-Strategie verwenden, um den Griff Ausnahme.

+0

Danke @Ryan.Ich habe gerade diese Option ein Go gegeben, und ich bekomme eine Fehlermeldung "Verschachtelter Filter ist verpasst" auf dem '' Element? – danw

+0

Das ist nur Studio winseln :). Wenn Sie laufen es sollte funktionieren.Es ist für mich.Lassen Sie mich wissen –

+0

Ja, das hat funktioniert.Ich habe auch eine Alternative gefunden, die nicht zu den lästigen Studio-Fehler führt.Ich habe das zum ursprünglichen Beitrag hinzugefügt. – danw

1

Der Zweck des Filters ist die Verarbeitung zu stoppen, wenn die Bedingung nicht erfüllt ist. Sie werfen normalerweise keine Ausnahme und unterbrechen den Fluss. Wenn Sie die Ausnahme erhalten und damit umgehen müssen, versuchen Sie es mit der Eigenschaft errorHandler-ref im Filter und zeigen Sie sie auf die Spring Bean, die den Fehler behandeln kann.

<mulexml:schema-validation-filter errorHandler-ref="" ></mulexml:schema-validation-filter> 

Hoffe das hilft.

+0

Vielen Dank für Ihre Antwort, die ich habe nie mit einem Fehler auf diese Weise behandelt -. Haben Sie ein Beispiel von etwas ähnliches haben, dass ich verwenden oder anpassen können ? – danw

-1

Wenn Sie errorHandler-ref = "" in der Schema-Validierung verwenden möchten, erstellen Sie einfach eine Java-Komponente, die ErrorHandler implementiert. In Java-Komponente können Sie jede Art von Validierungsfehler behandeln und entsprechend verarbeiten. Hier ist der Code-Snippet

<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" /> 

erstellt BEAN in Mule als -

<spring:beans> 
    <spring:bean id="Bean" name="Bean" class="com.training.ErrorHandler"/> 
</spring:beans> 

eine Java-Klasse erstellen und „org.xml.sax implementieren.Fehlerbehandler“wie wie unten -

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

Es ist unklar wie antwortet das Die Frage - bitte fügen Sie einige Details hinzu. – cybermonkey