0

I am trying to add custom validation against a generated request object for incoming JSON payload using the javax.validation framework and openapi-generator-maven-plugin in Mule ESB.

I am following the below mulesoft documentation :

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

I have added the below custom validation :

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

But when I amtrying to run the application ,it fails with the below message :

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.

Edit :

below is the xml configuration that I am now using :

<?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>
aled
  • 21,330
  • 3
  • 27
  • 34
souvikc
  • 991
  • 1
  • 10
  • 25

1 Answers1

2

The documentation that you are using is for Mule 3.9. That method is not compatible with Mule 4. To create a custom validator in Mule 4 you need to create a Mule Extension with the 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

aled
  • 21,330
  • 3
  • 27
  • 34
  • Hi aled, as suggested,i am now using the namespace with the validation and schema on the top,i have edited my original post with the entire xml configuration.Even now am facing the same issue.Can you please suggest where i am going wrong. – souvikc Dec 31 '20 at 07:06
  • Updated solution for Mule 4. – aled Dec 31 '20 at 18:03