Friday, October 10, 2008

How to write an Axis2 Observer


As an Axis2 user you might required to execute your own process when a state change happens to a service. You can implement a Axis2 Observer and link it at the runtime using the axis2 configuration without making changes to the Axis2 code base. Steps to write and configure a Observer as follows.
Implement the Observer:
Implement the 'org.apache.axis2.engine.AxisObserver' interface.
package org.apache.axis2.engine;
public interface AxisObserver extends org.apache.axis2.description.ParameterInclude {
void init(org.apache.axis2.engine.AxisConfiguration axisConfiguration);
void serviceUpdate(org.apache.axis2.engine.AxisEvent event, org.apache.axis2.description.AxisService axisService);
void serviceGroupUpdate(org.apache.axis2.engine.AxisEvent event, org.apache.axis2.description.AxisServiceGroup axisServiceGroup);
void moduleUpdate(org.apache.axis2.engine.AxisEvent event, org.apache.axis2.description.AxisModule axisModule);
}
Implement the abstract methods :
Pick the relevant callback and add your code, as an example I'm implementing the 'serviceUpdate' method.
 public void serviceUpdate(AxisEvent axisEvent, AxisService axisService) {
int eventType = axisEvent.getEventType();
if (eventType == AxisEvent.SERVICE_DEPLOY) {
log.debug("Service deployed");
//TODO: some code here
}
}
Using the axis event can identify the exact state change of the service.
Add the Observer to the axis2.xml :
<listener class="your axis-observer impl class">
<parameter name="param">value</parameter>
</listener>
You can pass parameters to the Observer using parameter tag.

1 comments:

Loïc said...

Do you have plan to support "listener" configuration in the WSF Spring module?