Thursday, 12 May 2016

Oracle SOA - Bypass payload validation when using Mediator

If you have been using SOA 12c actively you are probably a fan of XQuery for your XML transformations by now.

You might have noticed that when generating an XQuery transformation on a Mediator, by default, your payload will be validated against the schema definition.

Let's use the following example:

xquery version "1.0" encoding "utf-8";

import schema namespace bpe="http://xmlns.oracle.com/Application1/Project1/BPELProcess1" at "../Schemas/BPELProcess1.xsd";

declare variable $in.payload as schema-element(bpe:process) external;

declare function local:mediatorTransform($in.payload as schema-element(bpe:process)) as schema-element(bpe:process) {
    validate {
        <bpe:process/>
    }
};

local:mediatorTransform($in.payload)

Above, in red, you can see that the generated XQuery transformation uses the validate expression which will perform the aforementioned payload vs schema validation.

In certain situations you might not want this validation to be performed.
Looking up at the W3C definition for the used type, we can see:

  • schema-element(customer) refers to an element node whose name is customer (or is in the substitution group headed by customer) and whose type annotation matches the schema type declared for a customer element in the in-scope element declarations
while:
  • element(customer) refers to an element node named customer with any type annotation


So, if you don't want the XQuery transformation to perform the validation simply change the following on the generated XQuery:

  • Change the declared variables from schema-element to element
  • On the function declaration, change the variables from schema-element to element
  • Remove the validate {} expression

Taking the example it would become:

xquery version "1.0" encoding "utf-8";

import schema namespace bpe="http://xmlns.oracle.com/Application1/Project1/BPELProcess1" at "../Schemas/BPELProcess1.xsd";

declare variable $in.payload as element(bpe:process) external;

declare function local:mediatorTransform($in.payload as element(bpe:process)) as element(bpe:process) {
    
        <bpe:process/>
   
};

local:mediatorTransform($in.payload)


The opposite case is also viable. If you want to force payload vs schema validation in your XQuery validation just apply the changes above in reverse to achieve it.