About Jira modules
Customer portal
Project settings UI locations

Servlet context listener

Available:

Servlet Context Listener plugin modules are available in JIRA 4.0 and later.

Purpose of this Module Type

Servlet Context Listener plugin modules allow you to deploy Java Servlet context listeners as a part of your plugin. This helps you to integrate easily with frameworks that use context listeners for initialisation.

Configuration

The root element for the Servlet Context Listener plugin module is servlet-context-listener. It allows the following attributes and child elements for configuration:

Attributes

Name*

Description

class

The class which implements this plugin module. The class you need to provide depends on the module type. For example, Confluence theme, layout and colour-scheme modules can use classes already provided in Confluence. So you can write a theme-plugin without any Java code. But for macro and listener modules you need to write your own implementing class and include it in your plugin. See the plugin framework guide to creating plugin module instances

The servlet context listener Java class. Must implement javax.servlet.ServletContextListener.

state

 

Indicate whether the plugin module should be disabled by default (value='disabled') or enabled by default (value='enabled').

Default: enabled.

i18n-name-key

The localisation key for the human-readable name of the plugin module.

key

The unique identifier of the plugin module. You refer to this key to use the resource from other contexts in your plugin, such as from the plugin Java code or JavaScript resources.

 

1
2
<component-import key="appProps" interface="com.atlassian.sal.api.ApplicationProperties"/>

 

In the example, appProps is the key for this particular module declaration, for component-import, in this case.

I.e. the identifier of the context listener.

name

The human-readable name of the plugin module. 

I.e. the human-readable name of the listener.

Default: the plugin key.

system

Indicates whether this plugin module is a system plugin module (value='true') or not (value='false'). Only available for non-OSGi plugins.

Default: false.

*key attribute is required.

Elements

  • description - The description of the plugin module. The 'key' attribute can be specified to declare a localisation key for the value instead of text in the element body. I.e. the description of the listener.

Example

Here is an example atlassian-plugin.xml file containing a single servlet context listener:

1
2
<atlassian-plugin name="Hello World Listener" key="example.plugin.helloworld" plugins-version="2">
    <plugin-info>
        <description>A basic Servlet context listener module test - says "Hello World!"</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
        <version>1.0</version>
    </plugin-info>

    <servlet-context-listener name="Hello World Listener" key="helloWorld" class="com.example.myplugins.helloworld.HelloWorldListener">
        <description>Initialises the Hello World plugin.</description>
    </servlet-context-listener>
</atlassian-plugin>

Notes

Some information to be aware of when developing or configuring a Servlet Context Listener plugin module:

  • The servlet context you listen for will not be created on web application startup. Instead, it will be created the first time a servlet or filter in your plugin is accessed after each time it is enabled, triggering a new instance of your listener followed by the calling of the listener's contextCreated() method. This means that if you disable a plugin containing a listener and re-enable it again, the following will happen:
    1. The contextDestroyed() method will be called on your listener after the plugin was disabled.
    2. A new servlet context will be created after the plugin was re-enabled.
    3. Your listener will be instantiated.
    4. The method contextCreated() on your listener will be called.

Information sourced from Plugin Framework documentation

Rate this page: