forked from Grails-Plugin-Consortium/grails-cxf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CxfGrailsPlugin.groovy
108 lines (93 loc) · 3.64 KB
/
CxfGrailsPlugin.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import org.codehaus.groovy.grails.commons.GrailsClassUtils
class CxfGrailsPlugin {
// the plugin version
def version = "0.10.0"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.0.0 > *"
// the other plugins this plugin depends on
def loadAfter = ['hibernate']
def observe = ['hibernate']
def dependsOn = [hibernate: '2.0.0 > *']
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp",
"grails-app/services/test/**",
"web-app/**",
"src/test/**",
"src/java/test/**",
"test/**",
"spock-0.6"
]
def author = "Ryan Crum"
def authorEmail = "[email protected]"
def title = "CXF plug-in for Grails"
def description = 'Add SOAP exposure to Grails services using Apache CXF.'
def developers = [
[name: "Ryan Crum", email: "[email protected]"],
[name: "Christian Oestreich", email: "[email protected]"]]
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/cxf"
def doWithSpring = {
//In 2.5.2 the CXFServlet has some hard coded paths to "/WEB-INF/cxf-servlet.xml"
//probably don't want to create that file, so just wire up the cxf bean here.
cxf(org.apache.cxf.bus.spring.SpringBus)
if(application.serviceClasses) {
application.serviceClasses.each { service ->
def srvClass = service.getClazz()
def exposes = GrailsClassUtils.getStaticPropertyValue(srvClass, 'expose')
if(exposes?.contains('cxf')) {
def wsName = service.propertyName
"${wsName}Factory"(org.grails.cxf.GrailsCXFServerFactoryBean, wsName, srvClass) {
address = "/${wsName.replace("Service", "")}"
serviceBean = ref("${service.propertyName}")
}
} else if(exposes?.contains('cxfjax')) { // can't do both!
def wsName = service.propertyName
"${wsName}Factory"(org.grails.cxf.GrailsCXFJaxWsServerFactoryBean, wsName, srvClass) {
address = "/${wsName.replace("Service", "")}"
serviceBean = ref("${service.propertyName}")
}
} else if(exposes?.contains('cxfrs')) { // can't do both!
def wsName = service.propertyName
"${wsName}Factory"(org.grails.cxf.GrailsCXFRSServerFactoryBean, wsName, srvClass) {
address = "/${wsName.replace("Service", "")}"
serviceBeans = [ref("${service.propertyName}")]
}
}
}
}
}
def doWithApplicationContext = { applicationContext ->
}
def doWithWebDescriptor = { xml ->
def filters = xml.filter
def filterMappings = xml.'filter-mapping'
def servlets = xml.servlet
def servletMappings = xml.'servlet-mapping'
servlets[servlets.size() - 1] + {
servlet {
'servlet-name'('CXFServlet')
'servlet-class'('org.grails.cxf.GrailsCXFServlet')
'load-on-startup'(1)
}
}
servletMappings[servletMappings.size() - 1] + {
'servlet-mapping' {
'servlet-name'('CXFServlet')
'url-pattern'("/services/*")
}
}
}
def doWithDynamicMethods = { ctx ->
// TODO Implement registering dynamic methods to classes (optional)
}
def onChange = { event ->
// TODO Implement code that is executed when any artefact that this plugin is
// watching is modified and reloaded. The event contains: event.source,
// event.application, event.manager, event.ctx, and event.plugin.
}
def onConfigChange = { event ->
// TODO Implement code that is executed when the project configuration changes.
// The event is the same as for 'onChange'.
}
}