Consuming generic xml soap webservice in Java without wsimport

耗尽温柔 提交于 2019-12-11 08:58:16

问题


I'm searching for a way to consume soap webservices without using wsimport and tools like that. So far, everyting I found requires the wsdl artifacts generation and I want to avoid it because I don't know wich webservices will be used.

The idea is to give the user the possibility to add several WSDL's urls / methods and the program consume them and send it's response to another url.

I'm not looking for out of the box solutions/code or something like that. What I need is to know if it is possible or not and how to aproach this problem, ideas and things like that.

Thanks!


回答1:


SOAP mandates a contract between the Client and Server. The contract is that Client will give a request XML is XYZ format and Server will give response in ABC format. Without this, SOAP does not work. This is what is defined in WSDL. So we have to use WSDL.

Tools like wsimport, wsdl4j convert these WSDL files into an object hierarchy and prepares a JAXB wrapper for you, to make life easy!

Now if you do not want to use the tools which automatically convert WSDL to Java Beans or anything of that sort, note SOAP is based on nothing but an XML. If you know how to parse an XML in java, thats pretty much it. You can use a JAX Parser to achieve this and you can read everything that comes in a SOAP request and response.

The problem that you will face is, as the complexity of the SOAP XML grows, it will be difficult for you to parse the XML properly, identify the nodes, values and relations properly. And add to that the problem where in you cannot, without a proper object hierarchy , relate between nodes which are distance apart. Meaning, from line 100 you cannot go back and relate a line 10 node, unless you start maintaining your own objects, relations etc. (which is not what you want, i guess)

Using Java Beans the object hierarchy is maintained and because of that it is easy for you to relate them between different objects at different nodes easily. But JAXB is comparatively slower than JAX.



来源:https://stackoverflow.com/questions/30459083/consuming-generic-xml-soap-webservice-in-java-without-wsimport

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