事务回滚和Web服务 [英] Transaction rollback and web services

查看:127
本文介绍了事务回滚和Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个从会话bean调用两个Web服务方法的例子,如果在两个方法的调用之间抛出异常怎么办?在不调用Web服务的情况下,事务将回滚并且不会造成任何伤害。但是,Web服务不会回滚。当然,即使使用单个Web服务也存在问题。虽然这是一个通用问题,但我对与EJB会话bean有关的解决方案感兴趣。

Given an example of calling two web services methods from a session bean, what if an exception is thrown between the calls to two methods? In the case of not calling the web services the transaction will rollback and no harm done. However, the web service will not rollback. Of course, even with a single web service there is a problem. While this is a generic question I am interested in solutions having to do with EJB session beans.

一个简单而自定义的答案将是添加一个特殊的回滚方法每个实功能方法的Web服务。我要求的是一些标准化的方法。

An easy and customized answer would be to add a special "rollback method" to the web service for each "real functionality" method. What I am asking for is some standardized way to do so.

推荐答案

一些技术正在发展,但问题仍然是标准化流程还没有为我们提供完全可移植的解决方案的充分前沿。

A number of techniques are evolving, but the problem is still sufficiently cutting edge that the standardization process has not yet provided us with a totally portable solution.

选项一,您可以使Web服务事务感知到。这当然是假定您有权控制,但在某些情况下,为非事务性服务编写事务感知代理也是一种选择。

Option one, you can make the web services transaction aware. This of course assumes you have control over them, although writing a transaction aware proxy for non-transactional services is also an option in some cases.

WS-AT和WS -BA协议是事务性Web服务的主要标准。不幸的是,他们只指定协议,而不是语言绑定。换句话说,在编程语言层面上没有标准的API。对于Java来说,最接近的是JSR-156,但还没有准备好。

The WS-AT and WS-BA protocols are the leading standards for transactional web services. Unfortunately they specify the protocol only, not the language bindings. In other words, there is no standard API at the programming language level. For Java the nearest thing is JSR-156, but it's not ready yet.

然后问题变成:如何将EJB(即JTA / XA)事务绑定到WS一。由于WS-AT和XA协议使用的模型密切相关,因此可以通过协议桥来实现。几个应用服务器提供这些线路。 JBoss在JavaOne上展示了他们的内容 - 请参阅 http: //anonsvn.jboss.org/repos/labs/labs/jbosstm/workspace/jhalliday/txbridge/BOF-4182.odp

Then the problem becomes: how to tie the EJB (i.e. JTA/XA) transaction to the WS one. Since the models used by the WS-AT and XA protocols are closely related, this can be achieved by means of a protocol bridge. Several app servers provide something alone these lines. JBoss presented theirs at JavaOne - see http://anonsvn.jboss.org/repos/labs/labs/jbosstm/workspace/jhalliday/txbridge/BOF-4182.odp

请注意,协议桥接技术也可以以其他方式使用,以允许使用eg的EJB一个XA数据库后端,作为事务Web服务公开。

Note that the protocol bridging technique can also be used the other way around, to allow an EJB that uses e.g. an XA database backend, to be exposed as a transactional web service.

但是,两阶段提交事务所使用的锁定模式真的只适用于相同的控制领域。如果您的服务在同一家公司的数据中心运行,您可能会逃避。对于更广泛的分发,无论是地理还是行政,您可能想要查看专门为此类使用而设计的Web服务交易协议WS-BA。

However, the locking model used by two phase commit transactions is really only suitable for short lived transactions in the same domain of control. If your services run in the same company datacenter you'll probably get away with it. For wider distribution, be it geographical or administrative, you probably want to look at WS-BA, a web service transactions protocol specifically designed for such use.

WS-BA使用基于薪酬的模式更难编程。它基本上是基于你提到的技术:通过调用补偿方法来消除服务方法的效果。这可能是非常困难的,但JBoss的实习生做了一个相当不错的注释框架,允许您以最小的努力定义补偿方法,并使它们自动启动。它不是标准化的,但如果您选择这种方法,请非常值得: http:// www。 jboss.org/jbosstm/baframework

WS-BA uses a compensation based model that is harder to program. It's essentially based on the technique you mention: the effect of service methods is undone by calling a compensation method. This can be tricky to get right, but a JBoss intern did a rather nice annotation framework that allows you to define compensation methods with minimal effort and have them driven automatically. It's not standardized, but well worth checking out if you choose this approach: http://www.jboss.org/jbosstm/baframework

这篇关于事务回滚和Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