BPEL Business Process Execution Language for Web Services

Document Sample
BPEL Business Process Execution Language for Web Services Powered By Docstoc
					BPEL: Business Process Execution
Language for Web Services

         Dr. Yuhong Yan
        NRC-IIT-Fredericton
          Internet logic
What is BPEL

• It is positioned to become a standard for Web
  service composition.
• a notation for specifying business process
  behavior based on Web services.
• a joint specification of IBM, BEA, Microsoft, SAP,
  and Siebel
• OASIS ( Organization for the Advancement of
  Structured Information Standards e-business
  standards) standard.
     The description of a workflow
Need             Process to satisfy need                                                   Need satisfied



                 Go to coffee shop                     Make and serve
                                     Order                              Drink




Satisfy thirst
with coffee                                     Service                                     Thirst
                                                                                            quenched




                 Buy coffee
                 machine             Install           Operate          Fill cup   Drink




                                               Tangible good + self service
     The description of workflow
                              Loan Request


                 request.amount         request.amount>=1000
                     <1000


     Send to Risk Assessor                      Send to Approver

                            risk.level!=low
risk.level=low




  Prepare the answer
                                                        Reply
BPEL: describe the business logic

• The sequence of the activities (operations in
  WSDL)
• The triggering conditions of the activities
• The consequences of executing the activities
• The partners for the external activities
• The composition of Web Services
• The binding to WSDL
  Business Process (what) versus WSDL (how)


Business Process: what to do
• Modeled as a sequence of activities             Business
• Tools aid to define, monitor, and     WSDL      Process
manage business processes                                        WSDL
                                                     A
                                        WSDL
                                                 C           B
WSDL: how to execute activities                                  WSDL


• An activity can be an internal or                  D
                                        WSDL
external Web service (SOAP/WSDL)
                                                      E
• A business process can be exposed
for consumption by a client app or
another business process                       APPLICATION
 BPEL Process Model

                                 WSDL                Dynamic Partner/
                                 portType            Service Selection


A Business Process:
1. Comprises choreography                   1    A
   elements to define behavior
2. Exposes operations with                               B
   constraints as Web services              2    C
3. Uses other Web services to
   do its job                                           D
                                            3    E


                                       Service               External
                                       logic                 Service
 How BPEL looks like?

<process name="echoString"
     targetNamespace="urn:echo:echoService"
     xmlns:tns="urn:echo:echoService"
     xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">

 <partnerLinks>
   <partnerLink name="caller"
            partnerLinkType="tns:echoPLT"
          myRole="service"/>
 </partnerLinks>

 <variables>
   <variable name="request" messageType="tns:StringMessageType"/>
 </variables>

  <sequence name="EchoSequence">
    <receive partnerLink="caller" portType="tns:echoPT"
         operation="echo" variable="request"
         createInstance="yes" name="EchoReceive"/>
    <reply partnerLink="caller" portType="tns:echoPT"
        operation="echo" variable="request" name="EchoReply"/>
  </sequence>
</process>
How BPEL looks like?

•   <process>: root element of bpel
•   <partnerLink>: external partners
•   <variables>: variables in the process
•   <sequence>: a sequence scope
•   <receive>, <reply>: basic activities
  BPEL basic activities


• <receive> allows the business process to do a
  blocking wait for a matching message to arrive.
• <reply> allows the business process to send a
  message in reply to a message that was received
  through a <receive>. The combination of a
  <receive> and a <reply> forms a request-
  response operation for the process.
• <invoke> allows the business process to invoke
  a one-way or request-response operation on a
  portType offered by a partner.
BPEL basic activities (Cont’d)

• <assign> is used to copy data from one place to
  another.
• <throw> generates a fault from inside the
  business process.
• <terminate>: terminate the entire service
  instance. It is only available in executable
  processes.
• <wait> allows you to wait for a given time period
  or until a certain time has passed.
• <empty> allows you to insert a “do nothing”
  instruction to the process.
    Activities in BPEL vs.portType in WSDL


