Event Listener module
Job module
Language module
Macro Module
Servlet Filter module
Servlet module
Theme module
Web UI modules
Workflow module

Descriptor based Event Listener

Available:

Confluence 1.4 and later

Legacy:

In Confluence 3.3 and later, the preferred approach is to use annotation-based events with Atlassian Spring Scanner. More information and examples are on Event Listener module page.

The Listener Plugin XML

Each listener is a plugin module of type 'listener'. It is packaged with whatever Java classes and other resources the listener requires to run. Here is an example of atlassian-plugin.xml file containing a single listener:

1
2
<atlassian-plugin name='Optional Listeners' key='confluence.extra.auditor'>
    <plugin-info>
        <description>Audit Logging</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
        <version>1.0</version>
    </plugin-info>

    <listener name='Audit Log Listener' class='com.example.listener.AuditListener' key='auditListener'>
        <description>Provides an audit log for each event within Confluence.</description>
    </listener>
</atlassian-plugin>

The listener module definition has no configuration requirements beyond any other module. You just need to give it a name, a key, and provide the name of the class that implements the listener.

Example class

Below is an example of an EventListener that listens for the LoginEvent and LogoutEvent.

1
2
package com.atlassian.confluence.extra.userlister;

import com.atlassian.confluence.event.events.security.LoginEvent;
import com.atlassian.confluence.event.events.security.LogoutEvent;
import com.atlassian.event.Event;
import com.atlassian.event.EventListener;
import org.apache.log4j.Logger;

public class UserListener implements EventListener {
    private static final Logger log = Logger.getLogger(UserListener.class);

    private Class[] handledClasses = new Class[]{ LoginEvent.class, LogoutEvent.class};


    public void handleEvent(Event event) {
        if (event instanceof LoginEvent) {
            LoginEvent loginEvent = (LoginEvent) event;
            log.info(loginEvent.getUsername() + " logged in (" +  loginEvent.getSessionId() + ")");
        } else if (event instanceof LogoutEvent) {
            LogoutEvent logoutEvent = (LogoutEvent) event;
            log.info(logoutEvent.getUsername() + " logged out (" +  logoutEvent.getSessionId() + ")");
        }
}

    public Class[] getHandledEventClasses() {
        return handledClasses;
    }

}

You can find a more detailed example with sample code in Writing an Event Listener Plugin Module.

Rate this page: