无法使用com.google.gdata.data.spreadsheet的SpreadsheetService,SpreadsheetFeed和WorksheetEntry属性创建DTO

时间:2011-09-15 11:30:49

标签: osgi

我目前正在开发一个基于OSGI的项目。这是我遇到的情景: 1-我有返回的WebService com.google.gdata.client.spreadsheet.SpreadsheetService对象。

com.google.gdata.data.spreadsheet.SpreadsheetFeed

com.google.gdata.data.spreadsheet.SpreadsheetFeed 2-在运行时,我遇到了一个例外,

    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-我被告知Web服务导致此异常,因为除了Java类或DTO类之外,它不能返回任何对象。 4-我使用SpreadsheetService,SpreadsheetFeed,WorksheetEntry作为其属性创建了CustomDTO,以便我可以将CustomDTO作为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-现在我所有的DTO捆绑都崩溃了。我不能在DTO包上使用任何其他DTO。 6-PS。当我删除CustomDTO.java中的当前属性并添加一个常规的java对象,如String testString =“Hello World”在这种情况下,DTO工作正常。 7-我可以看到很明显我不能在我的DTO中使用SpreadsheetService,WorksheetEntry,SpreadsheetFeed作为属性。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

这似乎不是特定的OSGi问题,而是一个常见的Web服务问题。

您可以为每种类型编写javax.xml.bind.annotation.adapters.XmlAdapter并将其转换为您自己的DTO,或者通过为每个Google类别编写单独的DTO来更加手动执行此操作。这是一个相当全面的example of an XmlAdapter

String testString="Hello World"这样的原始类型可以正常工作,因为这些是Java / xs:types的已知映射。但是,不遵循Bean样式,没有零arg构造函数等的复杂对象肯定会导致问题。

旁注;我不认为你应该传递服务,如果它处于携带状态,你应该提取它。