Nullpointer部署Web服务,返回JaxbElement

时间:2016-02-02 08:16:51

标签: java xml web-services xsd jaxb

我的问题,一步一步:

  • 我使用XJC(来自xsd源)生成了一些类

  • 我在java中编写了一个jaxWs webservice

  • 其中一个web方法必须返回一个jaxbElement,因为其中一个xsd没有root元素。回报是:

    JAXBElement<MessageAcknowledgementType> element = new objectFactory().createOTAHotelDescriptiveContentNotifRS(rs);
    Return element;
    

WebMethod声明是:

@WebMethod
@WebResult(name="OTA_HotelDescriptiveContentNotifRS")
public JAXBElement<MessageAcknowledgementType> modifyHotelRQ(@WebParam(name="OTA_HotelDescriptiveContentNotifRQ")OTAHotelDescriptiveContentNotifRQ rq) {

当部署到tomcat(tomEE)时,会启动nullpointer异常,但如果我将返回更改为String,则一切正常。

我导航到类com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.getElementNamespaceURI,方法public String getElementLocalName(JAXBElement e)在部署时在“e”中收到空值:

 public String getElementLocalName(JAXBElement e) {
    return e.getName().getLocalPart();
}

跟踪:

java.lang.NullPointerException
    at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.getElementNamespaceURI(ElementBeanInfoImpl.java:279)
    at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.getElementNamespaceURI(ElementBeanInfoImpl.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:90)
    at com.sun.proxy.$Proxy113.getElementNamespaceURI(Unknown Source)
    at org.apache.cxf.jaxb.JAXBSchemaInitializer.begin(JAXBSchemaInitializer.java:225)
    at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:109)
    at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:130)
    at org.apache.cxf.service.ServiceModelVisitor.walk(ServiceModelVisitor.java:74)
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:417)
    at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:490)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:697)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:550)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:214)
    at org.apache.openejb.server.cxf.CxfEndpoint.doServiceCreate(CxfEndpoint.java:107)
    at org.apache.openejb.server.cxf.pojo.PojoEndpoint.<init>(PojoEndpoint.java:89)
    at org.apache.openejb.server.cxf.pojo.PojoWsContainer.createEndpoint(PojoWsContainer.java:70)
    at org.apache.openejb.server.cxf.pojo.PojoWsContainer.createEndpoint(PojoWsContainer.java:45)
    at org.apache.openejb.server.cxf.CxfWsContainer.start(CxfWsContainer.java:50)
    at org.apache.openejb.server.cxf.CxfService.createPojoWsContainer(CxfService.java:126)
    at org.apache.openejb.server.webservices.WsService.afterApplicationCreated(WsService.java:417)
    at org.apache.tomee.webservices.TomeeJaxWsService.afterApplicationCreated(TomeeJaxWsService.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.openejb.observer.ObserverManager$MethodInvocation.invoke(ObserverManager.java:400)
    at org.apache.openejb.observer.ObserverManager$InvocationList.invoke(ObserverManager.java:515)
    at org.apache.openejb.observer.ObserverManager.doFire(ObserverManager.java:111)
    at org.apache.openejb.observer.ObserverManager.fireEvent(ObserverManager.java:100)
    at org.apache.openejb.loader.SystemInstance.fireEvent(SystemInstance.java:135)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.afterStart(TomcatWebAppBuilder.java:1661)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:116)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:168)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

请帮助,我用这个石头丢了两整天......

0 个答案:

没有答案