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

Wednesday, August 14, 2013

Build & Integrate the Applications with SCA binding in WPS

Introduction:    
            Service Component Architecture (SCA) provides a simple, powerful programming model for implementing applications based on the Open SCA specifications. The SCA modules of WebSphere Process Server use import and export bindings to interoperate with Open SCA services.
            SCA application invokes WebSphere Process Server SCA applications using an export binding. An Open SCA application receives a call from a WebSphere Process Server SCA application using an import binding.
           The SCA binding is used for invocations between SCA modules. This binding type is the simplest to configure and provides seamless integration between modules. An SCA binding provides a consistent means for communicating across module boundaries in a WebSphere Process Server or WebSphere ESB environment. The underlying protocol used by the SCA binding is selected automatically based on the invocation pattern used by the client module.
Overview:   
            SCA provides four invocation patterns.
  • Synchronous - Client issues a request and waits for the response.
  • Asynchronous one-way - Client issues a request and a response is not expected.
  • Asynchronous deferred response - Client issues a request and the response will be requested by the client at a later point in time.
  • Asynchronous call back - Client issues a request and the target will call a service implemented by the client with the response.
            The WebSphere Process Server or WebSphere ESB SCA runtime will decide when to use the underlying system integration bus (for asynchronous invocation patterns), or RMI/IIOP (for the synchronous invocation pattern).
          The SCA binding capability is driven by the export. During the installation process of an SCA module to a WebSphere Process Server, the necessary support artifacts are created:
For asynchronous invocations, cell scoped service integration bus (SIBus) destinations are created in the SCA.SYSTEM.<cell name>.Bus.
          For synchronous communication, a cell scoped name space binding those points to the module session bean is created; a module session bean is a stateless session bean that is used by the module for a variety of purposes, such as unit of work boundaries, security configuration, and so on.
          The import and export files work together, where the import file contains important information about the export, helping any number of clients to import a target service. Using the information in the .import file and the invocation pattern (sync or async) the SCA runtime identifies whether to use a SIBus destination or a WebSphere name space binding.
       Here we are going to learn, how to creating import, export and configuring SCA binding for those import, export. He are we are going to develop a simple application for Order creation and approval.
Implementation:   
          Here we are going to build the application. We need to follow the steps to complete this application.
  • Create an EAI_Librry.
  • Create and Implement EAI_OrderApproval Module.
  • Create and Implement EAI_OrderRequest Module.
  • Test the Application.
Create an EAI_OrderLibrry:
       Select File àNew àLibrary, give name as EAI_Library then click on finish.
Create a business Object called OrderRequest.
Right click on EAI_Library, New àBusiness Object, give the name as ‘OrderRequest’ then click on finish. Add the following fields to business Objects as shown below.
Create a business Object called OrderRespons as shown below.
Create a business Object called OrderApproveRequest as shown below.
Create a business Object called OrderApproveResponse as shown below.
Create an Interface called OrderRequestInterface.
Right click on EAI_Library, New àInterface, give the name as ‘OrderRequestInterface’ then click on finish. Add the operation to Interface as shown below.
Create an Interface called OrderApproveInterface as shown below.
Create and Implement EAI_OrderApproval Module:
          Right click on Business Integration view, select new àModule.
        Give the name as ‘EAI_OrderApprove’, click on next then select EAI_Library as required libraries, then click on finish.
