HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Make Your Services Flow by Doron Sherman
WSJ Vol 03 Issue 07 - pg.18



Listing 1: BPEL Code

<process name="AvailableToPromiseFlow"
         targetNamespace="http://demo.cxdn.com"
         suppressJoinFailure="yes"
         xmlns:tns="http://demo.cxdn.com"
         xmlns:isns="http://demo.cxdn.com"
         xmlns:pssns="http://demo.cxdn.com"
         xmlns:shsns="http://demo.cxdn.com"
         xmlns:stesns="http://demo.cxdn.com"
         xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
         xmlns:sref="http://schemas.xmlsoap.org/ws/2002/07/
		 service-reference/"
         xmlns="http://schemas.xmlsoap.org/ws/2002/07/
		 business-process/">

  <partners>
    <partner name="client"
             serviceLinkType="tns:AvailableToPromiseFlow"
             myRole="AvailableToPromiseFlowService"
             partnerRole="AvailableToPromiseFlowRequester"/>

    <partner name="InventoryService"
             serviceLinkType="isns:InventoryService"
             myRole="InventoryServiceRequester"
             partnerRole="InventoryServiceService"/>

    <partner name="ProductionScheduleService"
             serviceLinkType="pssns:ProductionScheduleService"
             myRole="ProductionScheduleServiceRequester"
             partnerRole="ProductionScheduleServiceService"/>

    <partner name="SupplierHubService"
             serviceLinkType="shsns:SupplierHubService"
             myRole="SupplierHubServiceRequester"
             partnerRole="SupplierHubServiceService"/>

    <partner name="SupplierTimeoutExceptionService"
     serviceLinkType="stesns:SupplierTimeoutExceptionService"
             myRole="SupplierTimeoutExceptionServiceRequester"
     partnerRole="SupplierTimeoutExceptionServiceService"/>
  </partners>

  <containers>
    <!-- input of this process -->
    <container name="input"
messageType="tns:initiateAvailableToPromiseFlow
SoapRequest"/>

    <!-- input of Inventory Service-->
    <container name="inventoryRequest"
messageType="isns:initiateInventoryServiceSoapRequest"/>
               
    <!-- output of Inventory Service-->
    <container name="inventoryResponse"
messageType="isns:onInventoryServiceResultSoapRequest"/>
               
    <!-- input of Production Schedule Service-->
    <container name="productionScheduleRequest"
messageType="pssns:initiateProductionScheduleService
SoapRequest"/>
               
    <!-- output of Production Schedule Service-->
    <container name="productionScheduleResponse"
messageType="pssns:onProductionScheduleServiceResult
SoapRequest"/>
               
    <!-- input of Supplier Hub Service-->
    <container name="supplierHubRequest"
messageType="shsns:initiateSupplierHubServiceSoapRequest"/>
               
    <!-- output of Supplier Hub Service-->
<container name="supplierHubResponse"
messageType="shsns:onSupplierHubServiceResult
SoapRequest"/>
               
    <!-- input of Supplier Timeout Exception Service-->
    <container name="supplierTimeoutExceptionRequest"
messageType="stesns:initiateSupplierTimeoutExceptionService
SoapRequest"/>
               
    <!-- output of Supplier Timeout Exception Service-->
    <container name="supplierTimeoutExceptionResponse"
messageType="stesns:onSupplierTimeoutException
ServiceResult
SoapRequest"/>
    
               
    <!-- output of this process -->
<container name="output"
messageType="tns:onAvailableToPromiseFlowResult
SoapRequest"/>
  </containers>

  <sequence>
    
    <!-- receive input from the client -->
    <receive name="receiveInput" partner="client"
             portType="tns:AvailableToPromiseFlow"
             operation="process" container="input"
             createInstance="yes"/>
             
    <!-- initialize the output -->
    <assign>
        <copy>
            <from container="input" part="parameters"
            query="//xmlRequest"/>
            <to container="output" part="parameters"
     query="/onAvailableToPromiseFlowResult/xmlRequest"/>
        </copy>
    </assign>              

    <flow>

      <!-- invoke Inventory Service -->
      <sequence>
        <!-- initialize the input of Inventory Service -->

        <assign>
            <copy>
                <from container="input" part="parameters"
                    query="//xmlRequest"/>
      <to container="inventoryRequest" part="parameters"
         query="/initiateInventoryService/xmlRequest"/>
            </copy>
        </assign>

        <!--  initiate the remote process -->

        <invoke name="invokeIS" partner="InventoryService"
                portType="isns:InventoryService"
  operation="initiate" inputContainer="inventoryRequest"/>

        <!--  receive the result of the remote process -->

 <receive name="receive_invokeIS" partner="InventoryService"
     portType="isns:InventoryServiceCallback"
    operation="onResult" container="inventoryResponse"/>

      </sequence>

      <!-- invoke Production Schedule Service-->
      <sequence>
  <!-- initialize the input of Production Schedule Service-->
        <assign>
            <copy>
                <from container="input" part="parameters"
                    query="//xmlRequest"/>
