This sample demonstrates the functionality ofIt sends a message from a sample client to a back-end service through the ESB and uses the XSLT Mediator to perform transformations. The XSLT transformations are specified as registry resources.
For a list of prerequisites, see the Prerequisites section in ESB Samples Setup.
Building the Sample
1. Start the ESB with sample 8 configuration using the instructions given in Starting Sample ESB Configurations.
2. A message should appear in the command or text Linux console stating the server started successfully.
3. The synapse configuration in the ESB used for message mediation in this sample is provided in
synapse_sample_8.xml as shown below:
4. Deploy the back-end service 'SimpleStockQuoteService' and start the Axis2 server using the instructions given in section Starting Sample Back-End Services.
5. Now you have a running ESB instance and a back-end service deployed. In the next section, we will send a message to the back-end service through the ESB using a sample client.
Executing the Sample
synapse_sample_8.xml the first resource "xslt-key-req" is specified as a local registry entry. Local entries do not place the resource on the registry, but simply make it available to the local configuration. If a local entry is defined with a key that already exists in the remote registry, the local entry will get higher preference and override the remote resource.
In this example you will notice the new "registry" definition. ESB comes with a simple URL-based registry implementation
SimpleURLRegistry. During initialization of the registry, the
SimpleURLRegistry expects to find a property named "root," which specifies a prefix for the registry keys used later. When the
SimpleURLRegistry is used, this root is prefixed to the entry keys to form the complete URL for the resource being looked up. The registry caches a resource once requested, and caches it internally for a specified duration. Once this period expires, it will reload the meta information about the resource and reload its cached copy, if necessary, the next time the resource is requested.
Therefore, the second XSLT resource key
transform/transform_back.xslt concatenated with the "root" of the
SimpleURLRegistry file:repository/samples/resources/ forms the complete URL of the resource as file:repository/samples/resources/transform/transform_back.xslt and caches its value for a period of 15000 ms.
1. The sample client used here is 'Stock Quote Client' which can operate in several modes. For instructions on this sample client and its operation modes, refer to Stock Quote Client. Run the following ant command from
<ESB_HOME>/samples/axis2Client directory and analyze the the ESB debug log output on the ESB console.
2. The incoming message is now transformed into a standard stock quote request as expected by the
SimpleStockQuoteService deployed on the local Axis2 instance by the XSLT Mediator. The XSLT Mediator uses Xalan-J to perform the transformations. It is possible to configure the underlying transformation engine using properties where necessary. The response from the
SimpleStockQuoteService is converted back into the custom format as expected by the client during the out message processing.
During the response processing, the
SimpleURLRegistry fetches the resource.
3. Run the client again immediately (within 15 seconds of the first request). You will not see the resource being reloaded by the registry as the cached value would be still valid.
4. Leave the system idle for more than 15 seconds and retry the same request. The registry detects that the cached resource has expired and checks the meta information about the resource to determine if the resource itself has changed and requires a fresh fetch from the source URL. If the meta data / version number indicates that a reload of the cached resource is not necessary (unless the resource itself actually changed), the updated meta information is used and the cache lease extended as appropriate.
5. Now edit the
<ESB_HOME>/repository/samples/resources/transform/transform_back.xslt file and add a blank line at the end and run the client again using ant.
6. If the cache is expired, the resource would be re-fetched from its URL by the registry. This can be seen by the following debug log messages.
SimpleURLRegistry allows resource to be cached and updates detected so that the changes can be reloaded without restarting the ESB instance.