This documentation is for WSO2 Enterprise Service Bus version 4.7.0 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »


This sample demonstrates the functionality of static and dynamic registry resources and the XSLT Mediator. It 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 <ESB_HOME>/repository/samples/synapse_sample_8.xml as shown below:

<definitions xmlns="">
    <!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) -->
    <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry">
        <!-- the root property of the simple URL registry helps resolve a resource URL as root + key -->
        <parameter name="root">file:./repository/samples/resources/</parameter>
        <!-- all resources loaded from the URL registry would be cached for this number of milli seconds -->
        <parameter name="cachableDuration">15000</parameter>
    <!-- define the request processing XSLT resource as a static URL source -->
    <localEntry key="xslt-key-req" src="file:repository/samples/resources/transform/transform.xslt"/>
        <!-- transform the custom quote request into a standard quote requst expected by the service -->
        <xslt key="xslt-key-req"/>
        <!-- transform the standard response back into the custom format the client expects -->
        <!-- the key is looked up in the remote registry and loaded as a 'dynamic' registry resource -->
        <xslt key="transform/transform_back.xslt"/>

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

According to 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.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote

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.

[HttpClientWorker-1] DEBUG AbstractRegistry - Cached object has expired for key : transform/transform_back.xslt
[HttpClientWorker-1] DEBUG SimpleURLRegistry - Perform RegistryEntry lookup for key : transform/transform_back.xslt
[HttpClientWorker-1] DEBUG AbstractRegistry - Expired version number is same as current version in registry
[HttpClientWorker-1] DEBUG AbstractRegistry - Renew cache lease for another 15s

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.

[HttpClientWorker-1] DEBUG AbstractRegistry - Cached object has expired for key : transform/transform_back.xslt
[HttpClientWorker-1] DEBUG SimpleURLRegistry - Perform RegistryEntry lookup for key : transform/transform_back.xslt

The SimpleURLRegistry allows resource to be cached and updates detected so that the changes can be reloaded without restarting the ESB instance.

  • No labels