<to container="productionScheduleRequest" part="parameters"
query="/initiateProductionScheduleService/xmlRequest"/>
            </copy>
        </assign> 
        <!--  initiate the remote process -->
   <invoke name="invokePSS" partner="ProductionScheduleService"
          portType="pssns:ProductionScheduleService"
operation="initiate" inputContainer="productionScheduleRequest"/>

        <!--  receive the result of the remote process -->
<receive name="receive_invokePSS"
partner="ProductionScheduleService"
     portType="pssns:ProductionScheduleServiceCallback"
operation="onResult" container="productionScheduleResponse"/>
      </sequence>

    </flow>

    <!-- switch depends on the input value -->
    <switch>
<case condition="bpws:getContainerData
('input', 'parameters','//xmlRequest/Weight') > 
bpws:getContainerData('inventoryResponse',
'parameters','//result') +
        bpws:getContainerData('productionScheduleResponse',
		'parameters','//result')">
            <sequence>
                <assign>
                    <copy>
    <from container="input" part="parameters"
    query="//xmlRequest"/>
    <to container="supplierHubRequest" part="parameters"
    query="/initiateSupplierHubService/xmlRequest"/>
                    </copy>
                    <copy>
<from expression="bpws:getContainerData
('input', 'parameters','//xmlRequest/Weight') -
bpws:getContainerData('inventoryResponse',
'parameters','//result') -
bpws:getContainerData('productionScheduleResponse',
'parameters','//result')"/>
    <to container="supplierHubRequest" part="parameters"
    query="/initiateSupplierHubService/xmlRequest/Weight"/>
    </copy>
    </assign>
                
          <!--  initiate the remote process -->
  <invoke name="invokeAsyncService" partner="SupplierHubService"
      portType="shsns:SupplierHubService"
  operation="initiate" inputContainer="supplierHubRequest"/>


       <!--  receive the result of the remote process -->
        <pick>
     <onMessage partner="SupplierHubService"
     portType="shsns:SupplierHubServiceCallback"
    operation="onResult" container="supplierHubResponse">
      <empty/>
      </onMessage>
     <onAlarm for="PT30S">
      <sequence>
 <!-- initialize the input of Supplier Timeout Exception Service-->
     <assign>
      <copy>
  <from container="input" part="parameters"
   query="//xmlRequest"/>
<to container="supplierTimeoutExceptionRequest" part="parameters"
query="/initiateSupplierTimeoutExceptionService/xmlRequest"/>
     </copy>
     </assign>
      <!--  initiate the remote process -->
<invoke name="invokeSTES" partner="SupplierTimeout
ExceptionService"
 portType="stesns:SupplierTimeoutExceptionService"
operation="initiate" inputContainer="supplierTimeout
ExceptionRequest"/>

  <!--  receive the result of the remote process -->
<receive name="receive_invokeSTES" partner="SupplierTimeout
ExceptionService"
  portType="stesns:SupplierTimeoutExceptionServiceCallback"
operation="onResult" container="supplierTimeout
xceptionResponse"/>
     </sequence>
   </onAlarm>
   </pick>
            
            </sequence>
        </case>
        <otherwise>
            <empty/>
        </otherwise>
    </switch>


    <assign>
        <copy>
            <from expression="5"/>
            <to container="output" part="parameters"
            query="/onAvailableToPromiseFlowResult/Price"/>
        </copy>
    </assign>
    
    <assign>
        <copy>
            <from expression="'yes'"/>
            <to container="output" part="parameters"
            query="/onAvailableToPromiseFlowResult/Available"/>
        </copy>
    </assign>    
        
            

    <!-- callback initiator of this flow with digital receipt -->
    <invoke name="replyOutput" partner="client"
            portType="tns:AvailableToPromiseFlowCallback"
            operation="onResult" inputContainer="output"/>

  </sequence>

</process>