我正在探索Mule schema-validation-filter ,它用于根据xsd架构验证XML输入....我不知道如何实现此架构验证过滤器 ...我想过将它用于Web服务的传入SOAP请求。所以,我有以下方法来验证SOAP请求: -
<mulexml:schema-validation-filter name="Schema_Validation" schemaLocations="MainData.xsd" returnResult="true" doc:name="Schema Validation" />
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
<async doc:name="Async">
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<message-filter doc:name="filter to validate xml against xsd" throwOnUnaccepted="true" >
<filter ref="Schema_Validation"/>
</message-filter>
<logger message="Doneeeeee" level="DEBUG" doc:name="Logger"/>
</async>
<cxf:jaxws-service validationEnabled="true" serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</flow>
但每当我使用SOAP UI测试服务时,我都会遇到以下异常: -
Root Exception stack trace:
org.mule.api.routing.filter.FilterUnacceptedException: Message has been rejected by filter. Message payload is of type: DocumentImpl
at org.mule.routing.MessageFilter.filterUnacceptedException(MessageFilter.java:96)
at org.mule.processor.AbstractFilteringMessageProcessor.handleUnaccepted(AbstractFilteringMessageProcessor.java:58)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:51)
at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:118)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:189)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:182)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:109)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:181)
at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:39)
at org.mule.work.WorkerContext.run(WorkerContext.java:286)
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:724)
我尝试在互联网上搜索以找到合适的方法来验证SOAP请求并使用此架构验证过滤器 ..但是没有找到解决方案...请帮助我,让我知道这是我正在做的验证SOAP请求的正确方法。过滤器期望什么类型的数据格式?以及如何使它工作?
更新了流程: -
<mulexml:schema-validation-filter name="Schema_Validation" schemaLocations="MainData.xsd" returnResult="true" doc:name="Schema Validation" />
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP"/>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<message-filter doc:name="filter to validate xml against xsd" throwOnUnaccepted="true" >
<filter ref="Schema_Validation"/>
</message-filter>
<cxf:jaxws-service validationEnabled="true" serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</flow>
通过删除异步块更新了流...但仍然得到相同的异常: - 过滤器拒绝了消息。消息有效内容的类型为:DocumentImpl
答案 0 :(得分:2)
我建议你使用
<mulexml:dom-to-xml-transformer />
而不是您在这里使用的object-to-xml转换器。在过滤器之前记录整个mule消息,以确保您没有将documentImpl对象发送到过滤器。使用dom-to-xml后,它应该是一个字符串。
试试这个:
<http:inbound-endpoint address="http://localhost:9002/test">
<cxf:proxy-service />
</http:inbound-endpoint>
<mulexml:dom-to-xml-transformer />
<logger level="INFO" message=""/>
<message-filter doc:name="filter to validate xml against xsd" throwOnUnaccepted="true">
<filter ref="Schema_Validation"/>
</message-filter>
这个cxf:proxy-service取出了soapenv:body的内容,并将其分配给mule消息的有效负载变量。因此,架构过滤器将能够验证您的有效负载,而无需肥皂信封和标头。
答案 1 :(得分:0)
通常cxf:jaxws-service validationEnabled="true"
就足够了。你是说这不验证SOAP主体吗?
另外,如果您想手动验证请求:
async
:如果您在侧面执行此操作并且在发生错误时实际上没有中断请求,那么验证的重点是什么?答案 2 :(得分:0)
所以,最后大卫建议,解决方法是确保XSD包含SOAP信封...所以我添加了以下内容,它对我有用: -
<import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>
参考: - How to fix soapenv:Envelope issue in XSD schema while validating with SOAP request/response