| Randy Schnier 2005-12-13, 6:01 pm |
| This was resolved offline. Since RoutingSessionEJB started the
transaction, by default the EJB container must throw a RemoteException
back to RoutingSessionEJB's caller if this transaction is rolled back
for any reason. This will be either the exception thrown by
BusinessServiceSessionEJB (if it throws one) wrapped in a
RemoteException, or a javax.transaction.TransactionRolledbackException
(if BusinessServiceSessionEJB doesn't throw any exceptions of its own).
If RoutingSessionEJB doesn't want the container to throw a
RemoteException even if the transaction that bean started is rolled
back, it must explicitly call sessionContext.setRollbackOnly() before
returning -- even if setRollbackOnly() was already called by a different
EJB somewhere up in the callpath. (The container only knows that the
transaction was rolled back for some reason, not necessarily that it was
rolled back because of a setRollbackOnly() call.)
The requirement for the starter of the tran to call setRollbackOnly() in
order to suppress the throwing of a TransactionRolledbackException is
defined in the EJB standard specs. The change between 5.1.1 and 6.0.2
was made to better comply with the official specs.
bwall3@gmail.com wrote:
> I don't want the AppServer to throw a CSITransactionRolledbackException. I expect to catch the application exception, rollback the txn then convert the exception to a message to be handled by my UI.
>
> The container is throwing a CSITransactionRolledbackException when I don't expect it to - I've dealt with it already.
>
> steps:
>
> 1) servlet receives http request
> 2) servlet makes call to RoutingSessionEJB
> 3) RoutingSessionEJB looks up BusinessServiceSessionEJB
> 4) RoutingSessionEJB makes call to the BusinessServiceSessionEJB
> 5) Exception thrown and caught by BusinessServiceSessionEJB
> 6) BusinessServiceSessionEJB calls sessionContext.setRollbackOnly()
> 7) BusinessServiceSessionEJB throws Exception
> 8) Exception caught by RoutingSessionEJB
> 9) Exception converted to Vector
> 10) RoutingSessionEJB makes call to Audit service (***I wonder has it a problem with this because it expects the txn to have finished - although there is no ejb call in the service**)
> 11) Vector returned from method on RoutingSessionEJB
>
> stepping threw this code it all executes as expected
>
> 12) somewhere in the Stub processRequest method for the RoutingSessionEJB a RemoteException is thrown
>
>
> //Servlet
>
> try {
>
> RouterHome home = (RouterHome) lookup...
> Router router = home.create();
> 2) return router.processRequest(obj);
>
> } catch (RemoteException re) {
> exception is CSITransactionRolledbackException
> }
>
> //RouterBean
> public Vector processRequest(Vector request) {
>
> Vector response = null;
> try {
>
> 3) CustomerSearchHome home = (CustomerSearchHome) Server.lookup...
> CustomerSearch customerSearch = home.create();
> 4) return customerSearch.processRequest(obj);
>
> } catch (ApplicationException ae) {
> //exception is caught here
> //log it and convert to vector
> 8 & 9)response = //converted exception
>
> } finally {
>
> 10) AuditUtils.audit(request, response);
> }
> 11) return response;
> }
>
>
> //CustomerSearchSessionEJB
> public Vector processRequest(Request obj) throws ApplicationException {
>
> Vector response = null;
> try {
>
> process.....
>
> 5) }catch (ApplicationException eex) {
> 6) sessionContext.setRollbackOnly();
> 7) throw new ApplicationException(eex)
> }
> return response;
> }
>
|