Thursday, 15 October 2009

Grails 'metadata' from within HttpSessionListener

I needed to extract the application-name during execution - under normal circumstances this can be achieved as follows:

String appName = grailsApplication.metadata['app.name']

However, I recently needed to extract the application-name from within an implementation of the HttpSessionListener interface (which does not support inject of the grailsApplication object). This was part of resource releasing once following a session timeout.

Access to the same object can be achieved from within a SessionListener via the ApplicationHolder class:

import org.codehaus.groovy.grails.commons.ApplicationHolder

...

String appName = ApplicationHolder.getApplication().metadata['app.name']

1 comments: