Thursday, 19 November 2015

Composite Sensors in SOA Suite 11G

Hi Guys,

Its been long since I last wrote blog because of some workload.Eventually took out some time to continue sharing my knowledge.Without wasting any time, Ill start and explain you guys about Composite levels , what are they used for and how to use them.

Composite sensors
 provide a method for implementing trackable fields on messages. Composite sensors enable you to perform the following tasks:

  •     Monitor incoming and outgoing messages.
  •     Specify composite sensor details in the search utility of the Instances page of a SOA composite application in Oracle Enterprise Manager Fusion Middleware Control. This action enables you to locate a particular instance.
  •     Publish JMS data computed from incoming and outgoing messages.
  •     Track composite instances initiated through business event subscriptions.

You define composite sensors on service and reference binding components or on service components that have business event subscriptions in Oracle JDeveloper. This functionality is similar to variable sensors in BPEL processes. During runtime, composite sensor data is persisted in the database.

In our use case I have created a One Way BPEL process exposed as web service using below schema:


<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.example.org/Employee"
            targetNamespace="http://www.example.org/Employee"
            elementFormDefault="qualified">
<xsd:element name="employee" type="personinfo"/>
<xsd:complexType name="personinfo">
  <xsd:sequence>
  <xsd:element name="EmpID" type="xsd:string"/>
    <xsd:element name="firstname" type="xsd:string"/>
    <xsd:element name="lastname" type="xsd:string"/>
  </xsd:sequence>
</xsd:complexType>
</xsd:schema>

Inside the BPEL process  we only have receive activity.Our BPEL process will accept the fields defined in schema and thats all we require for this post. 

Step1: To create sensors ,Click the Composite Sensor icon above the SOA Composite Editor
Step2: Composite sensors window will pop up.Click on "+" icon to create composite sensor.

Step3: In the next window, give the name to sensor and define expression to assing value to this sensor.
Step4: You will see the input payload only in our usecase as our BPEL process is one way only.Drill down to Employee ID and click OK.
Step5: Now under sensor actions you will see two options Enterprise Manager and JMS Queue. 
  • Enterprise Manager
Select to make runtime sensor data searchable in the Instances tab of a SOA composite application in Oracle Enterprise Manager Fusion Middleware Control.
  • JMS Queue
Select to store composite sensor data (XML payload) in a JMS queue. You must specify the JMS connection factory and queue name.In our case we will use Enterprise Manager
Step6:Our Composite sensor EmployeeID is created .Click OK.
Step7: Under your projects on left hand side you can see two new files getting created sensor.xml and sensorActiuon.xml. These files contains list of all the sensors configured for particular composite and along with their actions.
Step8: Compile and deploy your code to EM and test the Sensors composite.Pass the values in employeeid,Fname and Lname.
Step9: Now Open up flow trace for the request you triggered.Expand the sensors tab just below Flow Trace.You will see EmployeeID as sensor and its value that we passed in the input.
Step10: Go back to your Composite in EM and go to Instances tab.Just next to Search,Reset Buttons you will see a new button :AddFields. Click on that and select EmployeeID.

Step11: New search field "EmployeeID" will be added in the Search box along with all other existing search criterias.In this way you can search your instances by passing employeeID field value.
Composite sensors are very important from support and operations point of view as we can set custom search fields using which we can search for our composite instances.
For more imformation you can refer this LINK.

Hope you guys enjoyed the blog.

Happy Learning,
Cheers

Difference between BPEL 1.1 and BPEL 2.0

Hi Guys,


In my project there was a requirement to work with BPEL 2.0.I had experience of working with BPEL 1.1 only so it was something new for me.There are some minor differences in both the two.I will explain the basic differences between them

  • FlowN activity in BPEL 1.1 is replaced by <forEach> activity which can be invoked both serially and parallel.
  • RepeatUntil activity is added. Use this activity if the body of an activity must be performed at least once. The XPath expression condition in the repeatUntil activity is evaluated after the body of the activity completes. The condition is evaluated repeatedly (and the body of the activity processed) until the provided boolean condition is true.(Same as do while in programming languages).
  • The switch activity in BPEL 1.1 is replaced by <if> <elseif <else> activity in BPEL 2.0.
  • Terminate activity is chqanged to Exit Activity.
  • CompensateScope activity added - This activity enables you to start compensation on a specified inner scope that has already completed successfully. This activity must only be used from within a fault handler, another compensation handler, or a termination handler.   
  • A new activity Rethrow has been added to fault handlers.This activity enables you to rethrow a fault originally captured by the immediately enclosing fault handler.
XPath expressions are simplified by using the ‘$’ notation for variable access in BPEL 2.0, for example, $inputVariable.payload/ns1:firstname. 

  • In BPEL 2.0, if you are working with synchronus BPEL process and in the BPEL code you have not used reply activity to send bcak the response.You will get below error where as, in BPEL 1.1 no error occurs.


These are the main differences in terms of process flow and new/modified activities. For more information you guys can refer below links:
Hope this helps you.Guys please do share your comments as well,if you find any of my post useful.

