Axis2 not returning own objects

强颜欢笑 提交于 2019-12-20 06:04:49

问题


I've written some webservices where some return a simple String (this ones work) and other returning a list of objects. No, axis2 (1.5.1) cannot handle collection types, so I changed my return type to Object[] but still I recieve this exception

[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

The service is created by the eclipse provided wizard. Is axis2 not able to return these objects? Only returning primitive types doesn't fit my need.


回答1:


Axis cannot find the mapping that it needs to be able to translate the objects that you are sending via the XML. It doesn't know how to translate the XML into an object, or the other way around. A good idea is to return an object which contains an array of objects.

With Axis, you must tell it how to do the mapping between the XML and an object. This is defined using the WSDL and the Classes themselves.

1) Look at the WSDL generated by the web service: You can find this by looking at http://localhost:8080/Service?wsdl. Check this is OK.

2) Axis find it's mapping by looking at the return value of Class.getTypeDesc(); Check that this mapping is correct.

For one of my services, I have the following mapping defined as the return value of a web service (class RechercherBatimentRetour, a sub-class of 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);

This is defining the return value of this SOAP service.

// 1 -> This is saying that the WSDL ComplexType RechercherBatimentRetour is in the namespace 'sbatimentto'.

// 2 -> We're adding the field 'batiments' to the ComplexType, which is defined via a getter and setter in the class as:

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

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

The ResumeBatimentTo is also in the same namespace. So this ends up with a WSDL which contains (amoungst other things)

  <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>

All used classes must have a getTypeDesc, getSerializer & getDeserializer defined correctly in order to be able to be used.




回答2:


Actually, the return type of the Method of Web service should be non-generic.

it should not be Object , or just a List...

so , return a specific Person class object ..if one object of Person class need to return or if list of object is there.....use... list.....

do change....and enjoy....!!!!!



来源:https://stackoverflow.com/questions/3069659/axis2-not-returning-own-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!