Thursday, 14 November 2013

Composite Sensors in Soa 11g



                 In this blog ,I want to discuss about Composite Sensors.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 case we Use the project we developed for  "Implementing Timeouts in Bpel Using Pick"

Let me remind you the xsd we used  

picksample.xsd
 <xsd:element name="EmployeeDetails">
<xsd:complexType>
<xsd:sequence>
 <xsd:element name="EmpID" type="xsd:string" />
  <xsd:element name="Salary" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="EmpdetailsResponse">
<xsd:complexType>
<xsd:sequence>
 <xsd:element name="EmpID" type="xsd:string" />
 <xsd:element name="MessageStatus1" type="xsd:string" />
 <xsd:element name="MessageStatus2" type="xsd:string" />

</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

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 assingn  value to this sensor.




Step4: You will see the input payload only inand out our usecase as our BPEL process is Synchronous .Drill down to EmpID 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 "EmployeeSensor" 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 from EM

Step9: Now Open up flow trace for the request you triggered.Expand the sensors tab just below Flow Trace.You will see EmployeeSensor 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 EmployeeSensor.



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 "EmployeeSensor" 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.

Till now we have seen sensors in Composite.xml

Along with the c omposite sensors we have one more sensors called BPEL sensors which we create in BPEL. We will see these sensors in coming post in detail.


For more Information Check the Below  Sensors


                                                                                                           by DeepthiReddy

Implementing TimeOuts in Bpel Using Pick(On Message,On Alaram)

                                       
                                    

                                                 In this blog ,I wanna  discuss how to create a pick activity to select to continue a process or wait, create wait activities to set an expiration time, create OnEvent branches in BPEL 1.0 to wait for message arrival, and set timeouts on synchronous processes.

The pick activity provides two branches, each one with a condition. The branch that has its condition satisfied first is executed
    

  • onMessage
    This condition has code for receiving a reply in the form of a web service. The onMessage code matches the code for receiving a response from the  web service before a timeout was added.
  • onAlarm
    This condition has code for a timeout of one minute. This time is defined as PT1M, which means to wait one minute before timing out. In this timeout setting:
    • S stands for seconds
    • M for one minute
    • H for hour
    • D for day
    • Y for year


       Note:The pick activity condition that completes first is the one that the BPEL process service component executes. The other branch then is not executed.
 An onMessage branch is similar to a receive activity in that it receives operations. However, you can define a pick activity with multiple onMessage branches that can wait for similar partner links and port types, but have different operations. Therefore, separate threads and parallel processes can be invoked for each operation. This differs from the receive activity in which there is only one operation. Another difference is that you can create a new instance of a business process with a receive activity (by selecting the Create Instance checkbox), but you cannot do this with a pick activity.


In this Example - A BPEL process(Process1) client: uses an Invoke to send an asynchronous request to the service (BPEL Process 2), and a Pick activity with:
- An onMessage branch to receive the response (callback)
- An onAlarm branch to manage the timeout condition if it occurs before the response is
received

 Create a BPEL project PICK_DemoPjct

Artifacts required is a simpleXSD : picksample.xsd


 <xsd:element name="EmployeeDetails">
<xsd:complexType>
<xsd:sequence>
 <xsd:element name="EmpID" type="xsd:string" />
  <xsd:element name="Salary" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="EmpdetailsResponse">
<xsd:complexType>
<xsd:sequence>
 <xsd:element name="EmpID" type="xsd:string" />
 <xsd:element name="MessageStatus1" type="xsd:string" />
 <xsd:element name="MessageStatus2" type="xsd:string" />

</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Step 1:  Design the BPEL Process 1 name it "PickSyncBpelProcess" by selecting "SynchronousBPEL Process"  as Template


Input,Output are the elements from the above picksample.xsd



Step 2:   Design the BPEL Process 2 name it "PickAsyncBpelProcess" by selecting "ASynchronousBPEL Process"  as Template
 Input,Output are the elements from the above picksample.xsd

 Note : Exposed as a soap Service is unchecked




  
 Connect the BPEL process1 to BPEL process2 as shown below, design composite as below


 Step 3:  Now we will edit BPEL Process 2  "PickAsyncBpelProces"

