简体   繁体   中英

Mule esb 3.8 How to check if property exist in payload and validate it is guid (uuid)

I know how to validate property if its match regexp:

regex = "^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$"

for guid, but if its not send in payload - receiving error, is it a simple way to check if property exist and do validate only then? As per now I check with choice if its exist and if so then do validation, but interested if its more smarter way to do such as if I will have 20 properties to check its becomes very messy flow.

For example 3 validations at the moment: 在此处输入图像描述

You could use the Validations Module All validator which seems to cover this use case. Note that you can not customize the exception or message. If this is not acceptable then you could use individual validations in the flow instead.

Example:

  <validation:all doc:name="Validation">
    <validation:validations>
      <validation:is-not-empty doc:name="Validation" value="#[payload.firstName]" message="Firstname cannot be empty"/>
      <validation:is-not-empty doc:name="Validation" value="#[payload.lastName]" message="Lastname cannot be empty"/>
      <validation:is-number message="Not an adult" value="#[payload.age]" minValue="18" numberType="INTEGER"/>
      <validation:is-email email="#[payload.email]" />
      <validation:matches-regex message="Invalid SSN" value="#[payload.ssn]" regex="^(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$"/>
      <validation:validate-size value="#[payload.ssn]" min="11" max="11" message="SSN too short"/>
    </validation:validations>
  </validation:all>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM