【问题标题】:How to use Mule schema-validation-filter for validating SOAP Request如何使用 Mule 模式验证过滤器来验证 SOAP 请求
【发布时间】:2015-07-21 14:49:45
【问题描述】:

我正在探索 Mule schema-validation-filter,它用于根据 xsd 模式验证 XML 输入......我不知道如何实现这个 schema-validation-filter ...我想将它用于针对 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 请求并使用此 schema-validation-filter .. 但没有找到解决方案...请帮助我,让我知道这是我验证 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

【问题讨论】:

    标签: xml web-services soap mule mule-studio


    【解决方案1】:

    我建议你使用

    <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消息的payload变量。因此,模式过滤器将能够在没有肥皂信封和标头的情况下验证您的有效负载。

    【讨论】:

      【解决方案2】:

      通常拥有cxf:jaxws-service validationEnabled="true" 就足够了。您是说这不会验证 SOAP 主体吗?

      另外,如果您想手动验证请求:

      • 不要这样做async:如果您在旁边进行验证并且在出现错误时实际上不中断请求,那么验证的意义何在?
      • 确保您用于验证的 XSD 验证整个 SOAP 信封,而不仅仅是正文。

      【讨论】:

      • 嗨,大卫,谢谢您的回复.. 我已经删除了异步,但问题是例外情况相同:- 消息已被过滤器拒绝。消息有效负载的类型为:DocumentImpl ...我不知道这意味着什么...我正在针对用于创建服务响应的同一个 xsd 进行验证...实现是否正确?异常是什么意思?...过滤器期望什么消息格式?最后,为什么它拒绝,因为我使用了与创建 Web 服务相同的 xsd?
      • 我将日志级别更改为调试并从控制台收到以下消息:- 找不到元素“soapenv:Envelope”的声明
      • 您需要在命名空间管理器中声明soapenv 和任何其他命名空间:mulesoft.org/documentation/display/current/XML+Namespaces
      • 嗨大卫......找到了解决方案......只需要在 xsd 架构中添加:-schemas.xmlsoap.org/soap/envelope" schemaLocation="schemas.xmlsoap.org/soap/envelope" > 和现在工作正常...非常感谢您的帮助
      • 这里是参考:- stackoverflow.com/questions/24224226/… .... 我发布它以防有人需要使用 XSD 验证 SOAP 请求..
      【解决方案3】:

      所以,最后正如大卫建议的那样,解决方案是确保 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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-14
        • 1970-01-01
        • 2018-10-18
        • 1970-01-01
        • 2018-04-15
        • 2011-04-30
        • 1970-01-01
        • 2010-11-05
        相关资源
        最近更新 更多