Sunday, April 5, 2015

eXtensible Stylesheet Language Transformation (XSLT) is used to map source XML to target XML. XSLT files are used in Oracle SOA Suite to transform the message from one format to another format. In Oracle Service Bus to achieve same (transformation from one format to another format) we have two choices , either we can use Xquery transformation or we can use XSLT files.

In this post, we will see how to use XSLT files in Oracle Service Bus. we have developed a use case to show how to use XSLT file in Oracle service Bus. In this use case source will send request message (XML) to Oracle Service Bus proxy service, in OSB proxy service message flow we use XSLT file and transform that request message (XML) to target message (XML) format and invoke business service which further call target. We have built one XSLT file that transform data from request message XML format to target message XML format.

Use XSLT in OSB


Below is the source XML, target XML structure and XSLT file screen shot.

Source XML Structure

XSLT in OSB Source Structure


Target XML Structure

XSLT in OSB target Structure


XSLT File

XSLT in OSB


Now create a new project in Oracle Service Bus, to create new project first of all create a session and click on Projects links. Add a new project with the name "UseXSLTSample". Create three folders (proxy, business and resources) folders under this project. Click on resources folder and import source and target WSDL & schema files as these files are required to create proxy and business services.

Create OSB Project and Import Resources


Now import the XSLT file that we generated for this sample. To import XSLT file, click on resources folder, choose "XSLT" option from create resource drop down and browse the XSLT file.

Import XSLT File

 
Now create business service using target WSDL and Schema file, to create it click on business folder, choose "Business Service" from create resource drop down. Mention business service name and choose "WSDL Web Service" as service type, click on browse to browse the target WSDL and click on WSDL port and click on last and save the business service.

Same way create proxy service using source WSDL and Schema file, to create it click on proxy folder, choose "Proxy Service" from create resource drop down. Mention proxy service name and choose "WSDL Web Service" as service type, click on browse to browse the source WSDL and click on WSDL port and click on last and save the proxy service.

Create Proxy and Business Service


Now go to message flow of proxy service and after start node, add pipeline pair. In request pipeline, add stage node.

Add Pipeline pair in Message flow


Go Inside stage node and click on "Add an Action", choose Message Processing --> Assign action. Click on expression and in Xquery/XSLT expression editor, go to variables link which you can find at right bottom end of the screen. Choose body variable from drop down and select the request message. Assign request message to variable (inVar) in assign activity.

Add Assign Inside Pipleline pair


Now add one more assign activity, click on expression link of that activity. In Xquery/XSLT expression editor, click on "XSLT Resources" and click on browse to browse the XSLT file.

Add Assign for XSLT


In Bind Input, we need to map the request message variable as XSLT will transform that request message to target message format. So in Input document, mention variable name that we assigned in above assign action ($inVar).

Assign Request Message to XSLT


In second assign, assign the XSLT outcome to another variable (outVar). Now add replace action to assign outvar content to body variable. for that add replace action and replace body content with outVar content.

Assign outcome of XSLT to Body


Now after pipeline pair add route node to route the message to business service. Inside route node, add routing action and browse business service to route the message to it. Below is screen shot which shows how's your message flow look like.

Final Message Flow



Now test this sample and you see that XSLT file transform the source XML message to target XML message and route it to target.

1 comments :