1

We're using JBoss 4.22 with portlets. When the listener tag is not in the web.xml the portlet loads, but the listener sessionDestroyed() is never called (obviously). When added the portlet isn't loaded, and there aren't any exceptions or log messages. Are there any gotchas I should be aware of?

   <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
             version="2.4">


           <!-- Listeners used by application -->
        <listener>
            <listener-class>listenerpackage.MyClassThatImplementsHttpSessionListener</listener-class>
        </listener>
    ...Other tags...
    </web-app>

In reply to the comments I have been looking through the code to find trouble spots. My Listener's constructor does have some possible trouble. Normally (not as listener) an instance would be made by the relevant portlet's (the one that isn't loaded when the listener is added to the web.xml) constructor. Can I still expect this to be the case or does the container create a instance itself?

Adam
  • 3,675
  • 8
  • 45
  • 77
  • In principle, that should be fine. Does your listener class do anything saucy that might be having knock-on effects? – skaffman Sep 17 '09 at 16:56
  • I'm not familiar with "knock-on" effects. The listener is a delegates and manages a number of objects and connections. We had it implement the HttpSessionListener so that it can clean-up objects and cleanup connections. – Adam Sep 17 '09 at 17:06
  • What is your listener doing ? Might it block the entire web-app somehow ? – nos Sep 17 '09 at 19:18

2 Answers2

1

The problem is that listeners declared in the deployment document are instantiated when that document is loaded. My class was designed to be instantiated by the portlet so needed info wasn't available.

A solution is to use an HttpSessionBindingListener and adding the class as an attribute to the session. Then the unbound() is called when the session invalidates. :)

Adam
  • 3,675
  • 8
  • 45
  • 77
1

Is your listener node in the right order in your web.xml? Maybe it's being ignored due to not following the DTD? For instance, servlets, servlet-mappings, session-configs are all supposed to be before the listener.

Greg
  • 1,126
  • 2
  • 11
  • 26
  • Where did you see this? My searches tended to show the listener tag at both the top and bottom. I've also read some threads stating that it only matters for repeats and parameters, though I don't have them now. – Adam Sep 18 '09 at 14:57