<process name="echoString"                                <definitions targetNamespace="urn:echo:echoService"
     targetNamespace="urn:echo:echoService"                       xmlns:tns="urn:echo:echoService"
     xmlns:tns="urn:echo:echoService"                             xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-
                                                              link/"
                                                                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.xmlsoap.org/ws/2003/03/busin
   ess-process/">                                                 xmlns="http://schemas.xmlsoap.org/wsdl/">

                                                           <message name="StringMessageType">
 <partnerLinks>                                              <part name="echoString" type="xsd:string"/>
   <partnerLink name="caller"                              </message>
                partnerLinkType="tns:echoPLT"
          myRole="service"/>                               <portType name="echoPT">
 </partnerLinks>                                             <operation name="echo">
                                                               <input message="tns:StringMessageType"/>
 <variables>                                                   <output message="tns:StringMessageType"/>
   <variable name="request"                                  </operation>
   messageType="tns:StringMessageType"/>                   </portType>
 </variables>                                              <plnk:partnerLinkType name="echoPLT">
                                                            <plnk:role name="service">
  <sequence name="EchoSequence">                             <plnk:portType name="tns:echoPT"/>
    <receive partnerLink="caller" portType="tns:echoPT"     </plnk:role>
         operation="echo" variable="request"               </plnk:partnerLinkType>
         createInstance="yes" name="EchoReceive"/>
    <reply partnerLink="caller" portType="tns:echoPT"      <!-- The service name and the TNS represent my service ID QName -
        operation="echo" variable="request"                   ->
    name="EchoReply"/>                                     <service name="echoServiceBP">
                                                           </service>
  </sequence>
</process>                                                </definitions>
The structure of activities

• <sequence>: an ordered sequence of
  steps
• <switch>: “case-statement” approach
• <while>: loop
• <pick>: execute one of several alternative
  paths
• <flow>: parallel steps
Partners

• For <invoke>
   – Invoke an operation at an external web service
   – The external web service is Process partner
• For <receive> and <reply>
   – The client sends message to invoke a local
     web service
   – The client is client partner
• <partnerLinks> : The different parties involved in
  the business process
   <partnerLinks> in BPEL


<partnerLinks>
   <partnerLink name="caller"
        partnerLinkType="tns:echoPLT"
           myRole="service"/>
</partnerLinks>

<partnerLinkType> in WSDL
<plnk:partnerLinkType name="echoPLT">
   <plnk:role name="service">
    <plnk:portType name="tns:echoPT"/>
   </plnk:role>
 </plnk:partnerLinkType>
        PartnerLink in BPEL vs.partnerLinkType in
        WSDL


<process name="echoString"                                <definitions targetNamespace="urn:echo:echoService"
     targetNamespace="urn:echo:echoService"                       xmlns:tns="urn:echo:echoService"
     xmlns:tns="urn:echo:echoService"                             xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-
                                                              link/"
                                                                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.xmlsoap.org/ws/2003/03/busin
   ess-process/">                                                 xmlns="http://schemas.xmlsoap.org/wsdl/">

                                                           <message name="StringMessageType">
 <partnerLinks>                                              <part name="echoString" type="xsd:string"/>
   <partnerLink name="caller"                              </message>
                partnerLinkType="tns:echoPLT"
          myRole="service"/>                               <portType name="echoPT">
 </partnerLinks>                                             <operation name="echo">
                                                               <input message="tns:StringMessageType"/>
 <variables>                                                   <output message="tns:StringMessageType"/>
   <variable name="request"                                  </operation>
   messageType="tns:StringMessageType"/>                   </portType>
 </variables>                                              <plnk:partnerLinkType name="echoPLT">
                                                            <plnk:role name="service">
  <sequence name="EchoSequence">                             <plnk:portType name="tns:echoPT"/>
    <receive partnerLink="caller" portType="tns:echoPT"     </plnk:role>
         operation="echo" variable="request"               </plnk:partnerLinkType>
         createInstance="yes" name="EchoReceive"/>
    <reply partnerLink="caller" portType="tns:echoPT"      <!-- The service name and the TNS represent my service ID QName -
        operation="echo" variable="request"                   ->
    name="EchoReply"/>                                     <service name="echoServiceBP">
                                                           </service>
  </sequence>
</process>                                                </definitions>
<variables>

• Data variables used by activities
   – <variable messagetype=“...”>: WSDL message;
   – <variable type=“…”>: XML Schema simple
     type;
   – <variable element=“…”>: XML Schema
     element.
• Variables associated with message types can be
  specified as input or output variables for invoke,
  receive and reply activities.
        Variables in BPEL vs.Messages in WSDL


<process name="echoString"                                <definitions targetNamespace="urn:echo:echoService"
     targetNamespace="urn:echo:echoService"                       xmlns:tns="urn:echo:echoService"
     xmlns:tns="urn:echo:echoService"                             xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-
                                                              link/"
                                                                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.xmlsoap.org/ws/2003/03/busin
   ess-process/">                                                 xmlns="http://schemas.xmlsoap.org/wsdl/">

                                                           <message name="StringMessageType">
 <partnerLinks>                                              <part name="echoString" type="xsd:string"/>
   <partnerLink name="caller"                              </message>
                partnerLinkType="tns:echoPLT"
          myRole="service"/>                               <portType name="echoPT">
 </partnerLinks>                                             <operation name="echo">
                                                               <input message="tns:StringMessageType"/>
 <variables>                                                   <output message="tns:StringMessageType"/>
   <variable name="request"                                  </operation>
   messageType="tns:StringMessageType"/>                   </portType>
 </variables>                                              <plnk:partnerLinkType name="echoPLT">
                                                            <plnk:role name="service">
  <sequence name="EchoSequence">                             <plnk:portType name="tns:echoPT"/>
    <receive partnerLink="caller" portType="tns:echoPT"     </plnk:role>
         operation="echo" variable="request"               </plnk:partnerLinkType>
         createInstance="yes" name="EchoReceive"/>
    <reply partnerLink="caller" portType="tns:echoPT"      <!-- The service name and the TNS represent my service ID QName -
        operation="echo" variable="request"                   ->
    name="EchoReply"/>                                     <service name="echoServiceBP">
                                                           </service>
  </sequence>
</process>                                                </definitions>
<faultHandlers>

• In response to faults
• Defines the recovery actions when faults occur
• Its sole aim is to undo the partial and
  unsuccessful work of a scope in which a fault
  has occurred.
        EachString: BPEL vs. WSDL


<process name="echoString"                                <definitions targetNamespace="urn:echo:echoService"
     targetNamespace="urn:echo:echoService"                       xmlns:tns="urn:echo:echoService"
     xmlns:tns="urn:echo:echoService"                             xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-
                                                              link/"
                                                                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="http://schemas.xmlsoap.org/ws/2003/03/busin
   ess-process/">                                                 xmlns="http://schemas.xmlsoap.org/wsdl/">

                                                           <message name="StringMessageType">
 <partnerLinks>                                              <part name="echoString" type="xsd:string"/>
   <partnerLink name="caller"                              </message>
                partnerLinkType="tns:echoPLT"
          myRole="service"/>                               <portType name="echoPT">
 </partnerLinks>                                             <operation name="echo">
                                                               <input message="tns:StringMessageType"/>
 <variables>                                                   <output message="tns:StringMessageType"/>
   <variable name="request"                                  </operation>
   messageType="tns:StringMessageType"/>                   </portType>
 </variables>                                              <plnk:partnerLinkType name="echoPLT">
                                                            <plnk:role name="service">
  <sequence name="EchoSequence">                             <plnk:portType name="tns:echoPT"/>
    <receive partnerLink="caller" portType="tns:echoPT"     </plnk:role>
         operation="echo" variable="request"               </plnk:partnerLinkType>
         createInstance="yes" name="EchoReceive"/>
    <reply partnerLink="caller" portType="tns:echoPT"      <!-- The service name and the TNS represent my service ID QName -
        operation="echo" variable="request"                   ->
    name="EchoReply"/>                                     <service name="echoServiceBP">
                                                           </service>
  </sequence>
</process>                                                </definitions>
       Echo Sample


      <PartnerLinks> in BEPL
<partnerLinks>
        <partnerLink name="caller“
          partnerLinkType="tns:echoPLT“ myRole="service"/>
 </partnerLinks>

   <partnerLinkType> in WSDL
 <plnk:partnerLinkType
   xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
   name="echoPLT">
    <plnk:role name="service">
     <plnk:portType name="tns:echoPT"/>
    </plnk:role>
  </plnk:partnerLinkType>
   Activities in BEPL
<sequence name="EchoSequence">
   <receive partnerLink="caller" portType="tns:echoPT"
        operation="echo" variable="request"
        createInstance="yes" name="EchoReceive"/>
   <reply partnerLink="caller" portType="tns:echoPT"
       operation="echo" variable="request" name="EchoReply"/>
 </sequence>

    PortType in WSDL
 <portType name="echoPT">
   <operation name="echo">
    <input message="tns:StringMessageType"/>
    <output message="tns:StringMessageType"/>
   </operation>
  </portType>
         Simple sample


<partnerLinks>       <PartnerLinks> and <Partners> in BEPL
  <partnerLink name="caller" partnerLinkType="tns:StockQuotePLT"/>
  <partnerLink name="provider" partnerLinkType="tns-utils:StockQuotePLT"/>
 </partnerLinks>

<partners>
  <partner name="invoker">
   <partnerLink name="caller"/>
  </partner>                                   another Web Service
  <partner name="serviceProvider">
                                                    defined in
   <partnerLink name="provider"/>
                                                 stockquote.wsdl
  </partner>
 </partners>
  Simple: StockQute Sample
