...
The ESB Script mediator can be programmed using any BSF compatible programming language. This Sample demonstrates how to use Ruby Scripts for mediation using the Script mediator.
...
The script used in this sample stockquoteTransform.rb
is as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
<x><![CDATA[ require 'rexml/document' include REXML def transformRequest(mc) newRequest= Document.new '<m:getQuote xmlns:m="http://services.samples">'<< '<m:request><m:symbol></m:symbol></m:request></m:getQuote>' newRequest.root.elements[1].elements[1].text = mc.getPayloadXML().root.elements[1].get_text mc.setPayloadXML(newRequest) end def transformResponse(mc) newResponse = Document.new '<m:CheckPriceResponse xmlns:m="http://services.samples/xsd"><m:Code>' << '</m:Code><m:Price></m:Price></m:CheckPriceResponse>' lastPrice=mc.getPayloadXML().root.elements[1].get_elements('*:last') code=mc.getPayloadXML().root.elements[1].get_elements('*:symbol') newResponse.root.elements[1].text =code[0].get_text newResponse.root.elements[2].text =lastPrice[0].get_text mc.setPayloadXML(newResponse) end ]]></x> |
...
You will see that the ESB uses the Script mediator and the function specified function to in the configuration to convert the custom request to a standard quote request, and . You will also see that the response received is subsequently transformed and sent back to the client.
...