PageRenderTime 25ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/content/server/jira/platform/servlet-context-listener.md

https://bitbucket.org/mrzymski/jira-server-docs
Markdown | 129 lines | 109 code | 20 blank | 0 comment | 0 complexity | 52b56148c2b7c25f81b9cdea876e2fc4 MD5 | raw file
  1. ---
  2. aliases:
  3. - /server/jira/platform/servlet-context-listener-plugin-module-4227084.html
  4. - /server/jira/platform/servlet-context-listener-plugin-module-4227084.md
  5. category: reference
  6. confluence_id: 4227084
  7. dac_edit_link: https://developer.atlassian.com/pages/editpage.action?cjm=wozere&pageId=4227084
  8. dac_view_link: https://developer.atlassian.com/pages/viewpage.action?cjm=wozere&pageId=4227084
  9. date: '2017-12-08'
  10. legacy_title: Servlet Context Listener Plugin Module
  11. platform: server
  12. product: jira
  13. subcategory: modules
  14. title: Servlet context listener
  15. ---
  16. # Servlet context listener
  17. <table>
  18. <colgroup>
  19. <col style="width: 40%" />
  20. <col style="width: 60%" />
  21. </colgroup>
  22. <tbody>
  23. <tr class="odd">
  24. <td><p>Available:</p></td>
  25. <td><p>Servlet Context Listener plugin modules are available in JIRA 4.0 and later.</p></td>
  26. </tr>
  27. </tbody>
  28. </table>
  29. ## Purpose of this Module Type
  30. 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.
  31. ## Configuration
  32. The root element for the Servlet Context Listener plugin module is **`servlet-context-listener`**. It allows the following attributes and child elements for configuration:
  33. #### Attributes
  34. <table>
  35. <colgroup>
  36. <col style="width: 20%" />
  37. <col style="width: 80%" />
  38. </colgroup>
  39. <thead>
  40. <tr class="header">
  41. <th><p>Name*</p></th>
  42. <th><p>Description</p></th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. <tr class="odd">
  47. <td><p>class</p></td>
  48. <td><p>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 <a href="https://developer.atlassian.com/display/DOCS/Creating+Plugin+Module+Instances">creating plugin module instances</a>. </p>
  49. <p>The servlet context listener Java class. Must implement <code>javax.servlet.ServletContextListener</code>.</p></td>
  50. </tr>
  51. <tr class="even">
  52. <td><p>state</p>
  53. <p> </p></td>
  54. <td><p>Indicate whether the plugin module should be disabled by default (value='disabled') or enabled by default (value='enabled').</p>
  55. <p><strong>Default:</strong> enabled.</p></td>
  56. </tr>
  57. <tr class="odd">
  58. <td><p>i18n-name-key</p></td>
  59. <td>The localisation key for the human-readable name of the plugin module.</td>
  60. </tr>
  61. <tr class="even">
  62. <td><p>key</p></td>
  63. <td><p>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.</p>
  64. <p> </p>
  65. <pre><code>&lt;component-import key=&quot;appProps&quot; interface=&quot;com.atlassian.sal.api.ApplicationProperties&quot;/&gt;</code></pre>
  66. <p> </p>
  67. <p>In the example, <code>appProps</code> is the key for this particular module declaration, for <code>component-import</code>, in this case.</p>
  68.  
  69. <p>I.e. the identifier of the context listener.</p></td>
  70. </tr>
  71. <tr class="odd">
  72. <td><p>name</p></td>
  73. <td><p>The human-readable name of the plugin module. </p>
  74. <p>I.e. the human-readable name of the listener.</p>
  75. <p><strong>Default:</strong> the plugin key.</p></td>
  76. </tr>
  77. <tr class="even">
  78. <td><p>system</p></td>
  79. <td><p>Indicates whether this plugin module is a system plugin module (value='true') or not (value='false'). Only available for non-OSGi plugins.</p>
  80. <p><strong>Default:</strong> false.</p></td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. **\*key attribute is required.**
  85. #### Elements
  86. - 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.
  87. ## Example
  88. Here is an example `atlassian-plugin.xml` file containing a single servlet context listener:
  89. ``` xml
  90. <atlassian-plugin name="Hello World Listener" key="example.plugin.helloworld" plugins-version="2">
  91. <plugin-info>
  92. <description>A basic Servlet context listener module test - says "Hello World!"</description>
  93. <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
  94. <version>1.0</version>
  95. </plugin-info>
  96. <servlet-context-listener name="Hello World Listener" key="helloWorld" class="com.example.myplugins.helloworld.HelloWorldListener">
  97. <description>Initialises the Hello World plugin.</description>
  98. </servlet-context-listener>
  99. </atlassian-plugin>
  100. ```
  101. ## Notes
  102. Some information to be aware of when developing or configuring a Servlet Context Listener plugin module:
  103. - 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:
  104. 1. The `contextDestroyed()` method will be called on your listener after the plugin was disabled.
  105. 2. A new servlet context will be created after the plugin was re-enabled.
  106. 3. Your listener will be instantiated.
  107. 4. The method `contextCreated()` on your listener will be called.
  108. ##### RELATED TOPICS
  109. Information sourced from [Plugin Framework documentation](https://developer.atlassian.com/display/DOCS/_Content+for+Servlet+Context+Listener+Plugin+Module)