Available: | Confluence 2.10 and later |
Using Servlet Filter plugin modules you can deploy Java Servlet filters as a part of your plugin, specifying the location and ordering of your filter. In this way you can build filters that can tackle tasks like profiling, monitoring, and content generation.
The root element for the Servlet Filter plugin module is servlet-filter
. To configure it, use the following attributes and child elements.
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 filter Java class must implement |
state
| Indicate whether the plugin module should be disabled (value='disabled') or enabled by default (value='enabled'). Default: enabled. |
i18n-name-key | The localization 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.
I.e. the identifier of the servlet filter. |
location | The position of the filter in the application filter chain. If two plugins provide filters at the same position, the 'weight' attribute (see later) is evaluated.
Default: before-dispatch. |
name | The human-readable name of the plugin module. i.e. the human-readable name of the filter. 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. |
weight | The weight of the filter, used to decide in which order to place the filter in the chain of filters that have the same 'location' attribute specified (see previously). The higher weight, the lower the filter's position. Default: 100. |
Attributes marked with * are required.
Name* | Description |
---|---|
description | The description of the plugin module. The 'key' attribute can be specified to declare a localization key for the value instead of text in the element body. i.e. the description of the filter. |
init-param
| Initialization parameters for the filter, specified using This element and its child elements may be repeated. |
resource | A resource for this plugin module. This element may be repeated. A 'resource' is a non-Java file that a plugin may need in order to operate. Refer to Adding Resources to your Project for details on defining a resource. |
url-pattern* | The pattern of the URL to match. This element may be repeated. The URL pattern format is used in Atlassian plugin types to map them to URLs. On the whole, the pattern rules are consistent with those defined in the Servlet 2.3 API. The following wildcards are supported:
Examples
|
dispatcher | Determines when the filter is triggered. You can include multiple
Note: This element is only available in Plugin Framework 2.5 and later. Default: filter will be triggered only for requests from the client. |
Elements marked with * are required.
Here is a sample atlassian-plugin.xml
file containing a single Servlet Filter:
1 2<atlassian-plugin name="Hello World Filter" key="example.plugin.helloworld" plugins-version="2"> <plugin-info> <description>A basic Servlet filter module test - says "Hello World!</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <servlet-filter name="Hello World Servlet" key="helloWorld" class="com.example.myplugins.helloworld.HelloWorldFilter" location="before-dispatch" weight="200"> <description>Says Hello World, Australia or your name.</description> <url-pattern>/helloworld</url-pattern> <init-param> <param-name>defaultName</param-name> <param-value>Australia</param-value> </init-param> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </servlet-filter> </atlassian-plugin>
You can access your servlet in the Atlassian web application via each url-pattern
you specify. But, unlike the Servlet plugin module, the url-pattern
is relative to the root of the web application.
For example, if you specify a url-pattern
of /helloworld
as previously, and your Atlassian application is deployed at yourserver/contextpath -- then your servlet filter would be accessed at yourserver/contextpath/helloworld.
Here is some information you need to know when developing or configuring a Servlet Filter plugin module:
init()
method is not called on web application start as for a normal filter. Instead, this method is called the first time your filter is accessed after each time plugin module is enabled. This means that if you disable a plugin containing a filter or a single Servlet Filter module and re-enable it again, the filter is re-created and its init()
method is called again.url-pattern
under which your filter is deployed. If you plan to handle the request in the filter, it is recommended to use a value that will always be unique to the world.Rate this page: