Advertisements
RSS

How to use dynamic validate in Oracle Service Bus 12c

29 Jul

One of the new features introduced in Oracle Service Bus 12c is the ability for dynamic validation. A feature which can be used to validate a message against a WSDL or XSD schema file which is both explained here by Oracle. The example on the Oracle website shows this XML code to validate against a XSD:

<validate xmlns="http://www.bea.com/wli/sb/context">
<schema>default/MySchema</schema>
<schemaElement>
<localname>MyElementType</localname>
</schemaElement>
</validate>

However I tried “playing” with the new feature but couldn’t get it to work. The error I got was:

<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="nl">OSB-382524: Failed to perform validation</soap:Text>
</soap:Reason>
<soap:Detail>
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
<con:errorCode>OSB-382524</con:errorCode>
<con:reason>Failed to perform validation</con:reason>
<con:location>
..
</con:location>
</con:fault>
</soap:Detail>
</soap:Fault>

After contacting Oracle Support I received the following info:

  • BUG 20367846: Internal Documentation  – Validate action to dynamically select a schema – documentation is not clear
  • BUG 20380158: Validate action – Dynamic validation throws NPE

A patch for BUG 20380158 was then released for Oracle Service Bus 12.1.3, which then could be downloaded from Oracle Support:

ppatch

I downloaded patch 20380158 and used opatch to install it on my DEV environment.


..\p20380158_121300_Generic\20380158&amp;gt;opatch apply
Oracle Interim Patch Installer version 13.2.0.0.0
Copyright (c) 2014, Oracle Corporation.  All rights reserved.

Oracle Home       : C:\ORACLE\middleware_12.1.3
Central Inventory : C:\Program Files\Oracle\Inventory
from           : n/a
OPatch version    : 13.2.0.0.0
OUI version       : 13.2.0.0.0

OPatch detects the Middleware Home as &quot;C:\ORACLE\middleware_12.1.3&quot;

jul 09, 2015 12:48:49 PM oracle.sysman.oii.oiii.OiiiInstallAreaControl initAreaControl
INFO: Install area Control created with access level  0
Applying interim patch '20380158' to OH 'C:\ORACLE\middleware_12.1.3'
Verifying environment and performing prerequisite checks...
All checks passed.

Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.
(Oracle Home = 'C:\ORACLE\middleware_12.1.3')

Is the local system ready for patching? [y|n] y
User Responded with: Y
Backing up files...

Patching component oracle.osb.server, 12.1.3.0.0...
Patching component oracle.osb.server, 12.1.3.0.0...

Verifying the update...
Patch 20380158 successfully applied
OPatch succeeded.

After the patch the error was still their but I received a more detailed error message in my logging:

<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">OSB-382571: Schema element: GetCaseRequestMessage not found</soap:Text>
</soap:Reason>
<soap:Detail>
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
<con:errorCode>OSB-382571</con:errorCode>
<con:reason>Schema element: GetCaseRequestMessage not found </con:reason>
....
</con:fault>
</soap:Detail>
</soap:Fault>

After more contact with Oracle Support it indeed appeared that the Oracle documentation was not correct (as mentioned earlier with their reference to BUG 20367846). The XML structure example shown by Oracle also requires an nameSpaceURI element.  Which means the correct XML input for dyanamic validation for an XSD is:

<validate xmlns="http://www.bea.com/wli/sb/context">
<schema>mySBproject/schema/myXsdSchemaFile</schema>
<schemaElement>
<namespaceURI>nl.rubix.messages/caseservice/1.0</namespaceURI>
<localname>getCaseRequestMessage</localname>
</schemaElement>
</validate>

Example Oracle Service Bus Project with Dynamic Validation

Here is an example of my SB project:

pipeline

I first use an Assign action in my pipeline to create the $dynValidate variable with XQuery which holds the XML structure for the validation. (You could also use the xquery directly on the validate action).

assign_xquery

Here is an example XQuery to generate the required Dynamic Validate XML structure:


xquery version "1.0" encoding "utf-8";
(:: OracleAnnotationVersion "1.0" ::)
(:: pragma parameter=”$i_operation” type=”xs:string” ::)

declare function local:dynValidate($i_operation as xs:string) as element()
{
<validate xmlns="http://www.bea.com/wli/sb/context">
<schema>mySBproject/schema/myXsdSchemaFile</schema>
<schemaElement>
<namespaceURI>nl.rubix.messages/caseservice/1.0</namespaceURI>
{
if ($i_operation = "getCase")
then <localname>getCaseRequestMessage</localname>
else if ($i_operation = "insertCase")
then <localname>insertCaseRequestMessage</localname>
else ()
}
</schemaElement>
</validate>
};

declare variable $i_operation as xs:string external;
local:dynValidate($i_operation)

After we have the $dynValidate variable we can use it as input for the Validate action. (As mentioned, you can also directly use the Xquery here instead of an expression with the earlier generated variable.

validate

Hope it helps!

References

Advertisements
 
Leave a comment

Posted by on 29-07-2015 in Oracle, OSB

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: