4. Agenda
• Early fault detection
• Current solution: XSD validation
• Validation Gap
• Schematron
• Schematron in SOA Suite
• Simple use case example
• Demo
5. Fault Detection
The earlier the better!
• Reduces load
• Decreases monitor ‘pollution’
(logs, monitor screens)
• May even prevent system crashes
• Response earlier (back to customer)
• Lower costs
6. Early Fault Detection in SOA
SOA: Webservices, SOAP
Early fault detection:
The 1st possibility is error detection
in accepting the request message.
Validating the request message
Request message is XML (SOAP)
XML Validation XSD (Schema)
7. Current solution: XSD validation
XML Schema (XSD):
Defines structure of XML including data type of elements and constraints.
1. Structure
Element “Person” contains child element “Name” and “Birthdate” in this
order.
2. Data type
Element “Name” is of String type and element “Birthdate” is of type date.
3. Constraints
Element “Name” is at least two characters long.
• XSD can be seen as the “ERD” or “DB Design” for XML documents
11. Validation Gap
Three types of XML Business Rule Validation:
1. On data / element itself:
Data type and (data) constraints
XSD (Even complex data constraints with regular expressions)
2. XML structure:
Element names & Hierarchy (child-parent) constraints
XSD? Partial! Optional combinations are difficult (choice combinations)
or even impossible.
3. Constraints between elements
Typically more Business Rules validations
e.g. sum of all percentage attributes in the XML document must be 100.
??
12. Schematron
• Used for validating an XML Document
• Validation of (conditional) structure
• Validation between nodes (elements/attributes), Business Rules
• Rules are defined in Schematron format which is ‘just’ an XML document
• Is built upon XPath expressions
so no new language, only XML and XPath knowledge required!
• Specifies the error message (so you are in control of the output)
• Is an ISO/IEC Standard: 19757-3 (2006)
• Basically is a double XSTL transformation (under the hood)
13. Schematron
How does it work:
1. Define the validations with the usage of XPath expressions in an XML
document in a fixed format and structure (according to the Schematron
XSD).
2. Transform this validations XML with a specific Schematron XSLT into a
new XSLT, which ‘contains/implements’ the validations of step 1.
(In the SOA Suite this is done ,‘under the hood’, by the Runtime Engine)
3. This generated XSLT (containing the validations) can be used to validate
XML data/payload by executing a transformation on it.
(In the SOA Suite this is done ,‘under the hood’, by the Runtime Engine)
Any output are errors! (these error messages were also specified in step
1).
So no output means the data is valid.
14. Schematron
Double XSLT transformation:
1. Rules.xml with Schematron.xslt Rules.xslt
2. Data.xml with Rules.xslt Result
16. Schematron Example
Attribute “abb” of all “Department” elements must be 2 or 3
long.
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">
<pattern name="Number of characters in an abbreviation">
<rule context="//Department">
<report test="string-length(@abb) < 2">There are not enough
characters in the abbreviation</report>
<report test="string-length(@abb) > 3">There are too much
characters in the abbreviation</report>
</rule>
</pattern>
</schema>
Just a name
Context: ‘starting point’ for the conditions
Conditions Error messages
17. Schematron Example
The sum of all direct child elements “Percent” under element
“Total” must be 100.
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron" >
<pattern name="Sum equals 100%.">
<rule context="//Total">
<assert test="sum(./Percent) = 100">Sum is not 100%.</assert>
</rule>
</pattern>
</schema>
18. Schematron in the SOA Suite
• Default filename extension “sch”
• Only assert tag, no report tag!
assert=not(report)
• Define namespace prefixes with uri tag:
<ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" />
• Implemented in Mediator:
19. Use Case Example
Company HRM XML file:
Company element contains departments which contains
employees:
• An employee may not be the manager of himself.
• All normal employees (so not a manager) must have a
manager.
• There is only one manager without a manager
(so there is only one president).
• All employees should have less salary than any manager
(manager = employee in department named “Managers”).
• The relation of manager and employee is a valid one.
This means that the manager of an employee must exist.
21. Use Case Example
An employee may not be the manager of himself.
<pattern name="Employee may not be the manager of himself">
<rule context="//com:Employee[@manager_id]">
<assert test="@manager_id != @id">Employee may not manage himself</assert>
</rule>
</pattern>
22. Use Case Example
All normal employees (so not a manager) must have a
manager.
<pattern name="All normal employees have a manager">
<rule context="//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
<assert test="@manager_id">Employee must have a manager</assert>
</rule>
</pattern>
23. Use Case Example
There is only one manager without a manager
(only one president).
<pattern name="Only one manager without manager, mr president">
<rule context="//cmp:Department[@name='Managers']/cmp:Employees">
<assert test="count(com:Employee[not(@manager_id)]) = 1">There should be
only one president</assert>
</rule>
</pattern>
24. Use Case Example
All employees should have less salary than any manager
(manager = employee in department “Managers”).
<pattern name="Managers earn more than normal employees">
<rule
context="//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
<assert test="com:Salary <
min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">
Employee earns too much</assert>
</rule>
</pattern>
25. Use Case Example
The relation manager and employee is a valid one, so the
manager of an employee must exist.
Keep in mind that the president doesn’t have manager!
<pattern name="Manager does not exist">
<rule context="//com:Employee[@manager_id]">
<assert test=
"//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees/com:Employee[@id=c
urrent()/@manager_id]">No valid manager</assert>
</rule>
</pattern>
26. Use Case Example
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">
<ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" />
<ns uri="http://amis.nl/schematrondemo/common" prefix="com" />
<pattern name="Managers earn more than normal employees">
<rule context= "//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
<assert test="com:Salary <
min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">Employee
earns too much: <value-of select="com:Salary"/></assert>
</rule>
</pattern>
<pattern name="Employee may not be the manager of himself">
<rule context="//com:Employee[@manager_id]">
<assert test="@manager_id != @id">Employee may not manage himself</assert>
</rule>
</pattern>
<pattern name="All normal employees have a manager">
<rule context=
"//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
<assert test="@manager_id">Employee must have a manager</assert>
</rule>
</pattern>
<pattern name="Only one manager without manager, the president">
<rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees">
<assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one
president</assert>
...
Emiel Paasschens
Graduated Aeronautical Engineering in 1996
Java and Oracle specialist since 1999
Oracle Certified Implementation Specialist for SOA
Got married in a tricycle and have a son & daughter
Amis Services, www.amis.nl
Founded in 1991
90 employees, 2 Aces, 1 Ace Directors
Located in Nieuwegein, The Netherlands
Oracle EMEA Middleware partner of the year (2014)
Blog: technology.amis.nl