* @param e
* @return
*/
public SpagoBIEngineServiceException getWrappedException(String serviceName, Throwable e) {
SpagoBIServiceException serviceException = null;
MessageBuilder msgBuild = new MessageBuilder();
Locale locale = null;
RequestContainer requestContainer=RequestContainer.getRequestContainer();
if(requestContainer!=null){
SessionContainer permSess=requestContainer.getSessionContainer().getPermanentContainer();
String lang=(String)permSess.getAttribute(SpagoBIConstants.AF_LANGUAGE);
String country=(String)permSess.getAttribute(SpagoBIConstants.AF_COUNTRY);
if(lang!=null && country!=null){
locale=new Locale(lang,country,"");
}
}else{
locale = GeneralUtilities.getDefaultLocale();
}
if(e instanceof SpagoBIServiceException) {
// this mean that the service have catched the exception nicely
serviceException = (SpagoBIServiceException)e;
String sms = serviceException.getMessage();
sms = msgBuild.getMessage(sms, locale);
serviceException = new SpagoBIServiceException(serviceName, sms, e);
} else {
// otherwise an unpredicted exception has been raised.
// This is the last line of defense against exceptions. Bytheway all exceptions that are catched
// only here for the first time can be considered as bugs in the exception handling mechanism. When
// such an exception is raised the code in the service should be fixed in order to catch it before and add some meaningfull
// informations on what have caused it.
Throwable rootException = e;
while(rootException.getCause() != null) {
rootException = rootException.getCause();
}
String str = rootException.getMessage()!=null? rootException.getMessage(): rootException.getClass().getName();
str = msgBuild.getMessage(str, locale);
String message = "An unpredicted error occurred while executing service."
+ "\nThe root cause of the error is: " + str;
serviceException = new SpagoBIServiceException(serviceName, message, e);