One of the interesting feature of Axis2 is its nature of extensibility, there are a number of way to extend Axis2 functionality. Here I am going to discuss how to extend its core functionality, that is invoking customer code when a message is received to the system. All the WS* features (Reliability, Security etc..), implemented in this way. Here I am going to discuss how to write a very simple Axis2 module to count the number of incoming messages and outgoing messages.
For this module we need three main components,
- Incoming message handler
- Outgoing message handler
- Module configuration
Incoming message counter has a global counter, which will be incremented for each request, and the same way outgoing message counter also has a global counter which also incremented for each outgoing messages. Then finally Module configuration which specify the ordering of handler in the execution chain [Axis2 execution chain].
you can find the source code of all those components as well as executable module.
How to use the module?
To use the module, first you need to download the "counter-module.mar" and need to drop into "modules" directory in Axis2 [Axis2 deployment]. Then you need to engage the module, for that you can either
- Do that using axis2.xml <module ref="counter-module"/>
- Or you can do that using Axis2 management console
(login to the admin console, then go to the engage module menu bar at the left hand side).
How to see that working?
To see that working you can do any of the Axis2 service invocation [Axis2 client API], the simplest way is to invoke the version service. For that type the following in the browser.
Then if you look at the server console (Tomcat console), you can see our module prints request and response count. If you invoke the service again you will see the number is getting incremented.
- Source code
- Binary file