diff options
Diffstat (limited to 'base')
5 files changed, 76 insertions, 39 deletions
diff --git a/base/common/src/com/netscape/certsrv/apps/CMS.java b/base/common/src/com/netscape/certsrv/apps/CMS.java index 63c1a2cbd..8b4bac2c0 100644 --- a/base/common/src/com/netscape/certsrv/apps/CMS.java +++ b/base/common/src/com/netscape/certsrv/apps/CMS.java @@ -17,8 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.apps; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; import java.math.BigInteger; import java.security.NoSuchAlgorithmException; import java.security.cert.Certificate; @@ -1586,21 +1584,19 @@ public final class CMS { CMS.startup(); } catch (EBaseException e) { // catch everything here purposely - CMS.debug("CMS:Caught EBaseException"); CMS.debug(e); // Raidzilla Bug #57592: Always print error message to stdout. - System.out.println(e.toString()); + System.out.println(e); shutdown(); throw e; - } catch (Exception e) { // catch everything here purposely - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintStream ps = new PrintStream(bos); - e.printStackTrace(ps); + } catch (Exception e) { // catch everything here purposely + CMS.debug(e); System.out.println(Constants.SERVER_SHUTDOWN_MESSAGE); - throw new EBaseException(bos.toString()); + + throw new EBaseException(e); // cms.shutdown(); } } diff --git a/base/common/src/com/netscape/certsrv/base/EBaseException.java b/base/common/src/com/netscape/certsrv/base/EBaseException.java index 140a6acbc..78d9a6d2d 100644 --- a/base/common/src/com/netscape/certsrv/base/EBaseException.java +++ b/base/common/src/com/netscape/certsrv/base/EBaseException.java @@ -63,25 +63,24 @@ public class EBaseException extends Exception { } /** - * Constructs an instance of the exception given the resource key and - * a exception parameter. + * Constructs an instance of this exception given the resource key and + * the cause exception. * - * <PRE> - * try { - * ... - * } catch (IOExeption e) { - * throw new EBaseException(BaseResources.INTERNAL_ERROR_1, e); - * } - * </PRE> - * <P> + * <pre> + * try { + * ... + * } catch (IOExeption e) { + * throw new EBaseException(BaseResources.INTERNAL_ERROR_1, e); + * } + * </pre> * * @param msgFormat The resource key - * @param param The parameter as an exception + * @param cause The cause exception */ - public EBaseException(String msgFormat, Exception param) { - super(msgFormat); + public EBaseException(String msgFormat, Exception cause) { + super(msgFormat, cause); mParams = new Exception[1]; - mParams[0] = param; + mParams[0] = cause; } /** @@ -98,6 +97,39 @@ public class EBaseException extends Exception { } /** + * Constructs an instance of this exception given the resource key, + * an array of parameters, and the cause exception. + * <P> + * + * @param msgFormat The resource key + * @param params Array of params + * @param cause The cause exception + */ + public EBaseException(String msgFormat, Object params[], Exception cause) { + super(msgFormat, cause); + mParams = params; + } + + /** + * Constructs an instance of this exception given the cause exception. + * + * <pre> + * try { + * ... + * } catch (IOExeption e) { + * throw new EBaseException(e); + * } + * </pre> + * + * @param cause The cause exception + */ + public EBaseException(Exception cause) { + super(cause.getMessage() == null ? cause.getClass().getName() : cause.getMessage(), cause); + mParams = new Exception[1]; + mParams[0] = cause; + } + + /** * Returns the list of parameters. * <P> * 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)); |