-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStandaloneTomcatRedisGrailsPlugin.groovy
73 lines (62 loc) · 2.66 KB
/
StandaloneTomcatRedisGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import ru.zinin.redis.session.RedisManager
class StandaloneTomcatRedisGrailsPlugin {
private final Logger log = LoggerFactory.getLogger('grails.plugin.standalone.StandaloneTomcatRedisGrailsPlugin')
String version = '0.3'
String grailsVersion = '2.0 > *'
List pluginExcludes = [
'docs/**',
'src/docs/**'
]
String title = 'Standalone Tomcat Redis Plugin'
String author = 'Burt Beckwith'
String authorEmail = 'burt@burtbeckwith.com'
String description = 'Uses Redis as the Tomcat session manager when using the Tomcat server'
String documentation = 'http://grails.org/plugin/standalone-tomcat-redis'
String license = 'APACHE'
def issueManagement = [system: 'GitHub', url: 'https://github.com/burtbeckwith/grails-standalone-tomcat-redis/issues']
def scm = [url: 'https://github.com/burtbeckwith/grails-standalone-tomcat-redis']
def doWithSpring = {
def conf = application.config.grails.plugin.standalone.tomcat.redis
tomcatSessionManager(RedisManager) {
disableListeners = true
if (conf.dbIndex) dbIndex = conf.dbIndex
if (conf.redisHostname) redisHostname = conf.redisHostname
if (conf.redisPassword) redisPassword = conf.redisPassword
if (conf.redisPort) redisPort = conf.redisPort
}
}
def doWithApplicationContext = { ctx ->
def tomcatSessionManager = ctx.tomcatSessionManager
if (!tomcatSessionManager) {
log.debug "No tomcatSessionManager bean found, not updating the Tomcat session manager"
return
}
def servletContext = ctx.servletContext
try {
if ('org.apache.catalina.core.ApplicationContextFacade'.equals(servletContext.getClass().name)) {
def realContext = servletContext.context
if ('org.apache.catalina.core.ApplicationContext'.equals(realContext.getClass().name)) {
def standardContext = realContext.@context
if ('org.apache.catalina.core.StandardContext'.equals(standardContext.getClass().name)) {
standardContext.manager = tomcatSessionManager
log.info "Set the Tomcat session manager to $tomcatSessionManager"
}
else {
log.warn "Not updating the Tomcat session manager, the context isn't an instance of org.apache.catalina.core.StandardContext"
}
}
else {
log.warn "Not updating the Tomcat session manager, the wrapped servlet context isn't an instance of org.apache.catalina.core.ApplicationContext"
}
}
else {
log.warn "Not updating the Tomcat session manager, the servlet context isn't an instance of org.apache.catalina.core.ApplicationContextFacade"
}
}
catch (Throwable e) {
log.error "There was a problem changing the Tomcat session manager: $e.message", e
}
}
}