Wednesday, 9 November 2011

Lesson04-Routing and Transformation

This tutorial explains how ’s dynamic routing and transformation features can be used to invoke two different public calculator web services.
At the end of this tutorial, you should understand
  1. Canonical schema in Proxy Services
  2. Dynamic Routing to Business Services
  3. XML content transformation from canonical to native format
  4. XML content transformation to canonical from native format
  5. Routing Actions
We are going to invoke two public calculator webservices from Parasoft and ASPAlliance using following WSDLs:
Each of these native webservices is invoked using a corresponding business service. Finally, we shall create a proxy service using canonical schema to invoke either of the business services based on specific routing conditions.
Login to OSB Console using url http://localhost:7001/sbconsole
Click “Create” in Change Center to create a new session.
Create a new project named “calculator” using Project Explorer.
Create “proxyservice”, “businessservice”, “extservice” folders in calculator project to hold proxy services, business services, external services respectively.
Import Native Webservices
Click on “extservice” folder link and import Parasoft and ASPAlliance WSDLs using Create Resource –> Interface WSDL option.
We have completed importing native webservices into extservice folder. Let us create business services to invoke these native services now.
Create Business Services
Click on “businessservice” folder. Using Create Resource –> Service –> Business Service command, create Business Service to invoke Parasoft Native Webservice. Select Parasoft WSDL we created in previous step for “WSDL Web Service” as shown below.
Similarly, create ASPAlliance Business Service using ASPAlliance Native Webservice we created earlier.
Create Proxy Service
Import XML artifacts necessary to create proxy service using details given below:
Name Type Description Command
ParasoftXSL XSLT file Convert canonical request to native parasoft webservice request Create Resource –> Transformation –> XSLT
ASPAllianceXSL XSLT file Convert canonical request to native ASP Alliance webservice request Create Resource –> Transformation –> XSLT
ParsoftResponseXSL XSLT file Convert native parasoft webservice response to canonical format Create Resource –> Transformation –> XSLT
ASPAllianceResponseXSL XSLT file Convert native ASP Alliance webservice reseponse to canonical format Create Resource –> Transformation –> XSLT
Calculator.xsd XSD file Calculator canonical schema definiton Create Resource -> Interface ->XML Schema
CalculatorCanonicalWSDL WSDL file Abstract WSDL definition for proxy service Create Resource -> Interface ->WSDL
After importing CalculatorCanonicalWSDL, we need to explicitly set the reference to Calculator.xsd file. Click on CalculatorCanonicalWSDL link from Resource section. From “View a WSDL (calculator/proxyservice/CalculatorCanonicalWSDL)” page, click on “Edit References”.
Specify calculator/proxyservice/calculator.xsd for XML Schema Name.
Create CalculatorProxyService based on “CalculatorCanonicalWSDL“ using Create Resource –> Service –> Proxy Service command. Here is the summary of resource we created so far:
We have successfully imported native webservices, created business and proxy services to interface them. Now, we need to create routing between proxy services, business services and native webservices. We also need to transform data appropriately.
Create Routing & Transformation
We are going to perform following tasks in routing and transformation.
  1. Route the request to Parasoft Business Service in case input value X is more than 1000. Create a default case to route request to ASPAlliance Business Service.
  2. Transform request from Proxy Service’s canonical format to appropriate Business Service format.
  3. Transform response from Business Service back to Proxy Service’s canonical format.
Navigate to proxyservice folder under calculator project. Click on Edit Message Flow icon.
From Edit Message Flow screen, click on CalculatorProxyService and then “Add Route”. Click on “Route Node1” and select “Edit Route”. From Edit Stage Configuration screen, click on Add Action –> Communication –> Routing Table.
image image image
Route Node screen appears as below. Click on “Expression” link next to “Routing Table”. From next screen, click on Variable Structure link at the bottom left corner of the screen.
image image
From Structure drop down at the top left corner of the screen, navigate to $body –> calculatorRequest –> inputX. Corresponding XQuery expression will be displayed in the “Property Inspector” section. Copy this expression to the text area above “Property Inspector” section.
Click on Save to return to Stage Configuration screen. Select operator “>” and provide value “1000” under Routing Table.
Click on <Service> link and select “ParasoftBS” from list of values. Select operation “multiply”.
Lets transform XML data from canonical to native format now. Click on “Add an Action” link under “Request Actions” and select “Message Processing –> Replace” option.
Enter “body” in variable field. Click on “XPath” link. Enter “./*” in XPath Expression.
Click on Save to return to main screen. Click on “Expression” link. Navigate to “XLST Resources” tab. Click on Browse and select ParasoftXSL component.
Click “Submit” to return to XQuery/XSLT Expression Editor. In “Input Document” field enter “$body/*”. This makes sure Canonical request payload ($body) is transformed using ParasoftXSL.
Click on Save to return to Stage Configuration screen. Follow the same steps for Response Actions. Select ParasoftResponseXSL for XSLT file.
Click on case icon and insert a “Default Case”.
Follow above steps to
  1. Route service to ASPAllianceBS,
  2. Add Request Action to transform input XML using ASPAllianceXSL.
  3. Add Response Action to transform output XML using ASPAllianceResponseXSL.
Routing table now looks as below:
Click on Save to return to Message Flow screen. Click Save again to save proxy service and return to project dashboard.
From Change Center, click on “Activate” and “Submit” to save changes made so far.
Test Proxy Service
Launch Test Console using the icon next to CalculatorProxyService entry.
Enter a value greater than 1000 for inputX field and hit “Execute”.
We can see the multiplication value of 1001 x 11 = 11011.0 in the response XML. From “Invocation Trace” section, we can see that the request is sent to ParasoftBS.
If we run the proxy service with inputX=11, inputY=11, we can see the request routed to “ASPAllianceBS”.

No comments:

Post a Comment