0

I'm currently working on an OSGI based project. Here is the scenario that I've faced: 1- I have WebService that returns com.google.gdata.client.spreadsheet.SpreadsheetService object.

com.google.gdata.data.spreadsheet.SpreadsheetFeed

and com.google.gdata.data.spreadsheet.SpreadsheetFeed 2- In run time, I faced an exception,

    5:40:08,183 Timer-2  INFO CXFServer:77 - Starting web service as SOAP URL: /spreadSheetConnector; WebService: com.pearlox.okarabia.ws.googlespreadsheetconnector.impl.GoogleSpreadSheetConnectorWebServiceImpl@1809715
15:40:08,431 Timer-2 ERROR CXFServer:68 - org.apache.cxf.service.factory.ServiceConstructionException
javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
    at 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(Endpoint.java:170)
    at com.pearlox.varaza.cxf.CXFServer.startWSImpl(CXFServer.java:78)
    at com.pearlox.varaza.cxf.CXFServer.startWSImpl(CXFServer.java:49)
    at com.pearlox.varaza.osgi.AbstractServer.startAllWebServices(AbstractServer.java:115)
    at com.pearlox.varaza.osgi.AbstractServer.start(AbstractServer.java:60)
    at com.pearlox.varaza.cxf.CXFServer.handleEvent(CXFServer.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
    at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy356.handleEvent(Unknown Source)
    at org.eclipse.equinox.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:177)
    at org.eclipse.equinox.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:198)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:220)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
    at org.eclipse.equinox.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:137)
    at org.eclipse.equinox.event.EventAdminImpl.sendEvent(EventAdminImpl.java:76)
    at com.pearlox.varaza.cxf.CXFServletExt.sendEvent(CXFServletExt.java:85)
    at com.pearlox.varaza.cxf.CXFServletExt.loadBus(CXFServletExt.java:58)
    at org.apache.cxf.transport.servlet.AbstractCXFServlet.init(AbstractCXFServlet.java:78)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:612)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.springframework.osgi.web.deployer.jetty.JettyWarDeployer.startWebAppContext(JettyWarDeployer.java:210)
    at org.springframework.osgi.web.deployer.jetty.JettyWarDeployer.startDeployment(JettyWarDeployer.java:122)
    at org.springframework.osgi.web.deployer.support.AbstractWarDeployer.deploy(AbstractWarDeployer.java:93)
    at org.springframework.osgi.web.extender.internal.activator.WarLoaderListener$DeploymentManager$DeployTask.doRun(WarLoaderListener.java:257)
    at org.springframework.osgi.web.extender.internal.activator.WarLoaderListener$DeploymentManager$BaseTask.run(WarLoaderListener.java:215)
    at org.springframework.scheduling.timer.DelegatingTimerTask.run(DelegatingTimerTask.java:70)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:351)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:460)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:548)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:523)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:271)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:177)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:100)
    at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:105)
    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)
    ... 46 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
com.google.gdata.util.Version does not have a no-arg default constructor.
    this problem is related to the following location:
        at com.google.gdata.util.Version
        at public com.google.gdata.util.Version com.google.gdata.client.Service.getProtocolVersion()
        at com.google.gdata.client.Service
        at public com.google.gdata.client.Service com.google.gdata.data.BaseEntry.getService()
        at com.google.gdata.data.BaseEntry
        at com.google.gdata.data.spreadsheet.WorksheetEntry
com.google.gdata.client.Service$GDataRequestFactory is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at com.google.gdata.client.Service$GDataRequestFactory
        at public com.google.gdata.client.Service$GDataRequestFactory com.google.gdata.client.Service.getRequestFactory()
        at com.google.gdata.client.Service
        at public com.google.gdata.client.Service com.google.gdata.data.BaseEntry.getService()
        at com.google.gdata.data.BaseEntry
        at com.google.gdata.data.spreadsheet.WorksheetEntry
com.google.gdata.client.Service$GDataRequestFactory does not have a no-arg default constructor.
    this problem is related to the following location:
        at com.google.gdata.client.Service$GDataRequestFactory
        at public com.google.gdata.client.Service$GDataRequestFactory com.google.gdata.client.Service.getRequestFactory()
        at com.google.gdata.client.Service
        at public com.google.gdata.client.Service com.google.gdata.data.BaseEntry.getService()
        at com.google.gdata.data.BaseEntry
        at com.google.gdata.data.spreadsheet.WorksheetEntry

3- I was told that the Webservice is causing this exception because it can not return object of anything but Java class or a DTO class. 4- I created CustomDTO with SpreadsheetService, SpreadsheetFeed, WorksheetEntry as its properties, so that I can return CustomDTO as a return object of my WebService.

 package com.pearlox.okarabia.dto;

    import com.google.gdata.client.spreadsheet.SpreadsheetService;
    import com.google.gdata.data.spreadsheet.SpreadsheetFeed;
    import com.google.gdata.data.spreadsheet.WorksheetEntry;

    public class CustomDTO {
        private SpreadsheetService spreadsheetService;
        private WorksheetEntry worksheetEntry;
        private SpreadsheetFeed spreadsheetFeed;

        public CustomDTO(){

        }

        public void setSpreadsheetService(SpreadsheetService spreadsheetService) {
            this.spreadsheetService = spreadsheetService;
        }

        public SpreadsheetService getSpreadsheetService() {
            return spreadsheetService;
        }

        public void setWorksheetEntry(WorksheetEntry worksheetEntry) {
            this.worksheetEntry = worksheetEntry;
        }

        public WorksheetEntry getWorksheetEntry() {
            return worksheetEntry;
        }

        public void setSpreadsheetFeed(SpreadsheetFeed spreadsheetFeed) {
            this.spreadsheetFeed = spreadsheetFeed;
        }

        public SpreadsheetFeed getSpreadsheetFeed() {
            return spreadsheetFeed;
        }

    }

5- Now all my DTO bundle crashed. I can not use any other DTO on the DTO bundle. 6- PS. when I delete current properties in CustomDTO.java and add a regular java object like String testString="Hello World" In such case the DTO works fine. 7- I can see it is very obvious that I can not use SpreadsheetService, WorksheetEntry, SpreadsheetFeed as properties in my DTO.

Can anyone help?

Ali Taha Ali Mahboub
  • 3,271
  • 6
  • 26
  • 25

1 Answers1

1

This doesn't appear to be specifically an OSGi problem, but rather a common webservice issue.

You could write a javax.xml.bind.annotation.adapters.XmlAdapter for each type and convert these into your own DTOs, or do this more manually by writing a separate DTO for each of the google classes. Here's a reasonably comprehensive example of an XmlAdapter

Primitive types like String testString="Hello World" will work ok as these are known mappings to/from Java - xs:types. But complex objects that don't follow the Bean style, having no zero arg constructors etc will definitely cause problems.

On a side note; I don't think you should be passing the service around, if it's carrying state you should extract that instead.

Community
  • 1
  • 1
earcam
  • 6,662
  • 4
  • 37
  • 57