[jboss-user] [EJB3] - Re: Why application exceptions are wrapped in EJBException on AS 6.1?
goldm
do-not-reply at jboss.com
Thu Nov 10 03:45:18 EST 2011
goldm [http://community.jboss.org/people/goldm] created the discussion
"Re: Why application exceptions are wrapped in EJBException on AS 6.1?"
To view the discussion, visit: http://community.jboss.org/message/635878#635878
--------------------------------------------------------------
Hi,
yes, there is one. You can extend BMTTxInterceptorFactory and override method createPerJoinpoint. In returned instance of StatelessBMTInterceptor, override handleException method - check if ApplicationException annotation is present on exception class.
Something like this:
public class BMTTxInterceptorFactoryCustom extends BMTTxInterceptorFactory
{
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(BMTTxInterceptorFactoryCustom.class);
public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
{
// We have to do this until AOP supports matching based on annotation attributes
TransactionManagementType type = TxUtil.getTransactionManagementType(advisor);
if (type != TransactionManagementType.BEAN)
return new NullInterceptor();
TransactionManager tm = TxUtil.getTransactionManager();
boolean stateful = advisor.resolveAnnotation(Stateful.class) != null;
// Both MessageDriven and Stateless are stateless
if(stateful)
return new StatefulBMTInterceptor(tm);
else
return new StatelessBMTInterceptor(tm) {
protected void handleException(Invocation invocation, Exception ex) throws Exception {
if (ex == null)
{
return;
}
ApplicationException ae = (ApplicationException) invocation.getAdvisor().resolveAnnotation(ApplicationException.class);
// it's an application exception, so just throw it back as-is
if (ae != null || ex.getClass().isAnnotationPresent(ApplicationException.class))
{
throw ex;
}
if (ex instanceof EJBException)
{
throw (EJBException) ex;
}
else
{
throw new EJBException(ex);
}
}
};
}
}
Then you have to use BMTTxInterceptorFactoryCustom instead of BMTTxInterceptorFactory (configured in ejb3-interceptors-aop.xml and singleton-container-aop.xml)
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/635878#635878]
Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111110/5735eda5/attachment.html
More information about the jboss-user
mailing list