forked from ldaley/apache-camel-grails-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CamelGrailsPlugin.groovy
executable file
·67 lines (54 loc) · 2.13 KB
/
CamelGrailsPlugin.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
import grails.plugins.camel.GrailsRouteBuilder
import org.codehaus.groovy.grails.plugins.camel.RoutesArtefactHandler
import org.codehaus.groovy.grails.plugins.camel.RouteBuilderFactoryBean
import org.apache.camel.spring.CamelContextFactoryBean
import org.apache.camel.spring.CamelProducerTemplateFactoryBean
import org.apache.camel.spring.CamelConsumerTemplateFactoryBean
import org.springframework.beans.factory.config.MethodInvokingFactoryBean
class CamelGrailsPlugin {
def title = "Integration with Apache Camel"
def description = 'This plugin provides integration with Apache Camel (http://camel.apache.org). It features a service for sending messages, and a Groovy DSL for defining routes.'
def documentation = "http://grails.org/Camel+Plugin"
def version = "0.3-RC3"
def author = "Chris Navta & Luke Daley"
def authorEmail = "[email protected]"
def grailsVersion = "1.1 > *"
def artefacts = [new RoutesArtefactHandler()]
def pluginExcludes = [
"grails-app/routes/**",
"grails-app/services/**/Test*",
"grails-app/conf/**",
"grails-app/domain/**"
]
def doWithSpring = {
def routeBuilderBeanNames = []
application.routesClasses.each {
def routesClassName = it.fullName
def routesClassBeanName = "${routesClassName}RoutesClass"
def routeBuilderBeanName = "${routesClassName}Builder"
routeBuilderBeanNames << routeBuilderBeanName
"$routesClassBeanName"(MethodInvokingFactoryBean) {
targetObject = ref("grailsApplication",true)
targetMethod = "getArtefact"
arguments = [RoutesArtefactHandler.TYPE, routesClassName]
}
"$routeBuilderBeanName"(RouteBuilderFactoryBean, ref(routesClassBeanName))
}
camelContext(CamelContextFactoryBean) {
routeBuilders = routeBuilderBeanNames.collect { ref(it) }
shouldStartContext = false
}
camelProducerTemplate(CamelProducerTemplateFactoryBean) {
camelContext = camelContext
}
camelConsumerTemplate(CamelConsumerTemplateFactoryBean) {
camelContext = camelContext
}
}
def doWithApplicationContext = { applicationContext ->
applicationContext.getBean("camelContext").with {
shouldStartContext = true
start()
}
}
}