OSB-12C : Schema Validation : Static



We can use validate node in OSB to validate schema.

There was an option to validate the payload in OSB 11g but it was static, however from 12c there is a new feature included in the OSB validation activity that is validating the data dynamically. This will allow the user to validate the input data or other data dynamically based on certain condition. Thus the process can be stopped at the beginning itself the the data validation goes wrong. You have the option to save the validation result or raise an error.

Use case:
1. Create a WSDL based service
2. Add validate (static) to validate incoming request structure.
3. If any violation in request structure compared with schema, Error will be raised with proper error code and description.

Create new project and name it as ‘SchemaValidation_UseCase’.












Create folder and name it as ‘ValidateSchema_Service’ and sub folders in structure as shown in below image.




For this use case we have created two XSDs and placed it inside Resources -> XSD folder
EmployeeDetailsRequest.xsd
EmployeeDetailsResponse.xsd

And created a WSDL with help of these two XSDs and placed it inside Resources -> WSDL folder
EmpData.wsdl




Create a new WSDL based pipeline service and name it as ‘ValidateSchema_ServicePipeline’.



Select created ‘EmpData.wsdl’ and assign it to proxy service.










In Pipeline pair, a new stage for validation of schema is added along with ‘Validate’ node.



Location: body
Schema: (Select type as ‘static’)

Select ‘Employee Type’ element from request xsd in validate node. This will be treated as root node.



Save result of validate action in a variable called ‘$ValidateStatus’.
Note: We can select ‘Raise Error’ in place of ‘Save Variable’, in which case error will be raised directly whenever validate activity fails.



Result of validate activity will be of type ‘Boolean’. If execution of validate node is success, it is considered as ‘true’, Else if validate node fails it is considered as ‘false’.
Next add an Assign activity to compare whether result of $ValidateStatus is ‘true’, and save this result in a variable called ‘$ComparedValue’.





Next add an IF condition and check whether value of variable $ComparedValue is equal to ‘true’.




If above IF condition passes successfully, replace the body with success response.

Note: For success response we have created XQuery mapping using EmployeeDetailsResponse.xsd and used same in ‘Replace’ activity.







If above IF condition fails, raise error with proper code and description.
Error Code: 1001
Error Desc: Validation of Schema failed.




Deploy the service into standalone local weblogic server. On successful deployment, we can locate this service in sbconsole




Run ValidateSchema_ServicePipeline 




Please find below sample request structure. This is valid request structure.




On successful execution, we can see success response as below.





Next we need to check fault case. Please find below request structure for fault case.
Note: Here we have removed ‘Last Name’ element which is a mandatory element.     
Hence Validate node will fail and error will be raise



We can see that error is raised with code as ‘1001’ and description as ‘Validation of schema failed.’
Please find below zip file of sample code, request-response structure for reference.



Comments

Post a Comment