在 CXF 中,为什么使用 JAXB 之外的任何其他绑定? (MTOM 附件、Aegis、XMLBeans...)

发布于 2024-09-17 09:12:31 字数 666 浏览 8 评论 0原文

我一直在研究 Apache CXF,特别是它支持的各种数据绑定:JAXB(默认)、MTOM、Aegis 和 XMLBeans。由于所有这些都得到支持,我想每个都有其优点。我想出了这些:

  • 显然,在涉及大型附件时,MTOM 是首选。
  • JAXB 依赖于注释,因此当类的修改受到限制时,它不太适合。
  • Aegis 没有 wsdl2java 工具,因此它不太适合“契约优先”开发,即从 WSDL 开始并从中生成 Java 代码。
  • 看起来,Aegis 通过其在 Class.aegis.xml 文件中的声明性语法,对 Java 类和 XML 之间的映射提供了更多的控制。另一方面,我无法设计任何 JAXB 无法解决问题的场景。

我发现这个问题将 JAXB 和 XMLBeans 并列,但它没有给出全面的概述:

JAXB vs Apache XMLBeans< /a>

除了这些天真的、先验的考虑之外,您是否有任何亲身经历可以支持使用除 JAXB 之外的任何其他绑定?我是从 CXF 的角度提问,但如果想到任何其他选项(例如 Castor),请毫不犹豫地详细说明。

I have been playing around with Apache CXF, in particular the various data bindings it supports: JAXB (the default), MTOM, Aegis and XMLBeans. Since all of these are supported, I suppose each has its merits. I came up with these:

  • Obviously, MTOM is to be preferred where large attachments are involved.
  • JAXB depends on annotations, so it is less suited when modification of classes is restricted.
  • Aegis has no wsdl2java tool, so it is less suited for "contract-first" development, i.e. start with a WSDL and generate your Java code from that.
  • It appears that Aegis provides slightly more control over the mapping between Java classes and XML through its declarative syntax in Class.aegis.xml files. On the other hand, I couldn't devise of any scenarios where JAXB did not do the trick.

I found this question juxtaposing JAXB and XMLBeans, but it doesn't give a comprehensive overview:

JAXB vs Apache XMLBeans

Besides these naive, a priori considerations, do you have any blood-and-guts experiences that would support the use of any other binding besides JAXB? I'm asking from a CXF point of view, but if any other options come to mind (e.g. Castor) please don't hesitate to elaborate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空宴 2024-09-24 09:12:31

如果从头开始创建第一个 WSDL Web 服务,那么我绝对会建议 95% 的时间(甚至更高)坚持使用 JAXB。它绝对是 CXF 中经过测试最好的数据绑定,并且性能非常好。

其他数据绑定通常适用于以下两种情况之一:

1) Java 第一个用例,您已经用 Java 编写了一些内容,您希望将其公开为 Web 服务,而无需对代码进行很少的修改或无需修改。 Aegis 在这方面有其优势,因为它的设计能够处理比 JAXB 更广泛的事务。但是,如果您可以修改代码,那么添加 JAXB 注释通常并不困难。如果你的大部分都是普通的“豆子”,那没什么大不了的。

2) 使用特定映射的现有应用程序。如果您现有的应用程序需要 XMLBeans beans(如果使用 CXF 的 2.3-SNAPSHOT,则需要 SDO beans;如果遵循 GSoC 项目,则需要 JiBX beans),那么使用其他数据绑定可以帮助删除从 JAXB 到这些对象模型的任何所需映射。

希望能有所帮助。

If starting from scratch to create a WSDL first web service, then I definitely would recommend sticking with JAXB 95% of the time (maybe even higher). It's definitely the best tested databinding in CXF and performs quite well.

Where the other databindings come in are usually for one of two cases:

1) Java first use cases where you have something already written in Java that you want to expose as a web service with little to no modifications to the code. Aegis has it's strengths here as it's designed to be able to handle a wider range of things than JAXB. However, if you CAN modify the code, adding JAXB annotations usually isn't that hard. If you have mostly normal "beans", it's not a big deal.

2) Existing applications that use a particular mapping. If you have exising applications that are expecting XMLBeans beans (or SDO beans if using 2.3-SNAPSHOT of CXF, or JiBX beans if following the GSoC project), then using the other databindings could help by removing any needed mappings from JAXB to those object models.

Hope that helps a little.

不离久伴 2024-09-24 09:12:31

请记住,JAXB 是一个规范,因此有多个实现:Metro(参考实现,MOXy(我是技术主管)等。

可以从 Java 类或 XML 模式开始使用 JAXB。如果您有无法修改单独 JAXB 的类实现提供了处理该问题的扩展:

JAXB 设计用于与 MTOM 附件配合使用,请参阅附件编组器/解组器,

MOXy 具有基于 XPath 的映射,可提供对对象到对象的完全控制 。 -XML绑定参见:

Remember that JAXB is a specification so there are multiple implementations: Metro (Reference Implementation, MOXy (I'm the tech lead), etc.

JAXB can be used starting from Java classes or XML schema. If you have classes that cannot be modified individual JAXB implmentations offer extensions to handle that. See MOXy's externalizable metadata:

JAXB was designed to work with MTOM attachments see the attachment marshaller/unmarshaller.

MOXy has XPath based mappings which offers full control of your object-to-XML binding see:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文