Drag and drop a Java component into EAI_OrderApprove - Assembly diagram and rename as ‘OrderApprove’.
Add OrderApproveInterface to OrderApprove java component as an Interface.
Right click on OrderApprove select Add à Interface, select OrderApproveInterface and click on ok.
Generate an export for access other SCA services. Right click on OrderApprove java component, select Generate Export à SCA Binding. This will available for access SCA applications.
Now we need to implement the OrderApprove Java component. Double click on OrderApprove and use the following code into approveOrder (DataObject request).
System.out.println("***** Entering into OrderApprove () *****");
// create approveOrder return data object using the BO factory
BOFactory bof =      (BOFactory)ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOFactory");
DataObject Response = bof.create("http://EAI_Library","OrderApproveResponse “);
String Status =null;
      String Remarks = null;
      if(request.getString("ItemID").contains("ITM")){
            Status = "APPROVED";
            Remarks = "Successfully order approved";
      }else{
            Status = "REJECTED";
            Remarks = "rejected the order";
      }
      Response.setString("OrderID", request.getString("OrderID"));
      Response.setString("Status",Status);
      Response.setString("Remarks",Remarks);
      System.out.println("***** Exit from OrderApprove () *****");
      return Response;
Create and Implement EAI_OrderRequest Module
Right click on Business Integration view, select new àModule.
Give the name as ‘EAI_OrderRequest’, click on next then select EAI_Library as required libraries, then click on finish.
Drag and drop a Process component into EAI_OrderRequest - Assembly diagram and rename as ‘BP_OrderRequest’.
Add OrderRequestInterface to BP_OrderRequest as an Interface. Right click on BP_OrderRequest select Add àInterface.
Select OrderRequestInterface then click on Ok.
Add OrderApproveInterface to BP_OrderRequest as a Reference. Right click on BP_OrderRequest select Add àReference.
Select OrderApproveInterface, give name as OrderApproveInterfacePartner click on Ok.
Drag and drop an Import component into EAI_OrderRequest - Assembly diagram and rename as ‘OrderApprove’.
Add OrderApproveInterface to OrderApprove’ as an Interface. Drag a wire from BP_OrderRequest to OrderApprove. The EAI_OrderRequest - Assembly diagram is shown below now.
Right click on OrderApprove import and select Generate Binding à SCA binding. It will be used for invoke external services using SCA binding
Select OrderApprove import component, select Properties àBinding, click on browse, select OrderApprovalExport then click on Ok.
OrderApprovalExport is which we have exported as export in EAI_OrderApproval assembly diagram. So we are going to invoke OrderApprove java component from BP_OrderRequest using SCA binding.
Now the properties are look like below.
Now double click on ‘BP_OrderRequest’ Process for implement. The implementation is look like below. I will explain here each and every activity functionality and implementation.
Log Entry (Snippet): It is used for customize our messages, we can write java code and made business logic here.
Here we are going to print the log into console. Click on LogEntry activity go to properties à Details, select Java button. Write the following code as shown below.
Generate OrderID:
Here we are writing java code for generate orderID for each order.
Click on Generate OrderID activity go to properties àDetails, select Java button. Write the following code as shown below.
Set Request for Order Approve (Assign): It is used for assign values to variables.
Here we are setting input for Order Approve service. Click on Set Request for Order Approve activity goes to properties àDetails. Select the x path as shown below.
Invoke Order Approve Service (Invoke): It is use for call external services.
Here we are using for call Order Approve Service. Click on Invoke Order Approve Service activity go to properties àDetails. Select the partner, operation and input, output parameters as shown below.
Set Response (Assign): It is used for assign values to variables.
Here we are setting response from Order approve service to OrderRespons. Click on Set Response activity go to properties àDetails. Select the x path as shown below.
Log Exit (Snippet): It is used for customize our messages, we can write java code and made business logic here.
Here we are going to print the log exit into console. Click on LogExit activity go to properties à Details, select Java button. Write the following code as shown below.
Test the Application:
Start the WebSphere process Server. Select Servers view à WebSphere Process Server v7.0 click on start the server.
Add the EAI_OrderRequest and EAI_OrderApprove modules to WebSphere process Server. Right click on WebSphere process Server v7.0 àAdd and remove projects, select EAI_OrderRequest and EAI_OrderApprove click on Add then click on Finish.
Double click on EAI_OrderRequest assembly diagram, Right click on BP_OrderRequest and select Test Component.
Enter the request parameters as shown below and click on continue.
The final output will be look like below. Here EAI_OrderRequest module will be invoked EAI_OrderApproval module using SCA binding. Find the Integrated test client flow for each activity it performed.
Find the console log for log statements which we have implemented in both the modules.
Conclusion:   
         Imports and exports enable us to expose out solutions in service-oriented fashion. In this article, you learned how to integrate SCA solutions using SCA import and exports. In future articles, we will examine integrating with other solutions using some of the other bindings such as Web services and JMS.
Downloads:  
File Name
Description
      Size
Download
SCA Binding.zip
SCA Binding Sample
25 KB
SCA Binding in WPS.pdf
SCA binding implementation in WPS
790 KB

continue reading

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

continue reading

Designed By AMEER BASHA G