In this Process Drop Assign activity between Receive and Callback and a delay activity (Waiit_1) between Assign and Callback.Assign activity just assign input to output.



Step 4:  Now Configure the Wait activity to 5 seconds.It Means after Assign_1 activity there will be a delay of 5 seconds




















What happens when you create wait activity<wait (for="duration-expr" | until="deadline-expr")standard-attributes>standard-elements</wait> 
  
in our case:  <wait name="Wait1" for="'PT5S'"/> 
the duration value bpelx:for="'PT5M'" specifies that the activity expects an inbound message to arrive 
no later than five minutesafter the activity has started execution.
 
Step 5:  Now we will edit BPEL Process 1   "PickSyncBpelProces"
 
                         1. Add Invoke activity to Call BPEL Process 2 "PickAyncBpelProces"
                         2. Add Pick activity.Pickout activity has 2 type of outcome , OnMessage and 
OnAlarm. Set An onMessage branch to receive the response (callback) and 
an onAlarm branch to manage the timeout condition if it occurs before the 
response is received.
 
Create a Variable for Callback  response to receive
reply from AsyncBpelprocess "PickAyncBpelProces"
 
                          
  3.Add Assign Activity Assign_1 with OnMessage branch and Assign activity 
Assign_1 with the OnAlarm activity.
 
   4.  In Assign_1 activity , assign MessageStatus1 element of "EmpdetailsResponse" of OutputMessageType 
with value  'OnMsg' and  MessageStatus2 element with value 'BPEL_Pick'    
 
    5.In Assign_2 activity , assign MessageStatus1 element of "EmpdetailsResponse" 
OutputMessageType with value  'On_ALARM' that indicate that it is Time out Activity.
 
   6.Configure the OnAlarm activity of Pick activity and set the time = 59 
seconds.That means if the OnMessage Branch has not been process within 59 
seconds that BPEL will trigger the OnAlaram branch of theflow
 
 
6. Add Assign_3 to map input to invoke inputVariable of   "PickAsyncBpelProces"
 

 Step 6:  Now our PICK_DemoPjct is ready to test 
Run the BPEL Process .Please note that in BPEL Process we have a delay of 5 seconds and OnAlaram branch in Process1 will trigger only if OnMessage will not get any response with in 59 seconds.
In Our case since delay in Process 2 is 5 seconds , On Message will get response in 5seconds and output will Print the variable assign in Assign activity_2 .
MessageStatus1 and  MessageStatus2  value 'BPEL_Pick' 


Step 7: Now we will tweet the code to test OnAlarm Branch 
 Once again configure the delay (Wait_1) activity of the BPEL process 2 and set the dealy time = 2 minutes .That means Process2 will take 2 minutes of dealy  between Assign and callback.
Run the BPEL Process 



                                                                                                              By Deepthi Reddy


Wednesday, 13 November 2013

Working with Multiple Webservices In BPEL



In this blog we will discuss how we can create BPEL using multiple operations in WSDL

   Scenario:  We will take the example of four basic mathematic binary operations (addition, subtraction, multiplication, division) to demonstrate this.  Our task is to build a web service that has four different operations.  The condition however we have is to do that only one BPEL Process.  We cannot have four BPEL process implementing four different web services.

   Step wise discription provided to implement the process

  Step 1: create an Empty BPEL process project  ‘MultipleWSDLoperations’ (Define Interface later template )
Step 2: Add a new schema MAthCalculations.xsd  to the BPEL process project.  In this example I used simple types for input and output.  You may have complex types depending on your business use case. Also as all operations are binary and all of them share the same input and output signature, Request and Response elements are reused in this example.  You may have different Request Response element types/structure. You can declare them in the same schema file.







Step 3:     create my WSDL with the required Operations in it. My WSDL uses the schema created in the previous step

   <?xml version="1.0" encoding="UTF-8" ?>
