J2EE Sessions and OnSessionEnd (HttpSessionBindingListener)

Here I was thinking I was really clever – but I guess I’m not as clever as I had thought.

I wanted to create a way for CF’ers to have a way to determine when a Session had ended – I could do it in J2EE, so I could do it in CF? Right? CF just sits on top of Java, so it should be easy.

So I created a Java class that implemented the HttpSessionBindingListener interface and set it up to call a series of URLs when a session was either timed out, or the user logged off.

I turned on ‘Use J2EE Session Variables’ within the cfadmin app and wrote the below CF test code:

 obj = createObject("Java", "com.compoundtheory.URLCallOnSessionUnbind").init();
 session.obj = obj;
 StructDelete(session, "obj");

Using this and subsequent test code, I found that neither valuBound() or  valueUnBound() was called on the my Java object.

This led me to believe that CF only implements a mechanism for sharing data between J2EE sessions and itself, and does not actually utilise the actual J2EE session objects themselves.

Apon further examination (thanks to getJavaMetaData), I discovered that the CF session object doesn’t even come close to the javax.servlet.http.HttpSession interface, so there was no way this was going to work in the first place.  (It is in face a coldusion.runtime.j2eeSessionScope object).

It’s a pity that this hasn’t worked, it would have been very handy – and I know how long CF’ers have wanted the capability to know when sessions had ended.

So I guess in conclusion – we now all know, that when it says in the CF admin ‘Use J2EE session variables’ – it’s really not telling the entire truth.

Naughty Naughty. ;o)

Just for fun these guys over at IBM talk about some ways of sharing J2EE and CF session information.  An interesting read never the less.

Leave a Comment


  • Andreas Thomas | June 21, 2004

    The Session Expiration Alarm (Part of DRK 7) uses the object which is returned by "getPageContext().getRequest().getSession()" to get in touch with the HttpSessionBindingListener.

  • Mark | June 21, 2004

    Andreas – I was looking into getting the HttpSession session via the pageContext, but I’m not convinced that they will both end at the same time – or are in any way related in that way.

    But thanks for the heads up, I will look in that direction to see what I can find.

    (Obviously I haven’t got the DRK)