最後,基於前面的回答和我個人的研究,我保留了如下因素的解決方案。
我創建了專門用於管理服務器故障的攔截:
public class FaultBarrierInterceptor {
@AroundInvoke
public Object intercept(final InvocationContext invocationContext) throws Exception {
try {
return invocationContext.proceed();
} catch (final RuntimeException e) {
final Logger logger = Logger.getLogger(invocationContext.getMethod().getDeclaringClass());
logger.error("A fault occured during service invocation:" +
"\n-METHOD: " + invocationContext.getMethod() +
"\n-PARAMS: " + Arrays.toString(invocationContext.getParameters()), e);
throw new TechnicalException();
}
}}
拋出的異常的技術延伸EJBException的和不公開的原因的RuntimeException:
public class TechnicalException extends EJBException {}
我使用這個攔截所有公共服務:
@Stateless
@Interceptors({FaultBarrierInterceptor.class})
public class ShoppingCardServicesBean implements ShoppingCardServices { ...
這是一個implementationatio n的Fault Barrier pattern。
捕獲,記錄任何運行時異常並使用TechnicalException向客戶端發送故障(沒有內部詳細信息)。檢查的異常被忽略。
RuntimeException處理是集中的,並與任何業務方法分開。