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:
In a command window, navigate to the
<PRODUCT_HOME>/samples/axis2Server/src/SimpleStockQuoteService
directory, and then runant
to build and deploy this service to the sample Axis2 server.
For example:user@host:~/wso2esb/samples/axis2Server/src/SimpleStockQuoteService$ ant Buildfile: build.xml clean: init: [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 compile-all: [javac] Compiling 9 source files to /home/user/wso2esb/samples/axis2Server/src/SimpleStockQuoteService/temp/classes build-service: [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 BUILD SUCCESSFUL Total time: 1 second
Navigate to the
<PRODUCT_HOME>/samples/axis2Server
directory and start the server using one of the following commands:- Linux//Unix:
./axis2server.sh
- Windows:
axis2server.bat
The Axis2 server starts on port 9000 (HTTP), and the following messages appear on the console:
user@host:~/wso2esb/samples/axis2Server$ ./axis2server.sh 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
- Linux//Unix:
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 init: [mkdir] Created dir: /home/user/wso2esb/samples/axis2Client/target/classes compile: [javac] Compiling 10 source files to /home/user/wso2esb/samples/axis2Client/target/classes stockquote: [java] Standard :: Stock price = $82.19300717003419 BUILD SUCCESSFUL 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.
POST / HTTP/1.1 Content-Type: text/xml; charset=UTF-8 SOAPAction: "urn:getQuote" User-Agent: Axis2 Host: 127.0.0.1 Transfer-Encoding: chunked 218 <?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <wsa:To>http://localhost:9000/services/SimpleStockQuoteService</wsa:To> <wsa:MessageID>urn:uuid:D538B21E30B32BB8291177589283717</wsa:MessageID> <wsa:Action>urn:getQuote</wsa:Action> </soapenv:Header> <soapenv:Body> <m0:getQuote xmlns:m0="http://services.samples"> <m0:request> <m0:symbol>IBM</m0:symbol> </m0:request> </m0:getQuote> </soapenv:Body> </soapenv:Envelope>0
This lesson demonstrated how to configure and monitor the mediation of messages. The next lesson walks you through the mediation of services.