I’m trying to create a web service using Grails and Apache CXF, naturally using the CXF-Grails plugin. I created a simple service called Test Service
package testcxf
class TestService {
static expose = ['cxf']
String echoString(String str) {
return str
}
String reverseString(String str) {
return str.reverse()
}
}
This service works exactly as expected and a test client successfully called the echo and reverse methods. Next I created a simple domain class called Person
package testcxf
class Person {
String name
String city
int age
static constraints = {
}
}
And revised the service with some basic functions to interact with the domain.
package testcxf
class TestService {
static expose = ['cxf']
String echoString(String str) {
return str
}
String reverseString(String str) {
return str.reverse()
}
void addPerson(Person person) {
person.save()
}
Person getPerson(String name) {
return Person.findByName(name)
}
List<Person> getAllPeople() {
return Person.findAll()
}
}
That’s when it all fell apart. When calling grails run-app I received the following exception. The application did complete startup but the wsdl that was generated was incomplete and lacked all definitions of the complex type Person.
| Error 2012-05-01 20:51:03,504 [pool-7-thread-1] ERROR [localhost].[/TestCxf] - StandardWrapper.Throwable
Message: Error creating bean with name 'testServiceBean': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.apache.cxf.endpoint.Server org.apache.cxf.frontend.ServerFactoryBean.create()] threw exception; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
Line | Method
->> 578 | createApplicationContext in grails.spring.BeanBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 57 | loadAdditionalConfig in org.grails.cxf.GrailsCXFServlet
| 40 | init . . . . . . . . . . in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . . . . . . . . in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by BeanDefinitionStoreException: Factory method [public org.apache.cxf.endpoint.Server org.apache.cxf.frontend.ServerFactoryBean.create()] threw exception; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
->> 578 | createApplicationContext in grails.spring.BeanBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 57 | loadAdditionalConfig in org.grails.cxf.GrailsCXFServlet
| 40 | init . . . . . . . . . . in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . . . . . . . . in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by ServiceConstructionException: null
->> 341 | initialize in org.apache.cxf.jaxb.JAXBDataBinding
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 86 | initializeDataBindings in org.apache.cxf.service.factory.AbstractServiceFactoryBean
| 442 | buildServiceFromClass . in org.apache.cxf.service.factory.ReflectionServiceFactoryBean
| 505 | initializeServiceModel in ''
| 242 | create . . . . . . . . . in ''
| 101 | createEndpoint in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory
| 148 | create . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean
| 578 | createApplicationContext in grails.spring.BeanBuilder
| 57 | loadAdditionalConfig . . in org.grails.cxf.GrailsCXFServlet
| 40 | init in ''
| 334 | innerRun . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . in java.lang.Thread
Caused by IllegalAnnotationsException: 5 counts of IllegalAnnotationExceptions
->> 102 | check in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 472 | getTypeInfoSet in com.sun.xml.bind.v2.runtime.JAXBContextImpl
| 302 | <init> . . . . . . . . . in ''
| 1140 | build in com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder
| 154 | createContext . . . . . in com.sun.xml.bind.v2.ContextFactory
| 121 | createContext in ''
| 248 | newInstance . . . . . . in javax.xml.bind.ContextFinder
| 235 | newInstance in ''
| 432 | find . . . . . . . . . . in ''
| 637 | newInstance in javax.xml.bind.JAXBContext
| 564 | createContext . . . . . in org.apache.cxf.jaxb.JAXBDataBinding
| 504 | createJAXBContextAndSchemas in ''
| 324 | initialize . . . . . . . in ''
| 86 | initializeDataBindings in org.apache.cxf.service.factory.AbstractServiceFactoryBean
| 442 | buildServiceFromClass . in org.apache.cxf.service.factory.ReflectionServiceFactoryBean
| 505 | initializeServiceModel in ''
| 242 | create . . . . . . . . . in ''
| 101 | createEndpoint in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory
| 148 | create . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean
| 578 | createApplicationContext in grails.spring.BeanBuilder
| 57 | loadAdditionalConfig . . in org.grails.cxf.GrailsCXFServlet
| 40 | init in ''
| 334 | innerRun . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . in java.lang.Thread
| Error 2012-05-01 20:51:03,570 [pool-7-thread-1] ERROR [localhost].[/TestCxf] - Servlet /TestCxf threw load() exception
Message: 5 counts of IllegalAnnotationExceptions
Line | Method
->> 102 | check in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 472 | getTypeInfoSet in com.sun.xml.bind.v2.runtime.JAXBContextImpl
| 302 | <init> . . . . . . . . . . in ''
| 1140 | build in com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder
| 154 | createContext . . . . . . . in com.sun.xml.bind.v2.ContextFactory
| 121 | createContext in ''
| 248 | newInstance . . . . . . . . in javax.xml.bind.ContextFinder
| 235 | newInstance in ''
| 432 | find . . . . . . . . . . . in ''
| 637 | newInstance in javax.xml.bind.JAXBContext
| 564 | createContext . . . . . . . in org.apache.cxf.jaxb.JAXBDataBinding
| 504 | createJAXBContextAndSchemas in ''
| 324 | initialize . . . . . . . . in ''
| 86 | initializeDataBindings in org.apache.cxf.service.factory.AbstractServiceFactoryBean
| 442 | buildServiceFromClass . . . in org.apache.cxf.service.factory.ReflectionServiceFactoryBean
| 505 | initializeServiceModel in ''
| 242 | create . . . . . . . . . . in ''
| 101 | createEndpoint in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory
| 148 | create . . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean
| 578 | createApplicationContext in grails.spring.BeanBuilder
| 57 | loadAdditionalConfig . . . in org.grails.cxf.GrailsCXFServlet
| 40 | init in ''
| 334 | innerRun . . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . . . in java.lang.Thread
Looking at the cxf plugin info page I found this:
—–EDIT—–
This one bothered me a lot because it should be so simple. I don’t know if you ever got it working but here is what I had to do:
It would throw the same error you were receiving with any XmlAccessorType except NONE. Then in order to get the fields available I had to add the @XmlElement annotation.
Now it runs without the error and the WSDL contains the details of the Person object: