Skip to main content

Make composite business services adaptable with points of variability, Part 4: Using WebSphere Enterprise Service Bus mediation modules

Carl Osipov (osipov@us.ibm.com), Software Architect, IBM, Software Group
author photo
Carl Osipov is an experienced software architect with the Strategy and Technology organization in IBM Software Group. His skills are in the area of distributed computing, speech application development, and computational natural language understanding. He has published and presented on Service-Oriented Architecture and conversational dialog management to peers in the industry and academia. His current focus is on design of reuse techniques for composite business services.
Ying Chun Guo (guoyingc@cn.ibm.com), Software Developer, IBM, Software Group
author photo
Ying Chun Guo works as a software engineer at the China Technology Institute, China Software Development Laboratory. She is currently working on composite business services (CBS) and Service-Oriented Architecture (SOA).

Summary:  Explore options for building points of variability in Service-Oriented Architecture composite business services in this series. In this article, learn options for designing and developing composite business services (CBS) to cope with changing requirements. Discover IBM® WebSphere® Enterprise Service Bus (ESB) capabilities in relation to WebSphere Process Server and use ESB to enable runtime integration with Web services. A banking scenario shows you how to use ESB Service Component Architecture (SCA) mediation modules for dynamic binding across Web service endpoints with different quality of service (QoS) levels.

Date:  17 Jul 2007
Level:  Intermediate
Comments:  

Introduction

Part 3 of this series, Using selectors and business rules for dynamicity, describes an approach for enabling points of variability (POV) in composite business services (CBS) by using business rules and selectors. Although that approach can improve flexibility, there are some drawbacks. For example, you can add new targets to a selector at runtime using the WebSphere Process Server administrative console or the corresponding scripting interface, but the following additional capabilities are needed:

  • Add new selector targets programmatically at runtime (see Part 1, "Choosing the right implementation)."
  • Add new selector targets regardless of the underlying invocation model (synchronous or asynchronous) or the implementation protocol.

    For example, you could realize this capability by dynamically switching between a synchronous SOAP/HTTP and an asynchronous SOAP/Java™ Message Service (JMS)-based service.

Stay tuned for Part 5, which will augment the technique described in this article by using WebSphere Service Registry and Repository (WSRR) for dynamic lookup for service endpoints and associated metadata. For a comparison of the approaches, see Part 1.

This article provides a solution to the technical limitations just described using an SCA mediation module in WebSphere Enterprise Service Bus (ESB) 6.0.1. WebSphere Process Server (Process Server) includes ESB, so everything in this article applies to Process Server as well. You get step-by-step examples for implementing a Service Component Architecture (SCA) mediation module in ESB and you learn the portlet and Business Process Execution Language (BPEL) process implementation details to support POV in the scenario.

Use case for funds transfer services

The solution in this article is based on a funds transfer scenario with two fictional banks: First Bank of North America (1st bank) and Second Canada Bank (2nd bank). The 1st bank wants to implement an SOA composite business service for funds transfer. The implementation for the service must support several features:

  • Expose functions using a portlet-based user interface (UI).
  • Handle internal bank funds transfer (from one account to another within the same bank) by relying on an existing legacy implementation that is exposed as a SOAP/HTTP Web service.
  • Handle external bank funds transfer (from an account in a bank to another account in an external bank) by relying on an existing batch transfer implementation that is exposed as a SOAP/JMS Web service.
  • Expose a common UI to the customer for funds transfers from one account to another, regardless of whether one of the accounts is an external bank account.

In the use case, Bob Clark is a bank customer of the 1st bank who logs on to the bank's portal and navigates to the Funds Transfer portlet.

If Bob makes a transfer to another account in the 1st bank, the transfer is executed synchronously. It is validated by the CBS to ensure that sufficient funds exist in the source account. If the validation business logic passes, the funds transfer is executed and a response with the success notification message is returned to the customer. The amounts on both source and target accounts are updated to reflect the transfer.

If Bob makes a transfer to an external account at 2nd bank, the transfer is executed asynchronously:

  1. The money is debited from the customer's 1st bank account.
  2. A funds transfer request message is submitted to a batch service that handles cross-bank transfers.
  3. The customer is notified with a message that the transfer has been submitted, and funds may take time to arrive at the 2nd bank account.
  4. Once the batch cross-bank service handles the transfer of funds, Bob Clark can log in to the 2nd bank's portal and verify that the funds transfer went through successfully.

In the remainder of this article you learn how to implement the use case using an ESB mediation module.


Services to transfer funds

Part of the implementation of the use case involves two Web services: the Internal Bank Funds Transfer Service and the External Bank Funds Transfer Service. The services use different underlying message protocols, but implement the same SCA interface.

The Internal Bank Funds Transfer Service has a SOAP over HTTP binding and provides a synchronous response within hundreds of milliseconds. The External Bank Funds Transfer Service uses SOAP over JMS and provides an asynchronous response that can return in a range from minutes to hours. The interface for funds transfer, called AccountTransferService shown in Figure 1, exposes the services for an account.


Figure 1. AccountTransferService interface
AccountTransferService interface

The Internal Bank Funds Transfer Service is generated from a stateless session Enterprise JavaBeans (EJB) component. Upon an invocation, the specified amount of money (input variable: amount) is debited from an account (input variable: fromAccId), and immediately credited to another account (input variable: toAccId) in the same bank (precondition: fromBankId == toBankId). To ensure atomicity, a component-managed EJB transaction is used to execute the makeTransfer method in a single transaction scope.

The External Bank Funds Transfer Service is also generated from a stateless session bean. Upon invocation, the specified amount (input variable: amount) of money is debited from an account (input variable: fromAccId) in a bank (input variable: fromBankId), followed by an invocation of the existing batch transfer service called Batch Interbank Funds Transfer Service. Since the batch service may take an indeterminate amount of time, it is invoked asynchronously. In this case, a bean-managed transaction is used.

Asynchronous invocation SCA wrapper component

By default, the invocation of an imported Web service in an SCA module is synchronous, so you need to create an asynchronous invocation wrapper for the External Bank Funds Transfer Service.

  1. Create an SCA module and import the External Bank Funds Transfer Service into this module using a Web service binding.
  2. Create a new interface named AsyncAccountTransferInterface containing a one-way invocation, as shown in Figure 2. The one-way method is nearly the same as the makeTransfer method, except it contains no responses or faults and includes an additional parameter called endpoint.

    Figure 2. AsyncAccountTransferInterface
    AsyncAccountTransferInterface

  3. Create a BPEL component with the interface AsyncAccountTransferInterface, as shown in Figure 3.

    Figure 3. Implementation of AsycService
    Implementation of AsyService

    Add a snippet activity to perform dynamic binding to the imported Web service using the endpoint address from the parameter Endpoint, as shown in Listing 1.


Listing 1. Perform dynamic binding to imported Web service
com.ibm.websphere.sca.addressing.EndpointReference eRef = 
    com.ibm.websphere.sca.addressing.EndpointReferenceFactory.INSTANCE.
       createEndpointReference();

eRef.setAddress(Endpoint);

com.ibm.websphere.sca.Service echoService = (com.ibm.websphere.sca.Service) 
  com.ibm.websphere.sca.ServiceManager.INSTANCE.
    getService("AccountTransferServicePartner", eRef);

commonj.sdo.DataObject response = 
  (commonj.sdo.DataObject)echoService.invoke("makeTransfer",serviceRequestObj);


Figure 4. Assembly diagram
Assembly diagram

Mediation module for funds transfer

A mediation module is created to dynamically route a funds transfer request to either the Internal Funds Transfer Service or the External Funds Transfer Service, depending on whether the funds transfer has an internal or external destination.

The mediation module exposes an interface, as shown in Figure 5. The input parameters contain all the input parameters of the AccountTransferService. There are two string parameters with values for the endpoint addresses of the two fund transfer services.


Figure 5. Mediation module interface
Mediation module interface

Figure 6 shows the assembly diagram. The component AccountTransfer is a Web service binding import that is exported by the Internal Funds Transfer Service. The component AsycAccountTransfer is a Web service binding import that is exported by the asynchronous wrapper of the External Funds Transfer Service. The two import components are wired to the mediation flow component called Mediation1. This component is exported with a Web service binding (Mediation1Export, shown here).


Figure 6. Mediation assembly diagram
Mediation assembly diagram

The mediation logic for funds transfers are in the flow shown in Figure 7.


Figure 7. Mediation flow
Mediation flow

A data type BankContext, shown in Figure 8, is set as the transient context, which contains the variable ifInternalBank to show whether the request is an internal transfer request or not. ifInternalBank is an XSL transformation primitive.


Figure 8. Transient context object
Transient context object

An XSL function, shown in Figure 9, is used to compare whether fromBankId is the same as toBankId, and set the result to the transient context variable.


Figure 9. XSLT function
XSLT Function

Filter, a message filter primitive shown in Figure 10, implements the following logic:

  • If the transient context variable is false, the request is an external transfer request. The message will be routed to AsycAccountTransfer, which will dynamically bind to the External Funds Transfer Service and asynchronously invoke it.
  • Otherwise, the request will be routed to a custom mediation primitive to dynamically invoke the Internal Funds Transfer Service.

Figure 10. Details of filter
Details of filter

CustomMediation is a custom mediation primitive. It has an execute method, which implements the custom mediate logic. In this method, the Internal Funds Transfer Service is dynamically bound to an address that is passed to the mediation module as parameter interEndpoint and synchronously invoked. Listing 2 shows the code snippet.


Listing 2. Code snippet of custom mediation primitive
public DataObject execute(DataObject input1) {

  BOFactory boFactory = (BOFactory) ServiceManager.INSTANCE.
    locateService("com/ibm/websphere/bo/BOFactory");

  // (1) Create endpoint reference
  EndpointReference eRef = EndpointReferenceFactory.INSTANCE.
    createEndpointReference();

  String address = input1.getString("interEndpoint");
  eRef.setAddress(address);
	      
  // (2) invoke service and extract response payload
  Service echoService = (Service) 
  ServiceManager.INSTANCE.getService("AccountTransferServicePartner", eRef);
	      
  // (3) Prepare input parameter to invoke partner service
  DataObject requestMsg = boFactory.
    createByMessage("http://accounttransferservice","makeCrossBankTransferRequest");
	
  DataObject requestEle = boFactory.
    createByElement("http://accounttransferservice","makeCrossBankTransfer");
	
  requestEle.setString("fromBankId",input1.getString("fromBankId"));
  requestEle.setString("fromAccId",input1.getString("fromAccId"));
  requestEle.setString("toBankId",input1.getString("toBankId"));
  requestEle.setString("toAccId",input1.getString("toAccId"));
  requestEle.setString("amount",input1.getString("amount"));
  requestMsg.setDataObject("parameters",requestEle);
	
  // (4) Invoke service synchronously
  DataObject responseMsg = 
    (DataObject) echoService.invoke("makeCrossBankTransfer",requestEle);
	
  return null;
}

After custom mediation is implemented, the assembly diagram will be changed as reflected in Figure 11. An additional Java component called CustomMediation implements the logic of custom mediation.


Figure 11. CustomMediationLogic component
CustomMediationLogic component

Portlets and configuration for the mediation module

A portlet called the SaaSBankTransferCustomerPortlet is created to provide a UI for fund transfer service, as shown in Figure 12.


Figure 12. Portlet
Portlet

You can configure the endpoint addresses of the Internal Bank Funds Transfer service, the External Bank Funds Transfer service, and the mediation module (Account Transfer Services Endpoint) through the config mode of the portlet, as shown in Figure 13. When the user clicks the Transfer Funds button in this portlet, the mediation module is invoked with the two endpoint address of internal and external bank funds transfer service as parameters.


Figure 13. Portlet Configuration Page
Portlet Configuration Page

Summary

In this article you examined how to enable points of variability in CBS with ESB mediation modules. You also learned how mediation modules allow programmatic routing across multiple endpoints using different underlying messaging protocols. Understanding the banking transfer scenario implementation details, which uses Web services, SCA modules, a mediation module, and a portlet, should be helpful as you develop your own solutions. Ultimately, this approach will help your solution be more flexible to adapt to continually changing requirements.


Resources

Learn

Get products and technologies

  • Get started now! Download more IBM product evaluation versions and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere.

Discuss

About the authors

author photo

Carl Osipov is an experienced software architect with the Strategy and Technology organization in IBM Software Group. His skills are in the area of distributed computing, speech application development, and computational natural language understanding. He has published and presented on Service-Oriented Architecture and conversational dialog management to peers in the industry and academia. His current focus is on design of reuse techniques for composite business services.

author photo

Ying Chun Guo works as a software engineer at the China Technology Institute, China Software Development Laboratory. She is currently working on composite business services (CBS) and Service-Oriented Architecture (SOA).

Comments



Trademarks

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services
ArticleID=240047
ArticleTitle=Make composite business services adaptable with points of variability, Part 4: Using WebSphere Enterprise Service Bus mediation modules
publish-date=07172007
author1-email=osipov@us.ibm.com
author1-email-cc=
author2-email=guoyingc@cn.ibm.com
author2-email-cc=