Mule ESB 中的自定义验证

Custom validation in Mule ESB

我正在尝试使用 javax.validation 框架和 Mule ESB 中的 openapi-generator-maven-plugin 为传入的 JSON 负载针对生成的请求对象添加自定义验证。

我正在关注以下 mulesoft 文档:

https://docs.mulesoft.com/mule-runtime/3.9/building-a-custom-validator

我添加了以下自定义验证:

<validation:custom-validator doc:name="Validation" class="com.poltu.validation.CustomValidator" />

但是当我尝试 运行 应用程序时,它失败并显示以下消息:

Invalid content was found starting with element 'validation:custom-validator'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.

编辑:

下面是我现在使用的 xml 配置:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:validation="http://www.mulesoft.org/schema/mule/validation"
xmlns:xml-module="http://www.mulesoft.org/schema/mule/xml-module" 
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:java="http://www.mulesoft.org/schema/mule/java"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" 
xmlns:db="http://www.mulesoft.org/schema/mule/db" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" 
xmlns="http://www.mulesoft.org/schema/mule/core" 
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json 
http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/core 
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http 
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/db 
http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/ee/core 
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/java 
http://www.mulesoft.org/schema/mule/java/current/mule-java.xsd
http://www.mulesoft.org/schema/mule/xml-module 
http://www.mulesoft.org/schema/mule/xml-module/current/mule-xml-module.xsd
http://www.mulesoft.org/schema/mule/validation 
http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">


<db:config name="Database_Config" doc:name="Database Config" 
 doc:id="d31ea473-7b58-4d28-83b3-bed7e0bebf2c" >
    <db:oracle-connection host="localhost" user="system" password="system" 
instance="xe" />
</db:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener 
config" doc:id="78fddb86-0942-4ccf-a300-2d721291c964" basePath="/emp_service" 
  >
    <http:listener-connection host="0.0.0.0" port="8081" />
 </http:listener-config>
 <flow name="mule1Flow" doc:id="246fb555-ea4b-4b9f-bf2c-a332dc3a0ea1" >
    <http:listener doc:name="Add_emp_Listener" doc:id="a9d8ff2a-00a7-4759- 
 8c0f-c53b9211e0e9" config-ref="HTTP_Listener_config" path="add_emp" 
 allowedMethods="POST"/>
    <validation:custom-validator doc:name="validation" 
 class="com.poltu.validation.CustomValidator" />
    <db:insert doc:name="Insert" doc:id="d44b5680-ae0a-4e97-8c91- 
  9baba4039e7e" config-ref="Database_Config">
        <db:sql ><![CDATA[insert into emp_details 
  values(:emp_id,:emp_name,:emp_status)]]></db:sql>
        <db:input-parameters ><![CDATA[#[{
 "emp_id": payload.emp_id,
 "emp_name" : payload.emp_name,
 "emp_status" : payload.emp_status
  }]]]></db:input-parameters>
    </db:insert>
    <ee:transform doc:name="Transform Message" doc:id="7e7be7f4-c2fc-43f9- 
   8b76-bf63bf8ac51b" >
        <ee:message >
            <ee:set-payload ><![CDATA[%dw 2.0
 output application/json
  ---
 {
"status":"OK",
"response":"Created re bhaii...."
 }]]></ee:set-payload>
        </ee:message>
    </ee:transform>
    <logger level="INFO" doc:name="Logger" doc:id="647043ee-5a28-414e-898e- 
  dce291114c2c" message="response payload is -- #[payload.response]"/>
</flow>
</mule>

您使用的文档适用于 Mule 3.9。该方法与 Mule 4 不兼容。要在 Mule 4 中创建自定义验证器,您需要使用 Mule SDK for Java. Follow the instructions to create the module. Once your module builds, add a validator operation as described at https://docs.mulesoft.com/mule-runtime/4.3/migration-module-validation#custom_validator

创建一个 Mule 扩展