I'd like to implement transaction-per-request in conjunction with Jersey resources. By that, I just mean I want a single place to manage transactions, something like:
try {
chain.doFilter(request, response);
commitSession();
} finally {
rollbackSession(); // no-op if already committed
closeSession();
}
In the past, I've done similar things with Servlet Filters, but that won't work in Jersey. In Jersey , the exception is intercepted and converted into a 500 long before web container Filters regain control. I suppose I could stick w/ the Filter approach, and check response codes, but that's not very appealing. I've seen a couple conversations about this, but I've been unable to come up with a solid approach using ResourceFilter, CloseableService, or ServletContainer, etc. My terrible solution so far has been to do implement a custom ExceptionMapper and perform a rollback there. Has anyone solved this cleanly?
Disclaimer - this project currently doesn't use Spring, so I'd rather avoid it for this small use case.