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

Wednesday, April 23, 2014

Using XSLT primitives for Data Transformation in ESB

Introduction:

Within a mediation module, the message is received from a service requester before it is sent to a service provider. The structure of the message from a service requester is not always the same as that of a service provider. One of the common uses of mediation is to transform data from one format to another. We have several data transformation primitives in WebSphere ESB. Here we are going to learn about XSLT Primitive. We will see different functionalities which we have in XSLT.
Overview:
In IBM® WebSphere® ESB, XSLT mediation primitives are the usual component for data transformation and mapping. The XSLT module offers basic built-in functions such as string, substring, floor, and ceiling for simple data transformation. But for complex mapping requirements such as Date/time format conversion, or for working with Java objects that XSLT does not support such as java.math.BigDecimal, we can use the custom Java bean functionality and custom Java functions for data transformation. This article will describe the custom Java bean functionality, explore the conditional data mapping techniques using xsl:choose, and conclude with a discussion of error handling.
XSL generation
An XSLT primitive offers two choices for data mapping: generating XSL through mapping created with the Mapping Editor interface, or else using your own XSL, though this second option is discouraged because any changes you make when using the Mapping Editor and rebuilding the project will overwrite the XSLT.
Implementation:
We will complete the following steps to implement application using XSLT primitive.
  1. Create BO, Interface and Mediation.
  2. Implement XSLT Primitive.
  3. Test XSL Transformation.
  4. Test the Application.
Create BO, Interface and Mediation:
Create a mediation Module called as ‘EAI_FlightBookingMediation’ under Data Types create the Business Objects for our application to store the date. The following Business Objects create before creating Interface.
Create two interfaces called ‘FlightBookingInterface’ and ‘FlightBookingService’ as shown below.
Open Assembly diagram and add ‘FlightBookingInterface’ as an interface to FlightBookingMediation component and add ‘FlightBookingService’ as a reference.
Dar and drop a Java component in Assembly diagram and rename as ‘FlightBookingService’. Wire from FlightBookingMediation to ‘FlightBookingService’ java component.
Implement the Java component and add the following code to flightBooking (DataObject request) method.
System.out.println("Flight Booking Request Received :: "+request);
String Response = null;
Response = "Request received successfully";
return Response;
Implement the FlightBookingMediation component as a blank mediation flow and add the following primitives as shown below.
Implement XSLT Primitive:
Now we will learn how to create a XSL transformation and implantation here. Drag and drop a XSL transformation from Transformation Pallet rename as ‘XSLT_Request’ drag a wire from MessageLogger_Entry to XSLT_Request and from XSLT_Request to SI_FlightBookingService.
Similarly add one more XSL transformation for response mapping. The flow should be look like below.
Now we will implement the transformation mapping for XSLT_Request and XSLT_Response.
Double click on XSLT_Request and Give the name as ‘XSLT_Request’ then click on next.
Select the Message Root as / and make sure the Input Message body and Output Message Body selected correctly then click on finish.
Now the XSLT_Request mapping will open in new window. It will be look like below.
Expand the source and destination smo body parts and wire as shown below, to Move the source values to destination.
Here the move work like copy the source values to the destination values.
Drag a wire from DepartDate to Depart in destination, from the move drop down select FormateDate under Date and Time Functions.
Select the Formate Date à Properties à General and select the Pattern from drop down as shown below.
Drag a wire from DepartDate to JournyDate and double click on Local map to implement local mapping transformation.
Drag a wire from DepartDate to Day, Date, Month, Year field and select the date functions as shown below.
This will give the Day name, Date, Month name and Year will be sent to service.
Rright click on FlightClass and select Create Assign to set static value to specified field.
Select the assign transformation à Properties à General à Give the value as ‘Business Class’
Drag a wire from ReturnDate, IsRoundTrip to return and select If.
Select the If à Properties à Condition and give the condition as $IsRoundTrip == true.
Double click on If and drag a wire from RetrunDate to Return as shown below.
Import the attached EAI_CommonUtility project which hold the utility java classes and add as a Dependency in ‘EAI_FlightBookingMediation’.
Drag a wire from Destination to CountryOfDeparture and select Custom Java Transfrmation.
Select the Custom Java Transformation à Properties à general, select the class name ,method name and parametes as shown below.
The above java class is available in EAI_CommonUtility. It has java code logic to select the country for destination value.
We have lot of functions to perform in XSL transformation. We can perform different string functions, Date functions, Maths functions similarly.
Similarly implement the XSLT_Response XSL transformation. It should be look like below.
 Test XSL Transformation:
WID has built in function to perform the XSL transformation test. We can directly test the XSLT after implementation.
Open the XSLT_Response XSL transformation and click on Test Map.
It will open a view call Test Map view and select ‘Use the Associated XML files’ button to add a sample input file.
Click on Generate Input, give the XML File name and click on Finish then click on Ok.
Now it will generate Input Sample XML file to test XSL Transformation. Now click on Run Transformations.
Now it will generate the response XML file based on the implementation we have in XSLT_Response transformation. We have passed the input as ‘SUCCESS’ and the implementation have Move, so the final response in Output is ‘SUCCESS’.
This input and output XML files we can save for future reference or for future testing purpose.
Test the Application:
Now save the all files, start the WESB server and deploy the EAI_FlightBookingMediation in server.
Open the Assembly diagram and Right click on FlightBookingMediation select test Component.
Give the values as shown below and click on continue.
The output will be look like below.
Select the Request activity in Test client and see the request message which sent to Service. It will be look like below.

Conclusion:

This article showed how to use XSLT functionality for common data type and date conversions. Although the XSLT module is not as feature-rich as the Business Object Mapping Editor provided for SCA components, it is the only option for data mapping in a mediation module apart from using a full-blown Java custom mediation component.
Downloads
File Name
Description
SIZE
Download
XSL Transformation.pdf
XSL Transformation Document
988 KB
XSL Transformation.zip
XSL Sample
32 KB
EAI_CommonUtility.zip
Common Utility
8 KB

0 comments :

Post a Comment

Designed By AMEER BASHA G