eXTReMe Tracker

Thursday, September 11, 2008

Validating input XML and sending out email for invalid XML in BPEL

I had this requirement recently to validate the input XML document before proeeding with the process orchestration.
We can keep the logic to validate the XML at the application tier, which is the client calling the BPEL process or
we can keep the logic on the database tier, which is nothing but the partner link to which my process connects (PL/SQL package for example).
The earlier approach reduces the reusability of the process any client which does not have a validation logic
needs to change its code to do the pre-invoke validations. And the later approach introduces an overhead on the
database tier as validating the XML documents on database tier would require the registration of schema and also the
validation on this side is pretty expensive.

So, the better approach is to validate in the BPEL layer.
You can do this by setting the 'validateXML' property to 'true' at the domain level. But this approach has a
disadvantage that it would apply it for all the processes on the domain and for all the partner links inside a process.
What if one needs to validate only the inbound XML.
Here's how:
1) Double click on 'client' partner link
2) Go to Property tab
3) Create a new property named 'validateXML' and set its value to true

Now, your BPEL process will validate all the XML documents related to 'client'.
What if you wanted to notify someone incase of invalid XML documents?
Here's how:
1) Declare a fault message shown below and then declare a fault variable of this message type:
<message name="InvalidXML_Message">
        <part name="code" type="xsd:string"/>
        <part name="summary" type="xsd:string"/>
        <part name="detail" type="xsd:string"/>
2) Add a Catch activity and fill the following information:
Namespace URI:http://schemas.oracle.com/bpel/extension
LocalPart:invalidVariables
Faultvariable: Mention the variable defined above
3) Add an email activity and copy the above variable to content body

You are all set to catch the invalid XML documents and notify your support team..!!!

No comments: