About Me
Facebook
Facebook
Linked In
Linked In
Twitter
Twitter
YouTube
YouTube
Google +
Google +

Thursday, August 8, 2013

Developing Simple Mediation Module using WID & WESB


Introduction:
This article demonstrates the development of Mediation module using WebSphere Integration developer and deployment in WebSphere Enterprise Service Bus. Here we are going to implement the mediation module by using different mediation primitives, like Custom mediation, Service Integration, XSLT transformation and BO Map.
Prerequisites for this sample are:
  1. WebSphere ESB.
  2. WebSphere Integration Developer.
Overview:
This sample is to get Customer details by using Customer ID. Mediation module will trigger a request with Customer ID; it will be logged into console then we are going to map the customer Id to our service (Java Component will be developed for populate customer details) by using XSLT Transformation. Once the customer id mapped we need to invoke service to get customer details, so we are going to use Service invoke primitive to call Java component. Finally we are going to map response to our mediation by using BO Map.
Implementation:
            To implement this sample we need to follow these steps:
  • Create the library.
  • Create an Interface and Business Objects.
  • Create the Mediation Module.
  • Implement the Mediation and Java Component. 
  • Test Mediation Module.
Create the library:
Right click on Business Integration view and go to New à Library
Give the library name as EAI_Library and click on Finish.
Create an Interface and Business Objects:
Right click on Data Types under EAI_Library go to New Business Objects.

Give the Business Object name as ‘CustomerDetailsBO’ and click on finish.
Add parameters to the Business Object and same the changes. The Business Object will be as shown below.
Right click on EAI_Library go to New a Interfaces
Give the Interface name as ‘CustomerInterface’ and click on finish.
Add a request response operation and give name as getCustomer and change the request, response parameters name as shown below.
This interface we are going to use for implement Mediation Component.
Create another interface called as ‘CustomerService’. It will be as shown below.
This interface we are going to use for implement Java Component.
Create the Mediation Module:
Right click on Business Integration view go to New and Select Mediation Module.
Give the name as ‘EAI_CustomerMediation’ select target runtime as ‘WebSphere ESB Server v7.0’ and Mediation component name as ‘CustomerMediation’ then click on next.
Select ‘EAI_Library’ as dependency and click on finish.
So now our mediation module has been created, so we need to implement the mediation component to invoke external service (here Java component).
Implement the Mediation and Java component:
Open the Assembly diagram add the customerInterface to CustomerMediation and reference as CustomerService.
Right click on ‘CustomerMediation’ and select Wire reference to New à Components.
Rename Java Component name as “CustomerService”.
Right click on CustomerMediation and select Generate Implementation.
Right click on ‘getCustomer’ and select open implementation in Mediation flow.
Select Blank Mediation Flow.
Drag and drop 2 custom mediation primitives, one XSLT transformation, one Service invoke, one message Validator, one stop, one fail and Business Object Map into CustomerMediation pallet. Rename and wire the primitives as show below.
Now I am going to explain each and every Mediation primitive functionality and implementation.
Custom Primitive: It’s used for transform message with custom java code.
Select Log_Entry go to properties à Details and select Implementation as visual.
Here we are going to print the request SMO body. The implementation is as shown below.
The same way implement Log_Exit for display Response SMO body as shown below.
MessageValidator: it is used for validate the request which has received by mediation flow.
Select MessageValidator Properties à Details and edit the Root as shown below.
It will validate the customerID, if the customer ID null, it will throw an exception.
XSLTransformation: It is used for transfer the messages. We can directly move the request or we can write our custom logic here.
Double click on XSLT_CustomerService_Request give the name as ‘XSLT_CustomerService_Request’ then click on next then select Message Root as ‘/’ then click on finish. Drag the wire from CustomerID to CustID as shown below.
Here we are sending request as customerID to Customer Service.
Service Invoke: It is used for invoke services. Here we don’t need to implement any thing for normal invocation, whenever we are placing this primitive it will ask for Interface name and operation name, we need to select at that time.
Business Object Map: It is used for transfer the messages. We can directly move the request or we can write our custom logic here.
Double click on BOM_CustomerServiceResponse give the name as ‘BOM_CustomerServiceResponse’ then click on next then select Message Root as ‘/’ then click on finish. Drag the wire from CustomerDetails as shown below.
Fail: It is used for throw an exception in case any failure with associated privative. Here we can write our own custom exception message to.
Select Fail primitive à Properties à Details enter custom exception message as shown below.
Stop: It is used for stop the flow. We don’t need to implement any thing for this primitive.
The final flow is look like below.
Now we need to implement Java component. Open Assembly diagram and double click on CustomerService Java component.
Copy and paste the following code into CustomerService java component.

import com.ibm.websphere.bo.BOFactory;
import com.ibm.websphere.sca.ServiceManager;
import commonj.sdo.DataObject;
public class CustomerServiceImpl {
            public CustomerServiceImpl() {
                        super();
            }
            @SuppressWarnings("unused")
            private Object getMyService() {
                        return (Object) ServiceManager.INSTANCE.locateService("self");
            }
            public DataObject getCustInfo(String custID) {
                        System.out.println("Entering into Customer Service for customer Id: "+custID);
                        //Create a DataObject.
                        BOFactory boFactory = (BOFactory) new ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
                        DataObject customer = boFactory.create("http://EAI_Library", "CustomerDetailsBO");
                        if(custID!=null && custID.equalsIgnoreCase("C123")){
                                    customer.setString("CustomerID", custID);
                                    customer.setString("CustomerName", "AMEER BASHA");
                                    customer.setString("Address", "HYD");
                                    customer.setString("Phome", "+91-9000001122");
                                    customer.setString("EmailID", "ameerg1986@gmail.com");
                        }else if(custID!=null && custID.equalsIgnoreCase("C124")){
                                    customer.setString("CustomerID", custID);
                                    customer.setString("CustomerName", "RAVI");
                                    customer.setString("Address", "HYD");
                                    customer.setString("Phome", "+91-9000001133");
                                    customer.setString("EmailID", "ameerg@gmail.com");
                        }
                        System.out.println("Exiting from Customer Service for Customer : "+customer);
                        return customer;
            }
}
Save the changes. Now we have completed implementation of our mediation module.
Test the Mediation Module:
            Now we need to test our application. Deploy the Mediation Module into WebSphere Enterprise service Bus server.
Select Servers view and click on start Server button at right corner green button.
Right click on WebSphere ESB V7.0 select ‘Add or Remove Projects’ select EAI_CustomerMediation and click on Add button and click on Finish.
Once Application deployed, open the Assembly diagram right click on ‘CustomerMediation’ and select Test Component.
Now enter the CustomerID as C123 and click on continue button as shown below.
Now the response as shown below.
Now we can see the console for print the request and response object as we implemented in custom mediation primitive (Log_Entery and Log_Exit) to print into the consol. Please look in to below.
Conclusion:
In this article we learnt how to develop a simple mediation module and implementation by using some of the mediation primitives like XSLT Transformation, Custom mediation primitive, Business Object Map, Service Invoke, Fail and stop primitive. We will learn more about mediation module implementation by using other mediation primitives in future articles.
Downloads:
File Name
Description
      Size
Download
CustomerMediation.zip
CustomerMediation Sample
32 KB
MediationModule.pdf
Developing Mediation Module using WID
791 KB

2 comments :

Nivedita Ghosh said...

nice article...well written to understand mediation flow for beginner...

Anonymous said...

CustomerMediation.zip file is not found ... pls upload the file ... thanks

Post a Comment

Designed By AMEER BASHA G