如何从 WSDL 生成 EJB
我知道如何使用 @WebService 和 @Stateless 注释来编写 EJB 并将其公开到 WebService 中。
但是因为我们尝试使用其他工具首先生成 WSDL,然后创建 Java 代码。我可以使用 WebLogic 的 WSDLC 从 WSDL 生成服务代码。但问题是WSDLC生成的代码不是EJB。有没有做 WSDL 的建议 -> EJB?
如果可能的话,我宁愿不使用 AXIS。
I know how to use @WebService and @Stateless annotation to write an EJB and expose it into a WebService.
But because we're try to use other tools to generate WSDL first and then create Java code. I can use WebLogic's WSDLC to generate a service code from WSDL. But the problem is that the code generated by WSDLC is not EJB. Is there any suggestion to do WSDL -> EJB?
If it's possible, I prefer not to use AXIS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 EJB 和 Web 服务领域工作了一段时间,但没有遇到过任何此类工具。从逻辑上讲,这是有道理的,
Web 服务本身不是组件,而是某些业务组件(在本例中为 EJB)的外观。它们彼此解耦。
WSDL 基本代码生成器将生成这些外观或带注释的 Pojo。
POJO/Facade 是否使用 EJB 或任何其他服务来进一步委托,完全取决于实现。
这就是我觉得不会有这样的工具可以直接从 WSDL 生成 EJB 的原因。但我再次受到我的经验的限制。我很想知道这样的工具是否存在。
编辑:仅供参考,有 WSDL EJB 扩展。但它需要现有的 EJB 将其操作绑定到 WSDL。 (它不创建EJB代码)
I am working in EJB and Web Services for quite some time and did not come across any such tools. Logically it makes sense,
Web services themselves are not components but as a a facade for some business component (EJB in this case). They are decoupled from each other.
WSDL base code generators will generate these facade or annotated Pojos.
Whether that POJO/Facade uses EJB or any other services to delegate further, entirely depend on the implementation.
This is the reason I feel there wont be such tool to generate EJB directly from WSDL. But again I am limited by my experience. I would be curious to know if such tool exists.
EDIT: Just FYI, there is WSDL EJB Extension. But it needs existing EJBs to bind its operation to WSDL. (It does not create EJB code)
好吧,并不是说新的 EJB 3.1 并不比旧版本好很多,但我仍然更喜欢使用 Apache CXF 来实现 Web 服务:
http://cxf.apache.org/
它有一个很好的 wsdl2java 工具(也可以用作 Maven 插件):
http://cxf.apache.org/docs/wsdl-to-java.html
它获取您的 WSDL 文件,验证它,然后生成非常干净的 Java 模板代码来实现您的 Web 服务:您有用于编组请求和响应的 JAXB 类,一个非常简单(编码为接口)的 Web 服务实现类和每个 ws 操作的方法(当然,您必须使用业务逻辑自己实现这些方法),以及可选的一个不错的 Java 客户端存根,另一个 Java 应用程序可以使用它来轻松访问您的服务。即使没有客户端存根,您仍然可以获得一个干净且标准的实现,它基本上只是 Java 类,不需要 EJB 容器来启动(或测试)您的 Web 服务。
Well, not that the new EJB 3.1 isn't A LOT better than the old versions, but I still preffer to use Apache CXF for web-services implementation:
http://cxf.apache.org/
It has a nice wsdl2java tool (which can be also used as a maven plugin):
http://cxf.apache.org/docs/wsdl-to-java.html
which takes your WSDL file, validates it, and then generates very clean Java template code for the implementation of your web-service: you have JAXB classes for marshalling the requests and responses, a very simple (coded to interface) webservice implementation class with methods for each ws operation (which methods you must ofcourse implement yourself with your business logic), and optionally a nice Java client stub that another Java app can use to access your service easily. Even without the client stub, you still get a nice clean and standard implementation which is basicaly just Java classes, no EJB container needed to start (or test) your web service.
SAP NetWeaver Developer Studio 支持从 WSDL 生成 EJB WebService。我只是尝试一下。
http://help.sap.com/saphelp_nw72/helpdata/en/46/7f2fef88190ad3e10000000a11466f/content.htm
我还检查了 Apache CXF、WebLogic wsdlc 和 SAP 生成的代码。他们很相似。而如果您使用EJB 3,您只需在Apache CXF或WebLogic生成的代码中添加@Stateless注释即可使其成为EJB。
但我认为直接将业务 EJB 暴露给 WebService 并不是一个好主意。应该有一个服务层。使用EJB作为服务层的好处是可以使用注入轻松地访问其他EJB。
SAP NetWeaver Developer Studio supports to generate a EJB WebService from WSDL. I just try it.
http://help.sap.com/saphelp_nw72/helpdata/en/46/7f2fef88190ad3e10000000a11466f/content.htm
And I also check the code generated by Apache CXF, WebLogic wsdlc and SAP. They are similar. And if you use EJB 3, you can just add @Stateless annotation to the code generated by Apache CXF or WebLogic to let it be a EJB.
But I think it's not a good idea to expose business EJB to a WebService directly. There should be a service layer. The benefit to use EJB as a service layer is that it can use injection to access other EJB easily.