users@jersey.java.net

Re: [Jersey] transaction-per-request

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 16 Apr 2010 15:53:39 +0200

HI Adam,

To be honest i cannot recall all that discussion :-) need to go
through it again.

Filters are not appropriate to perform rolllback because the chain can
be bypassed or broken by the throwing of an exception. But a request
filter could add a Closeable that is guaranteed to get called. IIRC
Martin had a particular requirement related to throwing of exceptions
and rollback. It is now possible to obtain the mapped exception from
ContainerResponse:

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/container/ContainerResponse.html
#getMappedThrowable%28%29

but i do not know if that satisfies his needs.


To help me get up to speed can you tell me what your ideal solution
might look like and using CloseableService does not work for you?

Paul.

On Apr 15, 2010, at 7:08 PM, Adam Rabung wrote:

> Hello,
> I am trying to cleanly implement "transaction-per-request" alongside
> Jersey Resources. That is, I'd like no mention of transactions in
> individual resources, but rather in a central place, as outlined by
> Martin Probst in an earlier email [1]:
>
> try {
> chain.doFilter(request, response);
> commitSession();
> } finally {
> rollbackSession(); // no-op if already committed
> closeSession();
> }
>
> I've seen a few conversations about this topic on the mailing list,
> but I can't piece together a good solution using the advice. I'd
> rather avoid Spring for tx management, as it's not yet a dependency.
> I've taken a look at CloseableService, ResourceFilter, overriding
> ServletContainer.service, etc, and cannot see how I can use these to
> implement transparent rollback-on-exception. I got it working by
> calling rollback in a custom ExceptionMapper, but that feels very
> dirty :)
>
> If anyone has pulled this off, could they offer some pseudocode
> describing the approach? Extra bonus points if the solution gives me
> metadata on what resource is being executed :)
>
> Thank you,
> Adam
>
> [1] http://markmail.org/thread/aefgmci6r2thkqxc
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>