Saturday, July 13, 2013

Validate XML schema In BPEL

Hello Friends,

Many time we came across the situation where we need to validate our input based on the schema before doing any processing on the received input.

Oracle BPEL provides 3 ways to do validation.

One way is to use Validate Activity and the second is by enabling Validate option in Assign/Transform activity and third way is Payload Validation on EM Console. Later in this Blog we will explain the implementation details.
 
Implementation of Validate Activity:
This activity enables you to validate variables in the list. The variables are validated against their XML schema.

[Note] : In BPEL 2.0, the Validate dialog includes a Documentation tab, Targets tab, and Sources tab, and does not include a Skip Condition tab

Steps to Implement:

1.     Create a BPEL process (For the Demo purpose below mentioned schema has been used to validate)




2.     From the BPEL Constructs section of the Component Palette, drag a Validate activity into the designer.
[Note]: In BPEL 1.1 Validate activity is not displayed in BPEL Constructs drop down menu. It needs to be added on source code (Mentioned in step 4).



3.     Double-click the Validate and Enter a name for the activity. Add the variable which needs to be validated.




4.     Click the Source tab to view the syntax. Note that the syntax for validating XML data with the validate activity is slightly different between BPEL versions 1.1 and 2.0.

                       <validate name="Validate_XMLSchema" variables="inputVariable"/> (For BPEL 2.0)

                       <bpelx:validate variables="inputVariable" name="Validate_XMLSchema"/> (For BPEL 1.1)

5.     Deploy to server.
6.     As mentioned in the XSD (step 1) we have put constraint of length 8 to field CompanyName. To Check the validation we will have 9 charaters for CompanyName
                  
                       Input:

                      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                            <soap:Body>
                               <ns1:process xmlns:ns1="http://xmlns.oracle.com/Demo/DemoValidateActivity">
                                       <ns1:CompanyName>123456789</ns1:CompanyName>
                                       <ns1:CompanyID>12345</ns1:CompanyID>
                              </ns1:process>
                           </soap:Body>
                        </soap:Envelope>

                      Output:

                         




Implementation of Assign Activity with validate option enabled:

Steps to implement:

1.      From the BPEL Constructs section of the Component Palette, drag an Assign activity into the designer.
2.      Double-click the Assign activity.
3.      In the General tab, enter a name for the activity and select the Validate checkbox.

                        


4.      Click Apply, then OK.
5.      Click the Source tab to view the syntax. Note that the syntax for validating XML data with the assign activity is slightly different between BPEL versions 1.1 and 2.0.
<assign name="Assign_ValidateXML" validate="yes"/> (For BPEL 2.0)
<assign name="Validate_XMLSchema" bpelx:validate="yes"/> (For BPEL 1.1)
 
6.      Deploy to server
 

 Implementation of Payload Validation:

          1.     Login to EM Console and go to the composite for which Payload validation is needed. Go to settings -> Payload Validation and select option Enable.                                                                                              
 
2.       Schema validation failed then an error is thrown :
 
                                        
                3.      Fault Message :
                                        
 
 
 
Cheers,
Lets Learn Oracle SOA Team

 


 

 



2 comments:

  1. Can you share source doe for this? I am new to BPEL so require it to understand few things during implementation.

    ReplyDelete
  2. Hi,

    Please share your Email id . We will mail you the source code. :)

    ReplyDelete