8- Oracle Mediator in SOA 12c- Validation (Using schematron file)


In this post we will use the validation functionality of Oracle Mediator in SOA 12c. In this tutorial we will be using the Student.xsd schema of our previous post.

Validation

We can configure Mediators to validate the incoming message payload using a Schematron or an XSD file. You can validate each part of incoming message using Schematron file validations.


What is Schematron?

Schematron is a rule-based validation language for making assertions about the presence or absence of patterns in XML document. Patterns can be thought of like presence of sequence of characters, defined length of element values, regular expressions etc.

You can apply assertions in the form of rules applied to specific context of XML document. If assertions fail, a message defined in the rule is displayed.

There are two types of schematron rules:
  • ASSERT:  The assert rule returns the error message when the test condition fails (returns false). For example, consider the following schematron file which checks if email element contains '@' or not. If email element does not contain '@' symbol, it will throw an error "Invalid Email". 
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">
  <ns uri="http://www.example.org" prefix="s1"/>
    <pattern name="Test if Email element is present">
        <rule context= "s1:Student">
            <assert test="contains(s1:Email,'@')"> Invalid Email</assert>
        </rule>
    </pattern>
</schema>

The below element declares that all elements prefixed with s1 will be from namespace "http://www.example.org", to resolve naming conflicts and for correctly identifying the elements.
<ns uri="http://www.example.org" prefix="s1"/>
  • REPORT:  The  the report rule returns your error message when the test conditions succeeds (returns true). Just replace assert keyword with report as below:
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">
  <ns uri="http://www.example.org" prefix="s1"/>
    <pattern name="Test if Email element is present">
        <rule context= "s1:Student">
            <report test="contains(s1:Email,'#')"> Invalid Email</assert>
        </rule>
    </pattern>
</schema>

So the above schematron rule will return the error message when email element contains '#'
Note: The Schematron implementation in the SOA Suite only supports the assert rule, so you have to rewrite your report rules.

Using Schematron file in Mediator

To use schematron file in mediator follow the below steps. We will use the same project of our previous post


  • Right click Schemas folder and create new XML Document (Schematron1.sch) by choosing it from New Gallery window. Paste the above schematron code (containing assert rule) and save the file

  • Open the Mediator.mplan file and make the checkbox "validate Schema (XSD)" checked. Choose the input part (request part in our case) and also select the Schematron1.sch file.

  • Deploy and Test the functionality by using different test inputs. If email element does not contain '@' symbol in it, you will get an error as shown below confirming that validation failed.

Comments

All Categories

Call Fusion BIP Report2 Change Password1 Code Combinations2 Compute Instance2 CTE1 Customer1 Data Aggregation2 Database5 Date Conversion1 DB Adapter2 Decryption1 Development1 EBS4 Encryption1 ESS Jobs3 Examine1 FBDI3 Fusion APIs1 Fusion BIP7 GIT2 GL3 GL Journals1 GL_DAILY_CONVERSION_TYPES1 GL_DAILY_RATES1 ICS1 Identity Domain1 Integrations1 Java1 Journal Import1 Keys1 Legal Entity1 LookupTypeLOV1 LOV1 LOVs1 MultiPartAPIs1 Networking1 NVL2 NVL in OIC2 OCI11 OCI Billing1 OCI Compute5 OCI Cost Management1 OCI Events Service1 OCI Free Tier3 OCI Notifification Service1 OCI Security3 OIC4 OIC Mapper2 Oracle26 Oracle ADF17 Oracle APEX1 Oracle Apps59 Oracle Apps R126 Oracle ATP1 Oracle BIP8 Oracle Cloud12 Oracle Cloud Free Tier1 Oracle cloud Infrastructure9 Oracle Cloud Security2 Oracle Cloud VM1 Oracle DB4 oracle ebs5 Oracle ERP4 Oracle ERP Adapter2 Oracle ERP Cloud7 Oracle financials2 Oracle Forms1 Oracle Fusion57 Oracle Fusion BIP4 Oracle Fusion ERP17 Oracle Fusion Financials18 Oracle Integration Cloud3 Oracle OAF17 Oracle OCI14 Oracle OIC22 Oracle SOA 12c10 Oracle SQL17 Oracle VBCS1 Oracle VBS2 Oracle Visual Builder Cloud Service1 Oracle Visual Builder Studio2 Oracle Workflow Notifications1 Others10 Payables2 Payables Import1 Properties1 R121 Register BIP as ESS Job1 Reset Password1 Responsibility1 REST4 Security List1 Site Map1 SOAP2 SOAP API2 SOAP UI3 SQL16 SQL Functions3 SQL Queries14 SQL Query8 SQL Tips3 SSH1 TCA1 Value Sets1 VBCS1 Virtual Machine2 Virtual Machines1 XML1 XSLT1
Show more