<variable name="request" messageType="tns:request"/>
<variable name="response" messageType="tns:response"/>
…
<receive name="receive" partnerLink="caller" portType="tns:StockQuotePT"
        operation="gimmeQuote" variable="request"
        createInstance="yes"/>                                             Variable,
<reply name="reply" partnerLink="caller" portType="tns:StockQuotePT"       Receive and
       operation="gimmeQuote" variable="response"/>                        Reply in BPEL
<message name="request">
  <part name="symbol" type="xsd:string"/>
 </message>
 <message name="response">                                  Message
  <part name="quote" type="xsd:float"/>
 </message>
                                                            and portType in WSDL
 <portType name="StockQuotePT">
  <operation name="gimmeQuote">
   <input message="tns:request"/>
   <output message="tns:response"/>
  </operation>
 </portType>
    Invoke external WSDL
               <Invoke> in BEPL
<invoke name="invoke"
      partnerLink="provider"    portType="sqp:StockQuotePT"
      operation="getQuote" inputVariable="invocationrequest"
      outputVariable="invocationresponse"/>


                          PortType in external stockquote.wsdl

  <portType name="StockquotePT">
    <operation name="getQuote">
     <input message="tns:GetQuoteInput"/>
     <output message="tns:GetQuoteOutput"/>
    </operation>
   </portType>
      LoanApproval Sample
  Import two external Web Services plus one external definition file in WSDL



<import namespace="http://tempuri.org/services/loandefinitions"
  location="http://localhost:8080/bpws4j-samples/loanapproval/loandefinitions.wsdl"/>

LoanApprover Web Service:
<import namespace="http://tempuri.org/services/loanapprover"
location="http://localhost:8080/bpws4j-samples/loanapproval/loanapprover.wsdl"/>

LoanAssessor Web Service:
<import namespace="http://tempuri.org/services/loanassessor"
location="http://localhost:8080/bpws4j-samples/loanapproval/loanassessor.wsdl"/>
      <PartnerLinkType> in WSDL


<plnk:partnerLinkType xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
  name="loanApprovalLinkType">
  <plnk:role name="approver">
   <plnk:portType name="apns:loanApprovalPT"/>
  </plnk:role>
 </plnk:partnerLinkType>


  <portType name="loanApprovalPT">      portType in loanapprover.wsdl
    <operation name="approve">
     <input message="loandef:creditInformationMessage"/>
     <output message="tns:approvalMessage"/>
     <fault name="loanProcessFault"
         message="loandef:loanRequestErrorMessage"/>
    </operation>
   </portType>
     <PartnerLinkType> in WSDL

<plnk:partnerLinkType xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" na
  <plnk:role name="assessor">
   <plnk:portType name="asns:riskAssessmentPT"/>
  </plnk:role>
 </plnk:partnerLinkType>




<portType name="riskAssessmentPT">        portType in loanassessor.wsdl
  <operation name="check">
   <input message="loandef:creditInformationMessage"/>
   <output message="tns:riskAssessmentMessage"/>
   <fault name="loanProcessFault"
       message="loandef:loanRequestErrorMessage"/>
  </operation>
 </portType>
Links defined for dependencies between the
activities in BEPL

 <links>
     <link name="receive-to-assess"/>
     <link name="receive-to-approval"/>
     <link name="approval-to-reply"/>
     <link name="assess-to-setMessage"/>
     <link name="setMessage-to-reply"/>
     <link name="assess-to-approval"/>
    </links>
 <receive name="receive1" partnerLink="customer"        Receive in BEPL
        portType="apns:loanApprovalPT"
        operation="approve" variable="request"
        createInstance="yes">                            condition
    <source linkName="receive-to-assess"
         transitionCondition="bpws:getVariableData('request', 'amount')&lt;10000"/>
    <source linkName="receive-to-approval"
         transitionCondition="bpws:getVariableData('request', 'amount')&gt;=10000"/>
   </receive>
                                           <link name="receive-to-assess"/>
                                           <link name="receive-to-approval"/>
<portType name="loanApprovalPT">
  <operation name="approve">                      portType in loanapprover.wsdl
   <input message="loandef:creditInformationMessage"/>
   <output message="tns:approvalMessage"/>
   <fault name="loanProcessFault"
        message="loandef:loanRequestErrorMessage"/>
  </operation>
 </portType>
                     <Invoke> in BEPL
<invoke name="invokeAssessor" partnerLink="assessor"
      portType="asns:riskAssessmentPT"
      operation="check"                     <link name="receive-to-assess"/>
      inputVariable="request"               <link name="assess-to-setMessage"/>
      outputVariable="riskAssessment">      <link name="assess-to-approval"/>
   <target linkName="receive-to-assess"/>
   <source linkName="assess-to-setMessage"
        transitionCondition="bpws:getVariableData('riskAssessment', 'risk')='low'"/>
   <source linkName="assess-to-approval"
        transitionCondition="bpws:getVariableData('riskAssessment', 'risk')!='low'"/>
  </invoke>
<portType name="riskAssessmentPT">
  <operation name="check">                                      condition
    <input message="loandef:creditInformationMessage"/>
    <output message="tns:riskAssessmentMessage"/>
    <fault name="loanProcessFault"
        message="loandef:loanRequestErrorMessage"/>
  </operation>                              portType in loanassessor.wsdl
 </portType>
A Sample – LoanApproval.bepl

• <process name="loanApprovalProcess"
•      targetNamespace="http://acme.com/loanprocessing"
•      suppressJoinFailure="yes"
•      xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
•      xmlns:lns="http://loans.org/wsdl/loan-approval"
•      xmlns:loandef="http://tempuri.org/services/loandefinitions"
•      xmlns:asns="http://tempuri.org/services/loanassessor"
•      xmlns:apns="http://tempuri.org/services/loanapprover">

•   <variables>
•    <variable name="request"
•           messageType="loandef:creditInformationMessage"/>
•    <variable name="riskAssessment"
•           messageType="asns:riskAssessmentMessage"/>
•    <variable name="approvalInfo"
•           messageType="apns:approvalMessage"/>
•    <variable name="error"
•           messageType="loandef:loanRequestErrorMessage"/>
•   </variables>
• <partnerLinks>
•   <partnerLink name="customer"
•        partnerLinkType="lns:loanApprovalLinkType"
•        myRole="approver"/>
•   <partnerLink name="approver"
•        partnerLinkType="lns:loanApprovalLinkType"
•        partnerRole="approver"/>
•   <partnerLink name="assessor"
•        partnerLinkType="lns:riskAssessmentLinkType"
•        partnerRole="assessor"/>
• </partnerLinks>
• <faultHandlers>
•   <catch faultName="lns:loanProcessFault"
•       faultVariable="error">
•    <reply partnerLink="customer"
•        portType="apns:loanApprovalPT"
•        operation="approve"
•        variable="error"
•        faultName="invalidRequest"/>
•   </catch>
• </faultHandlers>
• <flow>
•    <links>
•     <link name="receive-to-assess"/>
•     <link name="receive-to-approval"/>
•     <link name="approval-to-reply"/>
•     <link name="assess-to-setMessage"/>
•     <link name="setMessage-to-reply"/>
•     <link name="assess-to-approval"/>
•    </links>
• <receive name="receive1" partnerLink="customer"
•          portType="apns:loanApprovalPT"
•          operation="approve" variable="request"
•          createInstance="yes">
•     <source linkName="receive-to-assess"
•           transitionCondition="bpws:getVariableData('request',
  'amount')&lt;10000"/>
•     <source linkName="receive-to-approval"
•           transitionCondition="bpws:getVariableData('request',
  'amount')&gt;=10000"/>
•    </receive>
• <invoke name="invokeAssessor" partnerLink="assessor"
•          portType="asns:riskAssessmentPT"
•          operation="check"
•          inputVariable="request"
•          outputVariable="riskAssessment">
•     <target linkName="receive-to-assess"/>
•     <source linkName="assess-to-setMessage"
•            transitionCondition="bpws:getVariableData('riskAssessment',
  'risk')='low'"/>
•     <source linkName="assess-to-approval"
•            transitionCondition="bpws:getVariableData('riskAssessment',
  'risk')!='low'"/>
•    </invoke>

•   <assign name="assign">
•    <target linkName="assess-to-setMessage"/>
•    <source linkName="setMessage-to-reply"/>
•    <copy>
•     <from expression="'yes'"/>
•     <to variable="approvalInfo" part="accept"/>
•    </copy>
•   </assign>
• <invoke name="invokeapprover"
•        partnerLink="approver" portType="apns:loanApprovalPT"
•        operation="approve"
•        inputVariable="request"
•        outputVariable="approvalInfo">
•    <target linkName="receive-to-approval"/>
•    <target linkName="assess-to-approval"/>
•    <source linkName="approval-to-reply" />
•   </invoke>

•     <reply name="reply" partnerLink="customer"
    portType="apns:loanApprovalPT"
•          operation="approve" variable="approvalInfo">
•       <target linkName="setMessage-to-reply"/>
•       <target linkName="approval-to-reply"/>
•     </reply>
•    </flow>
•   </process>