How Can I Get Notified When There are Changes to Contexts?

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Eran Chinthaka
  • 30 Nov, 2008

Configuration Context, the parent of all the contexts within Axis2, acts as the central point for the operation of the Axis2 engine. Whenever there is a creation or deletion of a message context, service context or service group context, the configuration context will be notified about this creation or deletion. We can register a listener with the configuration context, so that we can also be notified about these changes within Axis2. This is very handy if you are implementing a monitoring service or a management functionality on top of Axis2.

Let's see how we can do this.

Step 1 : Implement org.apache.axis2.context.ContextListener interface

public interface ContextListener {

     * A context has been added
     * @param context
    void contextCreated(AbstractContext context);

     * A context has been removed
     * @param context
    void contextRemoved(AbstractContext context);

First implement the org.apache.axis2.context.ContextListener interface. This interface contains two methods to be notified during a context creation and context deletion. You will get the created or removed context as an input to this method, so that you can extract the relevant information or perform some operation on top of them.

Step 2 : Register the implementation of ContextListener

Then you need to register your implementation of ContextListener interface with the configuration context, using the provided

public void addContextListener(ContextListener contextListener)



ContextListener listener = new MyContextListener();

// get access to the configuration context. 
ConfigurationContext configContext = MessageContext.getCurrentMessageContext().getConfigurationContext();


Now whenever there is a creation or deletion of a context, the configuration context will notify your context listener.


Applies To

1. Apache Axis2


More Information


  • More information about various contexts can be found here.