Here is what I did:
- Start with a pojo; define the methods that will be exposed to the web
- Generate getters and setters for the pojo
- Use the WTP plugin to develop the service following the tutorial described here.
- Write unit test for the web service
Problem 1:
The pojo has annotations that are not part of the CXF annotations. When I use WTP plugin to generate the web service, the generated web service is usable. The exact cause of the problem is not known yet (not that important for now as I'm prototyping it). The workaround is to remove those unrecognized annotations before going to Step 3.
Problem 2:
Since one of my private members in the pojo represents an interface of a class, the CXF complaints:
javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionExceptionat org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:275)at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:209)at org.apache.cxf.jaxws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:84)at javax.xml.ws.Endpoint.publish(Unknown Source)at com.boci.sample.test.MarketData_PortTypeTest.setupServer(MarketData_PortTypeTest.java:58)at com.boci.sample.test.MarketData_PortTypeTest.startServices(MarketData_PortTypeTest.java:43)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)at org.junit.runners.ParentRunner.run(ParentRunner.java:220)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)Caused by: org.apache.cxf.service.factory.ServiceConstructionExceptionat org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:354)at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:381)at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:523)at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:444)at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:195)at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:163)at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:100)at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:117)at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:167)at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:346)at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:259)... 21 moreCaused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptionsorg.openspaces.core.GigaSpace is an interface, and JAXB can't handle interfaces.this problem is related to the following location:at org.openspaces.core.GigaSpaceat private org.openspaces.core.GigaSpace com.boci.sample.jaxws_asm.SetGigaSpace.arg0at com.boci.sample.jaxws_asm.SetGigaSpaceorg.openspaces.core.GigaSpace does not have a no-arg default constructor.this problem is related to the following location:at org.openspaces.core.GigaSpaceat private org.openspaces.core.GigaSpace com.boci.sample.jaxws_asm.SetGigaSpace.arg0at com.boci.sample.jaxws_asm.SetGigaSpaceat com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:302) at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1136)at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at javax.xml.bind.ContextFinder.newInstance(Unknown Source)at javax.xml.bind.ContextFinder.find(Unknown Source)at javax.xml.bind.JAXBContext.newInstance(Unknown Source)at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:500)at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:337)... 31 more
This sounds horrible but it can be fixed by annotating the getters and the setters with the @webmethod(exclude=true). and voila, everything should work :)
Hopefully, this trick will be helpful for someone else as well.
No comments:
Post a Comment