...
Code Block | ||
---|---|---|
| ||
<definitions xmlns="http://ws.apache.org/ns/synapse"> <!-- 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:repositorysamples/samplesservice-bus/resources/</parameter> <!-- all resources loaded from the URL registry would be cached for this number of milli seconds --> <parameter name="cachableDuration">15000</parameter> </registry> <!-- define the request processing XSLT resource as a static URL source --> <localEntry key="xslt-key-req" src="file:repositorysamples/samplesservice-bus/resources/transform/transform.xslt"/> <sequence name="main"> <in> <!-- transform the custom quote request into a standard quote requst expected by the service --> <xslt key="xslt-key-req"/> <send/> </in> <out> <!-- 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"/> <send/> </out> </sequence> </definitions> |
This configuration file synapse_sample_8.xml
is available in the <ESB<EI_HOME>/repository/samples
directorysamples/service-bus
directory.
To build the sample
Start the ESB Profile with the sample 8 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.
Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.
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.
...
In this example you will notice the new registry definition.
The ESB comes with Profile contains 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 of the resource being looked up. The registry caches a resource once requested, and caches it internally for a specified duration. Once this period expires, if necessary, it will reload reloads the meta information about the resource and reload then reloads its cached copy , at the next time that the resource is requested.
...
Run the following command from the
<ESB<EI_HOME>/samples/axis2Client
directory.Code Block language bash ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote
- Run the client again immediately using the above command (within 15 seconds of the first request).
- Leave the system idle for more than 15 seconds and run the client again using the command specified in step 1.
- Now edit the
<ESB<EI_HOME>/repositorysamples/samplesservice-bus/resources/transform/transform_back.xslt
file and add a blank line at the end - Run the client again using the command specified in step 1.
...
When you analyze the debug log output on the ESB Profile console, you will see that the incoming message is 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.
...
Once the transform_back.xslt
file is edited and the client is run again, If the cache is expired, you will see the following debug log messages which shows that the resource is re-fetched from its URL by the registry.:
Code Block |
---|
[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 |
This shows that the resource is re-fetched from its URL by the registry.
The SimpleURLRegistry
allows the resource to be cached and detects updates so that the changes can be reloaded without restarting the ESB instance.
Excerpt | ||
---|---|---|
| ||
Example of message mediation in WSO2 ESB. |