Axis2没有返回自己的对象

时间:2010-06-18 12:45:32

标签: java web-services axis2

我写了一些webservices,其中一些返回一个简单的String(这个工作)和其他返回一个对象列表。不,axis2(1.5.1)无法处理集合类型,因此我将返回类型更改为Object[]但仍然接受此异常

[ERROR] java.lang.RuntimeException: org.apache.axis2.AxisFault: Mapping qname not fond for the package: de.ac.dto
org.apache.axis2.AxisFault: java.lang.RuntimeException: org.apache.axis2.AxisFault: Mapping qname not fond for the package: de.ac.dto
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:161)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.axiom.om.OMException: java.lang.RuntimeException: org.apache.axis2.AxisFault: Mapping qname not fond for the package: de.ac.dto
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:260)
    at org.apache.axiom.om.impl.llom.OMNodeImpl.build(OMNodeImpl.java:335)
    at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:737)
    at org.apache.axiom.om.impl.llom.OMElementImpl.detach(OMElementImpl.java:706)
    at org.apache.axiom.om.impl.llom.OMNodeImpl.setParent(OMNodeImpl.java:124)
    at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:297)
    at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:213)
    at org.apache.axiom.soap.impl.llom.SOAPBodyImpl.addChild(SOAPBodyImpl.java:231)
    at org.apache.axis2.rpc.receivers.RPCUtil.processResponseAsDocLitWrapped(RPCUtil.java:381)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:138)
    ... 19 more
Caused by: java.lang.RuntimeException: org.apache.axis2.AxisFault: Mapping qname not fond for the package: de.ac.dto
    at org.apache.axis2.databinding.utils.BeanUtil.getPropertyQnameList(BeanUtil.java:261)
    at org.apache.axis2.databinding.utils.BeanUtil.getPullParser(BeanUtil.java:67)
    at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.processProperties(ADBXMLStreamReaderImpl.java:998)
    at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.next(ADBXMLStreamReaderImpl.java:835)
    at org.apache.axis2.util.StreamWrapper.next(StreamWrapper.java:71)
    at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:60)
    at org.apache.axiom.om.impl.builder.SafeXMLStreamReader.next(SafeXMLStreamReader.java:183)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:597)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
    ... 28 more
Caused by: org.apache.axis2.AxisFault: Mapping qname not fond for the package: de.ac.dto
    at org.apache.axis2.databinding.utils.BeanUtil.getPropertyQnameList(BeanUtil.java:117)
    ... 36 more

该服务由eclipse提供的向导创建。 axis2无法返回这些对象吗?只返回原始类型不符合我的需要。

2 个答案:

答案 0 :(得分:2)

Axis找不到能够翻译您通过XML发送的对象所需的映射。它不知道如何将XML转换为对象,反之亦然。一个好主意是返回一个包含对象数组的对象。

使用Axis,您必须告诉它如何在XML和对象之间进行映射。这是使用WSDL和Classes本身定义的。

1)查看Web服务生成的WSDL:您可以通过查看http://localhost:8080/Service?wsdl找到它。检查一下就可以了。

2)Axis通过查看Class.getTypeDesc()的返回值来查找它的映射;检查此映射是否正确。

对于我的一个服务,我将以下映射定义为Web服务的返回值(类RechercherBatimentRetour,Retour的子类)。

typeDesc.setXmlType(new QName("sbatimentto", "RechercherBatimentRetour")); // 1
org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("batiments");
elemField.setXmlName(new QName("", "batiments")); // 2
elemField.setXmlType(new QName("sbatimentto", "ResumeBatimentTo"));
elemField.setNillable(true);
typeDesc.addFieldDesc(elemField);

这是定义此SOAP服务的返回值。

// 1 - >这就是说WSDL ComplexType RechercherBatimentRetour位于命名空间'sbatimentto'。

// 2 - >我们将字段'batiments'添加到ComplexType中,ComplexType是通过类中的getter和setter定义的:

public ResumeBatimentTo[] getBatiments() {
    return batiments;
}

public void setBatiments(ResumeBatimentTo[] batiments) {
    this.batiments = batiments;
}

ResumeBatimentTo也在同一名称空间中。所以这最终得到一个包含(其他东西)的WSDL

  <complexType name="Retour">
    <sequence>
     <element name="codeRetour" nillable="true" type="xsd:string"/>
     <element name="message" nillable="true" type="xsd:string"/>
     <element name="statut" type="xsd:boolean"/>
    </sequence>
    </complexType>

    <complexType name="RechercherBatimentRetour">
    <complexContent>
     <extension base="tns1:Retour">
      <sequence>
       <element name="batiments" nillable="true" type="impl:ArrayOf_tns1_ResumeBatimentTo"/>
      </sequence>
     </extension>
    </complexContent>
  </complexType>

所有使用过的类必须有getTypeDesc,getSerializer&amp;正确定义了getDeserializer以便能够使用。

答案 1 :(得分:0)

实际上,Web服务方法的返回类型应该是非泛型的。

它不应该是Object,也不应该只是List ...

所以,返回一个特定的Person类对象..如果Person类的一个对象需要返回   或者如果对象列表在那里.....使用...列表.....

做改变....并享受...... !!!!!