<definitions targetNamespace="tns:MAthCalculationWSDL"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:tns="tns:MAthCalculationWSDL"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
             xmlns:ns2="http://www.example.org"
       xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
               
   
  <types>
    <xsd:schema targetNamespace="tns:MAthCalculationWSDL/types"
                elementFormDefault="qualified">
 <xsd:import namespace="http://www.example.org" schemaLocation="xsd/MathCalculations.xsd" />
 </xsd:schema>
  </types>
  <message name="MathoperationrequestMessage">
    <part name="MathoperationInputmessage" element="ns2:Inputvales"/>
  </message>
  <message name="MathoperationresponseMessage">
    <part name="MathoperationOutputmessage" element="ns2:Outputvales"/>
  </message>
  <portType name="MathOperation">
    <operation name="add">
      <input message="tns:MathoperationrequestMessage"/>
      <output message="tns:MathoperationresponseMessage"/>
    </operation>
    <operation name="Substract">
      <input message="tns:MathoperationrequestMessage"/>
      <output message="tns:MathoperationresponseMessage"/>
    </operation>
    <operation name="Multiply">
      <input message="tns:MathoperationrequestMessage"/>
      <output message="tns:MathoperationresponseMessage"/>
    </operation>
    <operation name="Divide">
      <input message="tns:MathoperationrequestMessage"/>
      <output message="tns:MathoperationresponseMessage"/>
    </operation>
  </portType>
</definitions>

  Step 4: add a partner link using the WSDL above. Name this ‘client’ with Role as ‘Provider’.  This action imports the WSDL and adds a partnerLinType tag to the imported WSDL.


 <plnk:partnerLinkType name="MathOperation_PL">
     <plnk:role name="MathOperation_Role">
     <plnk:portType name="tns:MathOperation"/>
      </plnk:role>
    </plnk:partnerLinkType>


and also  Namespace as : xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"

During this step also create two global variables ‘inputVariable’ and ‘outputVariable’ for the Request and Response data using the Project WSDL.

You can directly add sourcecode  in  Bpel

<variables>
        <!-- Reference to the message passed as input during initiation -->
        <variable name="inputVariable"
                  messageType="ns1:MathoperationrequestMessage"/>

        <!-- Reference to the message that will be sent back to the requester during callback -->
        <variable name="outputVariable"
                  messageType="ns1:MathoperationresponseMessage"/>
</variables>

note: the code above creates two global variables namely  inputVariable,outputVariable

Step 5:  add a pick activity to the empty BPEL process,. This activity waits for the occurrence of one event in a set of events and performs the activity associated with that event. In our case an event translates to a web service operation.  If more than one of the events occurs, then the selection of the activity to perform depends on which event occurred first. If the events occur nearly simultaneously, there is a race and the choice of activity to be performed is dependent on both timing and implementation. As our implementation is going to be state-less atomic services, we may not have a racing condition.  Coming back to the pick activity The pick activity provides two branches, each one with a condition. When you double-click the pick icon, the pick activity shown in figure below, appears and displays these two branches: onMessage (on the left) and onAlarm (on the right). The onMessage branch contains the code for receiving a reply, for example, from a loan service. The onAlarm branch contains the code for a timeout, for example, after one minute. Whichever branch completes first is executed; the other branch is not. The branch that has its condition satisfied first is executed.


 Step 6:  delete the alarm branch (from BPEL Source) as we will not be using it.  Also add 3 more onMessage branches to implement all the four operations in the WSDL.







Create a webservice with the created "MAthCalculationWSDL" above


 Step 7: for each of the onMessage branch, associate the WSDL operation as shown below.




Create 4 variables namely
OnMessage_add_InputVariable
OnMessage_Substract_InputVariable
OnMessage_Multiply_InputVariable
OnMessage_Divide_InputVariable

with respective Operations
add
Substratct
Multiply
Divide




Now you have a BPEL process that can branch based on the operations invoked by the client.

 Step 8:  implement the mathematical operations under each branch and provide a synchronous response to the client.  Add a simple assign step followed by reply activities  to achieve this.






 



For each Assign  assign activities  I use a simple copy operation to perform the mathematical operation.


   Same as for 4 Assigns add simple copy operations to define the Mathematical fuction we implement

Step 9: In each of the reply activities assign the output variable and partner link
                              Deploy and test the service.


                                                                         
                                                                                                                    By-DeepthiReddy