如何验证 mule esb 中的架构?
How to validate Schema in mule esb?
我需要根据 XSD 架构验证传入的 XML 文件。是否有任何组件可以完成此任务?我怎样才能在 mule esb 中实现这一点?
请建议我对 mule 有点陌生。谢谢..,
您可以使用 XML Schema Validation filter.
你可以使用下面的例子:-
<mulexml:schema-validation-filter schemaLocations="yourSchema.xsd" returnResult="true" name="Schema_Validation"
doc:name="Schema Validation" />
并且可以参考您的 .xsd 文件,您的传入 XML 需要根据该文件进行验证。 Mule 有一个验证过滤器,它会为你做验证..
参考:- https://docs.mulesoft.com/mule-user-guide/v/3.7/schema-validation-filter
参考:- 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)
使用 .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"/>
我需要根据 XSD 架构验证传入的 XML 文件。是否有任何组件可以完成此任务?我怎样才能在 mule esb 中实现这一点?
请建议我对 mule 有点陌生。谢谢..,
您可以使用 XML Schema Validation filter.
你可以使用下面的例子:-
<mulexml:schema-validation-filter schemaLocations="yourSchema.xsd" returnResult="true" name="Schema_Validation"
doc:name="Schema Validation" />
并且可以参考您的 .xsd 文件,您的传入 XML 需要根据该文件进行验证。 Mule 有一个验证过滤器,它会为你做验证..
参考:- https://docs.mulesoft.com/mule-user-guide/v/3.7/schema-validation-filter
参考:- 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)
使用 .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"/>