如何在mule esb中验证Schema?

时间:2015-09-10 06:52:44

标签: xml mule xsd-validation mule-component

我需要根据XSD Schema验证传入的XML文件。是否有任何组件可以实现这项任务?我怎样才能在mule esb中实现这一目标?

请建议我对骡子有点新意,谢谢..,

2 个答案:

答案 0 :(得分:1)

参考: - https://docs.mulesoft.com/mule-user-guide/v/3.7/schema-validation-filter

似乎无法在此处使用代码片段,如下所示,仍然会收到以下错误。

根据文档使用的代码段:

 <message-filter throwOnUnaccepted="true" doc:name="Message">
                            <mulexml:schema-validation-filter schemaLocations="GetMasterOrganizationRecordByIDRequest.xsd" returnResult="false"/>
                        </message-filter>

用于验证的架构如下:

    <xs:element name="CustMDGetRequest" type="CustMDGetRequestType"/>

    <xs:complexType name="CustMDGetRequestType">
        <xs:sequence>  
            <xs:element name="CallingSourceSystem" type="xs:string" maxOccurs="1" minOccurs="1"/>
            <xs:element name="SourceSystemId" type="xs:string" maxOccurs="1" minOccurs="1"/>
            <xs:element name="SourceSystemNm" type="xs:string" maxOccurs="1" minOccurs="1"/>
            <xs:element name="IncludeDefaultAttributesForSourceTypes" type="xs:boolean" maxOccurs="1" minOccurs="0"/>
            <xs:element name="SourceTypesToBeIncluded" type="xs:string" maxOccurs="1" minOccurs="0"/>
            <xs:element name="Filters" type="FiltersType" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="AsynchronousRequestId" type="xs:string" maxOccurs="1" minOccurs="0"/> 
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="FiltersType">
        <xs:sequence>
            <xs:element name="Name" type="xs:string" maxOccurs="1" minOccurs="1"/>
            <xs:element name="Values" type="xs:string" maxOccurs="1" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>

收到错误:

org.mule.api.routing.filter.FilterUnacceptedException: Message has been rejected by filter.


------
ERROR 2017-05-24 21:01:14,887 [[eip-vcits-mdm-processes-proxy].HTTP_Listener_Configuration1.worker.01] org.mule.exception.CatchMessagingExceptionStrategy: 
********************************************************************************
Message               : Message has been rejected by filter.
Payload               : <?xml version="1.0" encoding="UTF-8"?>
                        <CustMDGetRequest>
                                                <CallingSourceSystem>AUTOPUBLISH</CallingSourceSystem>
                                                <SourceSystemId>348109</SourceSystemId>
                                                <SourceSystemNm>CUSTMD</SourceSystemNm>
                                                <IncludeDefaultAttributesForSourceTypes>true</IncludeDefaultAttributesForSourceTypes>
                            </CustMDGetRequest>

Payload Type          : java.lang.String
Filter                : org.mule.module.xml.filters.SchemaValidationFilter@435baa89 (null)
Element               : /eip-vcits-mdm-processes-proxy-templateFlow/processors/1/0/1/0/3 @ eip-vcits-mdm-processes-proxy:eip-vcits-mdm-processes-proxy.xml:43 (Message)
Element XML           : <message-filter throwOnUnaccepted="true" doc:name="Message">
                        <mulexml:schema-validation-filter schemaLocations="GetMasterOrganizationRecordByIDRequest.xsd" returnResult="false"></mulexml:schema-validation-filter>
                        </message-filter>
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.routing.filter.FilterUnacceptedException: Message has been rejected by filter.
    at org.mule.routing.MessageFilter.filterUnacceptedException(MessageFilter.java:113)

答案 1 :(得分:1)

使用.xsd进行架构验证对我没有用,但使用正则表达式进行验证对我有用,如下面显示的上述问题陈述所示。

<set-variable variableName="CallingSrcSys" value="#[xpath3('//CallingSourceSystem')]" doc:name="Variable-callingSrcSystem"/>
                <validation:matches-regex value="#[flowVars.CallingSrcSys]" regex="^[a-zA-Z]{0,14}+$" doc:name="Validation-CallingSrcSys"/>
                <set-variable variableName="MandatoryFieldRestrictionLevel" value="#[xpath3('//MandatoryFieldRestrictionLevel')]" doc:name="var-MandatoryFieldRestrictionLevel"/>
                <validation:matches-regex value="#[flowVars.MandatoryFieldRestrictionLevel]"  doc:name="Validation-MandatoryFieldRestrictionLevel" regex="^\s*\d*\s*$"/>
                <set-variable variableName="MinimumSearchScore" value="#[xpath3('//MinimumSearchScore')]" doc:name="var-MinimumSearchScore"/>
                <validation:matches-regex value="#[flowVars.MinimumSearchScore]" regex="^[a-zA-Z]{0,14}+$" doc:name="Validation-MinimumSearchScore"/>