How to return arbitrary XML Document using an Eclipse/AXIS2 POJO Service

青春壹個敷衍的年華 提交于 2019-12-23 03:06:16

问题


How can I return an arbitrary XML document using an Eclipse/AXIS2 POJO Service?

For full background details, see this question: Java Web Service returns string with &gt; and &lt; instead of > and <

To deploy the web service, I have a dynamic web project with a class that defines the interface of my service. The method I am concerned with returns a String type. To create and deploy the web service I right click on the class (contained in the dynamic web project) and select create web service, here I indicate that I want a "Bottom up Java bean Web Service" and that the service implementation comes from the class in my dynamic web project. This starts my service and creates a WSDL that has the definition of my ports and endpoints.

The types section of the wsdl are automatically generated based on the code that will become the service. The function of intrest has an org.w3c.DOM.Document that holds the XML that I want to return. This Document is converted to a string and returned, because the Document object is not serialized and does not have a public constructor. Is there another type that I can use as the return type for my function that will hold the XML structure throught the service call?


回答1:


I don't think it can be done via the technologies and process you are using.

Ideally you could just return a org.w3c.dom.Document (or a comparable DOM object in that framework) and it would supply the "any" type in the WSDL but, unfortunately, it doesn't seem to work like that. AXIS2 is strongly typed and needs a data binding technology (e.g. ADB, XmlBeans, JiBX, possibly JAXB) for request and response data. It seems to have support for the <xsd:any> and <xsd:anyType> elements via AXIOM services, but that is a different implementation style than you are using.

See this interesting discussion "Unknown type can not serialize" Exception. Also, here is a related SO question, AXiS2 - Problem in returning the String value. < and > are getting converted to &lt; and &gt;



来源:https://stackoverflow.com/questions/7877515/how-to-return-arbitrary-xml-document-using-an-eclipse-axis2-pojo-service

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