Happy Learning.
Cheers !!!

Base64 Binary Encoding and Decoding - BPEL 11G

Hi Guys,

Sometimes there are requirements where we receives request from consumer in opaque/binary format or we may have to interact with applications using binary format.To facilitate this requirement Java embedding activity is used in BPEL.I will be demonstrating how to convert string to binary format and vice verse.

For this use case I have already created a BPEL process that will receive string in string format.In the BPEL code I have added 2 java embedding activities one for encoding and one for decoding the data.

Firstly, I will encode the payload received in binary format using below code:

addAuditTrailEntry("Encoding started");      
try {      
oracle.xml.parser.v2.XMLElement input = (oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload","/client:process/client:input");      
java.lang.String input_str = input.getTextContent();      
addAuditTrailEntry("Input String = "+input_str);      
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();          
java.lang.String encoded = null;         
encoded = encoder.encode(input_str);      
addAuditTrailEntry("encoded string = "+encoded);      
setVariableData("InputVar",encoded);      
} catch (Exception e) {      
  addAuditTrailEntry("Exception: "+e.getMessage());      
}      
addAuditTrailEntry("Encoded ended");

Pass the input variable name in the input string and create one more variable of 64binary format that will store the encoded string.
Now, we will decode the string that we encoded in previous step using below code:

 addAuditTrailEntry("decoding started");
String encodedString = (String)getVariableData("InputVar");
Base64Decoder Decoder = new Base64Decoder();
addAuditTrailEntry("encoded String = "+encodedString);
try
{
String decoded = Base64Decoder.decode(encodedString);
addAuditTrailEntry("decoded string = "+decoded); 
setVariableData("decodedString",decoded);
}
catch(Exception e)
{
  addAuditTrailEntry("Exception: "+e.getMessage());
}


Create one more variable of string type that will contain the decoded string.In this case we will pass the variable we created in previous step as input.Decoded string will be stored in variable we created for storing decoded string.
Now, we will test our composite to verify the changes we have made.String passed is encoded using 1st java embedding activity and decoded using second java embedding java activity.
Make sure you imported below mentioned classes in your BPEL source:

    <bpelx:exec import="oracle.soa.common.util.Base64Encoder"/>
    <bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>

  
Otherwise your compilation will fail.
In this way you can achieve encoding and decoding functionality in BPEL.Hope this post is useful to you.

Happy Learning,
Cheers !!!

Saving Preference Variables Permanently - SOA Suite 11G

Hi All,

I would like to share one very useful information today related to preference variables in SOA 11G. Sometimes,you might have observed that you have changed the value for a preference variable but,after server restart it somehow got revert back to its original value. Weird isn't it !!!

Solution to this problem is very simple.

Step1: Just right click on SOA infrastructure and navigate to Administration --> System MBean Browser.
Step2: Then go to Application Defined MBeans --> oracle.soa.config --> Server: soa_server1 --> SCAComposite --> <your SOA composite> --> SCAComposite.SCAComponent and open up the BPEL Component.

Step3: In the BPEL just make required changes to the value of your preference variables and click Apply.

Step4: After that in the MBean configuration only,navigate to Operations tab and then click on save.

Step5: In the next window that opens up,click on Invoke.

Here you go the values of your preference variables are saved permanently.even after the server restart the new value will still persist.If you guys dont know how to set/get preference variable values you can check my post

Hope this post helped you guys.

Happy Learning,
Cheers !!!

Adding nodes and creating variables in XSL - Oracle SOA 11G

Hi guys,

Today I am gonna write about,how to use summation function in XSL and how to create a cariable and use it in your xsl. Actually,there was a requirement in our project,which was like adding some values of some fields in the input and based upon the sum we required to pass some value to the target system.So, to accomplish this we used sum function, that is available in xslt.

I will be demonstrating it taking one example.Suppose we have some fields that are coming in the input such as A,B,C and we need to add all these values and see whether its sum is greater than zero or less than zero.If the sum is greater than 0, we will pass say "pass" and if its other way around we will pass say "fail" to the target system.I have create a sample BPEL process for this usecase.Process is very simple: it is exposed as webservice and taking input from the client and after doing aforesaid transformation and logic will publish the message in jms Queue.I will just explain the XSL part.


Step1: In my transformation, first I will create a variable that I will be using to storing the sum of all the required nodes. So in your xsl on target node,right click and add variable "tempVar".
Step2: Drag and drop "Sum" function from Mathematical functions in the centre of xsl.
Step3: Now in the function add all the nodes that you want to add separated by "|".In this example I am adding surcharge,tax,vat,shipmentcharge nodes.






 <xsl:variable name="tempVar"
                select="sum((/imp1:employee/imp1:surcharge | (/imp1:employee/imp1:order/imp1:Tax | (/imp1:employee/imp1:order/imp1:VAT | /imp1:employee/imp1:order/imp1:shipmentCharge))))"/>


Step4: Based upon the sum we need to send value in the target XML.So in our case if its greater tha 0, We will send "Invocie" in typecode tag and "Credit MEmo" otherwise.To implement this add a choose when and otherwise condition. 
Step5: It will check the value of "tempVar" and based on the result,value will be set in the target xml.

Step6: Now deploy and test your composite. First we will test for positive vsalue.I have passed values in all the field greater than 0.As per our logic value in Typecode tag is sent as "INVOICE".
Step7: To check the opposite scenario,pass values such that sum is less than 0.Values now passed is "Credit Memo".
In this way we can use the sum function and also you learned ,how to create a variable in xsl and use that in your XSL.







NOTE: There can be scenarios where values in some nodes can be empty.So you have to handle that as well,otherwise,you will get "NaN" in your result.Hence in order to handle blank nodes use below expresssion:

sum((/imp1:employee/imp1:surcharge[. != ""] | (/imp1:employee/imp1:order/imp1:Tax[. != ""] | (/imp1:employee/imp1:order/imp1:VAT[. != ""] | /imp1:employee/imp1:order/imp1:shipmentCharge[. != ""]))))
  
Hope this post is useful to you guys.

Happy Learning,
Cheers !!!

Retry and Rollback using DB adapter - SOA Suite 11G

Hi All,


Retrying and rolling back transactions that got failed while invocation is one of the major things that needs to be keep in mind while designing the solution for any interface.As it helps in preventing any data discrepancy that can be there between source and target systems,had there not been any rollback in case of failed transaction.

I will be demonstrating,how to retry and rollback failed transactions in SOA.To illustrate this use case I will be using one JMS queue from where our composite will consume the message and, after that it will insert data in 3 tables that I have created for this usecase.you will be requiring XA JNDIs both for Database and JMS Adapters.

Three tables have been created namely Customer,Order, and Invoice.Our SOA process will insert records in table in the same order.


On weblogic console,we need to set some properties for our jms queue for retry functionality.Just go to your jms queue and navigate to "Delivery Failure" tab for your queue.Set following parameters
  • Redilvery Delay Override: 10000 (10 seconds) It is the interval after which rolledback messages will be retried.
  • Redilvery Limit: 2 (Number of times failed message will be retried).
  • Expiration Policy: Redirect (or Discard, if you want to discard the message after retry) Redirect will move the message to "Error Destination" if even after configured retry parameters message is failed.
  • Error Destination: <Queue Name> Queue to which failed message will be moved after all retry attempts.
In the BPEL process, add catch or catch all handler for your composite to handle any faults that may occur.In the Catch All block ,explicitly throw a rollback fault using throw activity.It will rollback the complete transaction i.e. undo all the data inserted in any of the tables and then request message will be rolled back to the jms queue.

NOTE: Any fault thrown using throw activity that is not being caught will result in rollback of complete transaction. 


Now,first we will test the happy path.Deploy your code to EM and test the interface.Records will be inserted into all the tables successfully.
To see how rollback works,I will intentionally change the DB jndi for Invoice adapter.To do that open jca file for your Invoice DB Adapter and give some random value in that.Save and redeploy the code.Now the interface will fail while inserting the data in Invoice table and flow will got to Catch All block,where transaction will be rollbacked.
To validate this,check the tables and no new records would have been inserted into the tables.

Since we have configured,retry parameters for our request queue, the rollbacked message will be retried again after 10 seconds.Message state will be changed to "delayed" which means it is being retried.

After all failed attempts the message will be redirected into the error destination that we have configured for our queue.


In this way, you can implement retry and rollback functionality in your interfaces.
Hope this helps you.


Happy Learning,
Cheers !!!



Transaction Behavior and Delivery Policy in BPEL 11G

Oracle SOA Suite 11gR1 (11.1.1.6.0) includes new features.Some of them are new delivery and transaction properties that you can set when creating a BPEL process.These configuration properties have a significant impact on the behavior of a BPEL process. You can now set these properties as part of the BPEL component creation process within JDeveloper. The wizard presents these properties and sets the default values based on the context. For example, the oneWayDeliveryPolicy property only shows up for one way processes and the 
transaction property only shows up for synchronous processes.
Delivery: The possible values are:

    async.persist: Messages into the system are saved in the delivery store before being picked up by the service engine.
    async.cache: Messages into the system are saved in memory before being picked up by the service engine.
    sync: The instance-initiating message is not temporarily saved in the delivery layer. The service engine uses the same thread to initiate the message.

Transaction: The possible values are:

    requiresNew: A new transaction is created for the execution, and the existing transaction (if there is one) is suspended. This behavior is true for both request/response (initiating) environments and one-way, initiating environments in which the Delivery list value (oneWayDeliveryPolicy property) is set to sync
    required: In request/response (initiating) environments, this setting joins a caller's transaction (if there is one) or creates a new transaction (if there is no transaction). In one-way, initiating environments in which the Delivery list value (oneWayDeliveryPolicy property) is set to sync, the invoke message is processed using the same thread in the same transaction.

For more information please refer this LINK.

Happy Learning,
Cheers !!!