This documentation is for WSO2 Enterprise Service Bus version 4.8.0 . View documentation for the latest release.

All docs This doc
Skip to end of metadata
Go to start of metadata

A message mediator performs a specific action on a message. This lesson demonstrates the basics of message mediation by using mediators to filter and log the messages passing through the ESB. You can replace this simple functionality with any combination of advanced mediations, such as transformation and content-based routing, as well as bridging different communication protocols, such as transforming an HTTP request to a JMS topic.

For the ESB samples, we use a standalone Apache Axis2 Web services engine as the back-end server, which is bundled with the WSO2 ESB distribution by default. This lesson involves building and deploying a simple stock quote service to the back-end server, starting the server, and then executing the request from the client.

To run the sample:

  1. In a command window, navigate to the <PRODUCT_HOME>/samples/axis2Server/src/SimpleStockQuoteService directory, and then run ant to build and deploy this service to the sample Axis2 server.
    For example:

    user@host:~/wso2esb/samples/axis2Server/src/SimpleStockQuoteService$ ant
    Buildfile: build.xml
        [mkdir] Created dir: /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp
        [mkdir] Created dir: /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/classes
        [mkdir] Created dir: /home/user/wso2esb/samples/axis2Server/repository/services
        [javac] Compiling 9 source files to /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/classes
        [mkdir] Created dir: /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/SimpleStockQuote
        [mkdir] Created dir: /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/SimpleStockQuote/META-INF
         [copy] Copying 1 file to /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/SimpleStockQuote/META-INF
         [copy] Copying 1 file to /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/SimpleStockQuote/META-INF
         [copy] Copying 9 files to /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/SimpleStockQuote
          [jar] Building jar: /home/user/wso2esb/samples/axis2Server/repository/services/SimpleStockQuoteService.aar
    Total time: 1 second
  2. Navigate to the <PRODUCT_HOME>/samples/axis2Server directory and start the server using one of the following commands:

    • Linux//Unix: ./
    • Windows: axis2server.bat

    The Axis2 server starts on port 9000 (HTTP), and the following messages appear on the console:

    user@host:~/wso2esb/samples/axis2Server$ ./
     Using JAVA_HOME:   /usr/java
     Using AXIS2 Repository :   /home/user/wso2esb/samples/axis2Server/repository
     Using AXIS2 Configuration :   /home/user/wso2esb/samples/axis2Server/repository/conf/axis2.xml
    2007-11-08 18:00:54,283 [-] [main]  INFO SimpleHTTPServer [SimpleAxisServer] Starting
    [SimpleAxisServer] Using the Axis2 Repository : /home/user/wso2esb/samples/axis2Server/repository
    [SimpleAxisServer] Using the Axis2 Configuration File : /home/user/wso2esb/samples/axis2Server/repository/conf/axis2.xml
    2007-11-08 18:00:55,494 [-] [main]  INFO HttpCoreNIOSender HTTPS Sender starting
    2007-11-08 18:00:55,495 [-] [main]  INFO HttpCoreNIOSender HTTP Sender starting
    2007-11-08 18:00:55,798 [-] [main]  INFO HttpCoreNIOListener HTTPS Listener starting on port : 9002
    2007-11-08 18:00:55,804 [-] [main]  INFO HttpCoreNIOListener HTTP Listener starting on port : 9000
    2007-11-08 18:00:55,805 [-] [main]  INFO SimpleHTTPServer [SimpleAxisServer] Started
  3. To run the sample from the client, navigate to the <PRODUCT_HOME>/samples/axis2Client directory and type the following command:
    ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280 -Dsymbol=IBM -Dmode=quote

You can see the following output with the quote price sent by the server.

user@host:~/wso2esb/samples/axis2Client$ ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280 -Dsymbol=IBM -Dmode=quote
Buildfile: build.xml

    [mkdir] Created dir: /home/user/wso2esb/samples/axis2Client/target/classes

    [javac] Compiling 10 source files to /home/user/wso2esb/samples/axis2Client/target/classes

     [java] Standard :: Stock price = $82.19300717003419

Total time: 4 seconds

This command sent a request for a stock quote for the symbol 'IBM', set the transport URL to the ESB (http://localhost:8280), and the WS-Addressing EPR to the actual server (http://localhost:9000/services/SimpleStockQuoteService). The actual wire-level HTTP message sent by the client is as follows and is sent over port 8280 to the ESB instance on localhost.

Content-Type: text/xml; charset=UTF-8
SOAPAction: "urn:getQuote"
User-Agent: Axis2
Transfer-Encoding: chunked

<?xml version='1.0' encoding='UTF-8'?>
   <soapenv:Envelope xmlns:wsa="" xmlns:soapenv="">
         <m0:getQuote xmlns:m0="http://services.samples">

This lesson demonstrated how to configure and monitor the mediation of messages. The next lesson walks you through the mediation of services.

  • No labels