This section explains, through an example scenario, how the Content Filter EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Content Filter
The Content Filter EIP helps manage a large message when you are interested in a few data items only. It removes unimportant data items from a message and leaves only the important ones. In addition to removing data elements, Content Filter can be used to simplify a message structure. For more information, refer to http://www.eaipatterns.com/ContentFilter.html.
Figure 1: Content Filter EIP
This example scenario explains how a message's content can be optimized to gain a more productive response. A client sends a stock quote request containing additional data that is not necessary for message processing. WSO2 ESB uses an XSLT mediator to restructure the request message and optimize it with only the required data before sending it to the Stock Quote service. This approach improves performance, as removing unnecessary bits of data makes the message more lightweight.
The diagram below depicts how to simulate the example scenario in WSO2 ESB.
Figure 2: Example Scenario of the Content Filter EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Content Filter EIP by comparing their core components.
|Content Filter EIP (Figure 1)||Content Filter Example Scenario (Figure 2)|
|Original Message||Simple Stock Quote Request from Client|
|Content Filter||XSLT Mediator|
|Filtered Message||Simple Stock Quote Request from WSO2 ESB|
- Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Installation Guide in the WSO2 ESB documentation.
- Start the sample Axis2 server. For instructions, refer to the section Setting Up the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.
Save the following XSLT document as
Start the ESB server and log into its management console UI (
//). In the management console, navigate to the Main menu and click Source View in the Service Bus section. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.
Simulating the sample scenario
Send the following request to the ESB using a SOAP client like SoapUI.
When a request arrives to the ESB, it is first simplified to the following structure using the XSLT mediator. You can use TCPMon to observe this behavior.
How the implementation works
Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration shown above.
- localEntry [line 8 in ESB config] - Entry from the local registry.
- xslt [line 12 in ESB config] - The XSLT mediator applies an XSLT transformation to the selected element in the message specified using the
sourceattribute. In this case, no source attribute is given, so the transformation will be applied to the first child element of the message.