diff options
author | Endi S. Dewata <edewata@redhat.com> | 2015-01-20 09:25:32 -0500 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2015-01-21 15:35:37 -0500 |
commit | 802f7471d5ee65e3c4d99b528bb6d8526c277185 (patch) | |
tree | 02dd03d41e301499b0b28fbd0af948f253bac03d /base/server | |
parent | deb188bffd38f82396c47411381a875020ca748b (diff) | |
download | pki-802f7471d5ee65e3c4d99b528bb6d8526c277185.tar.gz pki-802f7471d5ee65e3c4d99b528bb6d8526c277185.tar.xz pki-802f7471d5ee65e3c4d99b528bb6d8526c277185.zip |
Added support for exception chains in EBaseException.
The EBaseException has been modified to provide constructors that
can be used to chain the cause of the exception. This way the root
cause of the exception can be traced back to help troubleshooting.
Some codes have been modified to utilize the proper exception
chaining as examples.
https://fedorahosted.org/pki/ticket/915
Diffstat (limited to 'base/server')
3 files changed, 25 insertions, 16 deletions
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java index 47048c31a..a594dad05 100644 --- a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java +++ b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java @@ -174,7 +174,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou cs.commit(false); } catch (EBaseException e) { CMS.debug(e); - throw new PKIException("Unable to commit config parameters to file"); + throw new PKIException("Unable to commit config parameters to file", e); } initializeDatabase(data); @@ -200,8 +200,8 @@ public class SystemConfigService extends PKIService implements SystemConfigResou ConfigurationUtils.setCertPermissions(cert.getCertTag()); CMS.debug("Processed '" + cert.getCertTag() + "' certificate."); } catch (Exception e) { - e.printStackTrace(); - throw new PKIException("Error in configuring system certificates" + e); + CMS.debug(e); + throw new PKIException("Error in configuring system certificates" + e, e); } if (ret != 0) { throw new PKIException("Error in configuring system certificates"); @@ -234,8 +234,8 @@ public class SystemConfigService extends PKIService implements SystemConfigResou try { ConfigurationUtils.removePreopConfigEntries(); } catch (EBaseException e) { - e.printStackTrace(); - throw new PKIException("Errors when removing preop config entries: " + e); + CMS.debug(e); + throw new PKIException("Errors when removing preop config entries: " + e, e); } // Create an empty file that designates the fact that although @@ -915,8 +915,8 @@ public class SystemConfigService extends PKIService implements SystemConfigResou cs.putString("securitydomain.host", host); cs.putInteger("securitydomain.httpsadminport",port); } catch (Exception e) { - e.printStackTrace(); - throw new PKIException("Failed to resolve security domain URL"); + CMS.debug(e); + throw new PKIException("Failed to resolve security domain URL", e); } getCertChainFromSecurityDomain(host, port); @@ -957,8 +957,8 @@ public class SystemConfigService extends PKIService implements SystemConfigResou try { installToken = ConfigurationUtils.getInstallToken(host, port, user, pass); } catch (Exception e) { - e.printStackTrace(); - throw new PKIException("Failed to obtain installation token from security domain: " + e); + CMS.debug(e); + throw new PKIException("Failed to obtain installation token from security domain: " + e, e); } if (installToken == null) { diff --git a/base/server/cmscore/src/com/netscape/cmscore/authentication/AuthSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/authentication/AuthSubsystem.java index 549ce01f9..137edb5c5 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/authentication/AuthSubsystem.java +++ b/base/server/cmscore/src/com/netscape/cmscore/authentication/AuthSubsystem.java @@ -219,21 +219,26 @@ public class AuthSubsystem implements IAuthSubsystem { isEnable = true; log(ILogger.LL_INFO, CMS.getLogMessage("CMSCORE_AUTH_ADD_AUTH_INSTANCE", insName)); + } catch (ClassNotFoundException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_AUTHSUB_ERROR", e.toString())); - throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className)); + throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className), e); + } catch (IllegalAccessException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_AUTHSUB_ERROR", e.toString())); - throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className)); + throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className), e); + } catch (InstantiationException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_AUTHSUB_ERROR", e.toString())); - throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className)); + throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className), e); + } catch (EBaseException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_AUTH_INIT_ERROR", insName, e.toString())); // Skip the authenticaiton instance if // it is mis-configurated. This give // administrator another chance to // fix the problem via console + } catch (Throwable e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_AUTH_INIT_ERROR", insName, e.toString())); // Skip the authenticaiton instance if @@ -330,15 +335,18 @@ public class AuthSubsystem implements IAuthSubsystem { authMgrInst = (IAuthManager) Class.forName(className).newInstance(); return (authMgrInst.getConfigParams()); + } catch (InstantiationException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_INSTANCE_NOT_CREATED", e.toString())); - throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className)); + + throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className), e); } catch (ClassNotFoundException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_INSTANCE_NOT_CREATED", e.toString())); - throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className)); + throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className), e); + } catch (IllegalAccessException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_AUTH_INSTANCE_NOT_CREATED", e.toString())); - throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className)); + throw new EAuthException(CMS.getUserMessage("CMS_ACL_CLASS_LOAD_FAIL", className), e); } } diff --git a/base/server/cmscore/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java b/base/server/cmscore/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java index f5bde0b54..11b6104bf 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java +++ b/base/server/cmscore/src/com/netscape/cmscore/authentication/ChallengePhraseAuthentication.java @@ -103,8 +103,9 @@ public class ChallengePhraseAuthentication implements IAuthManager { try { mSHADigest = MessageDigest.getInstance("SHA1"); + } catch (NoSuchAlgorithmException e) { - throw new EAuthException(CMS.getUserMessage("CMS_AUTHENTICATION_INTERNAL_ERROR", e.getMessage())); + throw new EAuthException(CMS.getUserMessage("CMS_AUTHENTICATION_INTERNAL_ERROR", e.getMessage()), e); } log(ILogger.LL_INFO, CMS.getLogMessage("INIT_DONE", name)); |