为 Web 服务创建 Java 存根的库
我想知道是否有人可以推荐一个好的库来生成 java webservices 存根作为客户端。
目前我正在使用一个嵌入了生成器的产品,该生成器只需要 WSDL,然后创建所需的类和方法。
我的问题是它会抛出警告并且不会为我尝试使用的某些网络服务创建任何方法。
真正的问题是它没有解释问题是什么(所以我可以与网络服务的所有者一起修改它),也没有让我修改输出,这样我就可以自己解决问题。
然而,网络服务的所有者(因为这种情况发生在几个不同的 ws 上)说他们的 ws 运行良好,实际上如果我使用 soapUI 他们确实有效!
我快速浏览了一下soapUI 本身使用的库,看起来很有希望。
我知道有 Axis 应该可以完成这项工作,但我担心的是我的失败生成器已经在使用该库(这让我觉得它会再次失败)
最近我不知道这两个库是否生成 java 源存根或仅具有类似
Object [] args = ...;
service.inkvoke("updateCustomer", args );
当我想要的东西时 的方法比如:
CustomerWs cws = ....
cws.updateCustomer(custId, custName, custAddress /*etc*/ );
那么,有人有一个GOOD ws 存根生成器可以推荐吗?
我即将自己编写代码,但这肯定需要几天时间才能被接受
I would like to know if anyone can recommend a good library to generate java webservices stubs as clients.
Currently I'm using a product which has embedded a generator which only needs the WSDL and then creates the needed classes and methods.
My problems is it throws warnings and doesn't create any method for some webservices I'm trying to use.
The real problem is it doesn't explain what the problem is ( so I can go with the owner of the webservice and have it modified ) nor let me modify the ouput so I can probably fix the problem my self.
Yet, the owners of the webservices ( because this happens with several different ws ) say their ws runs fine and actually if I use soapUI they actually work!!!
I took a quick look at the libraries used by soapUI it self and I looks promising.
I know there is Axis which should do the work, but my concern is that my failing generator is using that library already ( which makes me thing it will fail again )
And lately I don't know if these two libraries generate the java source stub or only have methods like
Object [] args = ...;
service.inkvoke("updateCustomer", args );
When what I would like to have is something like:
CustomerWs cws = ....
cws.updateCustomer(custId, custName, custAddress /*etc*/ );
So, anyone has a GOOD ws stubs generator that can recommend?
I'm about to handcode my own, but it will definitely take several days to be acceptable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我喜欢 Apache CXF - 它通过插件与 Maven 很好地集成,并且确实有效。 我已经使用它来生成客户端存根代码一段时间了,在我工作的上一家公司中,他们也将它用于 WS 的服务器部分。
在我使用 CXF + Maven + Subversion 处理的上一个项目中,我们没有在 Subversion 中包含生成的类,仅包含 WSDL 文件的副本 - 存根类是在 Maven 的“生成”目标中生成的。
I like Apache CXF - it integrates nicely with Maven through a plugin, and it does it work. I have been using it for a while for client stub code generation, and in the last company I worked they were using it for the server part of the WS's too.
In the last projects that I worked on with CXF + Maven + Subversion, we didn't include the generated classes in Subversion, only a copy of the WSDL file - the stub classes were generated in the "generate" goal of Maven.
Apache Axis 2 是最佳选择...尽管您可能需要尝试一下才能正确使用。 这可能是最常见的方法。 也许您使用的工具是基于轴 1 的?
Apache Axis 2 is the way to go... though you may need to play around a bit to get it right. It is perhaps the most common way to do it. Perhaps the tool that you are using is based on Axis 1?
我绝对建议使用基于 API 标准的东西。 这意味着 JAX-WS API。 Apache CXF 和 Metro 是两个主要的 JAX-WS 实现,尽管 JBoss 也有一个实现。 Axis2 有一个未经认证的实现,但没有代码生成支持。
使用基于标准的 API 的最佳部分是,如果您确实遇到某个产品的问题,您可以尝试其他产品。 在我见过的许多情况下,其他产品也不起作用,但会输出不同的错误消息或类似的信息,以帮助诊断这确实是我们自己的代码或 wsdl 中的问题。
此外,JAX-WS 直接内置于 Java6 中。 如果您计划在 Java6 上运行,您可以使用它,而不必处理额外的 jar 等。
I would definitely suggest using something based on standards based API's. That would mean JAX-WS API's. Apache CXF and Metro are the two main JAX-WS implementations, although JBoss has an implementation as well. Axis2 has a non-certified implementation, but no code gen support.
The best part of using a standards based API is if you DO run into an issue with on product, you can try the other. In many cases I've seen, the other product also doesn't work, but will spit out a different error message or similar that helped diagnose the fact that it really is a problem in our own code or wsdl.
Also, JAX-WS is built right into Java6. If you are planning to run on Java6, you could use it and not have to deal with extra jars and such.
最新的 JAX-WS 作为 Metro 的一部分 (http://metro.dev.java.net)是一个非常好的抽象层。 需要一些调整,但对我来说,它比其他一些选项更直观。
The latest JAX-WS as part of metro (http://metro.dev.java.net) is a pretty nice abstraction layer. Takes a little adjusting to but it was a lot more intuitive to me than some of the other options out there.
当您引用“Axis”时要非常小心:Apache Axis 1 于 2006 年初因线程而被放弃导致死锁和 CPU 旋转的安全错误(我们都经历过)。 使用它你将会深深后悔。 Apache Axis 2 是一个完整的重写,可能值得一看。 但我建议您首先查看 Apache CXF 和 Glassfish Metro。
更新:以下是关于死锁和100% CPU 旋转。 这是 Cyrille Le Clerc 三年前的提议的补丁,从未提交。
我们通过直接使用 Java 重新编码客户端来消除死锁和旋转。 然后 Axis 服务器拒绝与我们通信,发回 HTTP 500 错误。 我们需要谎称我们是安讯士客户才能得到正确的回应。 SOAP 互操作性并不是 Axis 1 团队的首要任务。
Be really careful when you refer to "Axis": Apache Axis 1 was abandoned in early 2006 with thread safety bugs leading to deadlocks and CPU spins (both of which we experienced). You will deeply regret using it. Apache Axis 2 is a complete rewrite and may be worth a look. But I would suggest you first look at Apache CXF and Glassfish Metro.
Update: Here are bug reports on the deadlock and 100% CPU spin. Here is Cyrille Le Clerc's proposed patch of three years ago, never committed.
We eliminated our deadlocks and spins by recoding our client in straight Java. And then the Axis server refused to talk with us, sending back HTTP 500 errors. We needed to falsely claim we were a Axis client to get a proper response. SOAP interoperability was not a priority for the Axis 1 team.
您目前使用什么? 我使用 Axis Wsdl2Java 作为 Ant 任务。 它生成您想要的存根类型。 效果很好,尽管在 Eclipse 中设置用于运行构建的类路径有点麻烦(我需要跟踪并包含一些 jar)。 在我的 ant 构建文件中,它看起来像这样:
What are you currently using? I use Axis Wsdl2Java as an Ant task. It generates the types of stubs you want. Works great, though setting up the classpath for running the build was a bit of a pain in Eclipse (there were a handful of jars I needed to track down and include). In my ant buildfile it looks like this: