diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-09-14 16:45:06 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-09-14 16:45:17 +0100 |
commit | a65e4772f4557a109917532b2d9c49680ce3bb15 (patch) | |
tree | 1669786f0b3ce82e005debc53218825d537841c8 /client/client-full | |
parent | 6d72a4a1e5d8678ecd8b093480ea9543089015b0 (diff) |
Fix exception not logged or rethrown
Eclipse sonarlint does not check for exception dropping by default,
it must be configured. This commit addresses exception dropping in
apex.
Change-Id: I406838990b3424c2912124b25d7326502cacc96c
Issue-ID: POLICY-1034
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'client/client-full')
2 files changed, 34 insertions, 30 deletions
diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java index c89fcf473..b11cd7ff3 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java @@ -74,7 +74,7 @@ public class ApexServicesRestMain { final ApexServicesRestMain editorMain = new ApexServicesRestMain(args, System.out); editorMain.init(); } catch (final Exception e) { - LOGGER.error(e.getMessage()); + LOGGER.error("error starting REST client", e); } } @@ -95,9 +95,8 @@ public class ApexServicesRestMain { // Get and check the parameters parameters = parser.parse(args); } catch (final ApexServicesRestParameterException e) { - throw new ApexServicesRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' - + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); + throw new ApexServicesRestParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + + e.getMessage() + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()), e); } if (parameters.isHelpSet()) { @@ -108,8 +107,8 @@ public class ApexServicesRestMain { final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { throw new ApexServicesRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage - + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); + REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); } state = EditorState.READY; @@ -119,8 +118,8 @@ public class ApexServicesRestMain { * Initialize the Apex editor. */ public void init() { - outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " - + parameters.getBaseUri().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + + " . . ."); try { state = EditorState.INITIALIZING; @@ -135,7 +134,7 @@ public class ApexServicesRestMain { if (parameters.getTimeToLive() == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE) { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " - + parameters.getBaseUri().toString()); + + parameters.getBaseUri().toString()); } else { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } @@ -152,8 +151,9 @@ public class ApexServicesRestMain { Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT); } } catch (final Exception e) { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); + String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage(); + outStream.println(message); + LOGGER.warn(message, e); } finally { if (apexServices != null) { apexServices.shutdown(); @@ -181,7 +181,7 @@ public class ApexServicesRestMain { public String toString() { final StringBuilder ret = new StringBuilder(); ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=") - .append(this.getState()); + .append(this.getState()); return ret.toString(); } diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java index d7b7229c4..d0b374fd4 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java @@ -32,12 +32,17 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class ParameterCheck { + // Recurring string constants + private static final String PARAMETER = "parameter \""; + private static final String NOT_FOUND = "\" not found"; + private static final int MAX_PORT = 65535; /** * private constructor to prevent subclassing of this utility class. */ - private ParameterCheck() {} + private ParameterCheck() { + } /** * The Enum StartStop is used to hold. @@ -65,14 +70,14 @@ public final class ParameterCheck { */ public static String getHostName(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(HOSTNAME_PAR)) { - LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND); return null; } final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR); if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND); return null; } @@ -87,14 +92,14 @@ public final class ParameterCheck { */ public static int getPort(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(PORT_PAR)) { - LOGGER.warn("parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND); return -1; } final String[] portValue = parameterMap.get(PORT_PAR); if (portValue.length == 0 || portValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND); return -1; } @@ -102,13 +107,13 @@ public final class ParameterCheck { try { port = Integer.parseInt(portValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e); + LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid integer", portValue[0], e); return -1; } if (port <= 0 || port > MAX_PORT) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR - + "\" not a valid port between 0 and 65535"); + LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid port between 0 and 65535", + portValue[0]); return -1; } @@ -131,14 +136,14 @@ public final class ParameterCheck { } } if (artifactKeyParameter == null) { - LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found"); + LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND); return null; } final String[] axArtifactKeyArray = artifactKeyParameter.split("#"); if (axArtifactKeyArray.length != 2) { - LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid"); + LOGGER.warn("value \"{}\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid", artifactKeyParameter); return null; } @@ -153,17 +158,17 @@ public final class ParameterCheck { * @return the start stop */ public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap, - final AxArtifactKey engineKey) { + final AxArtifactKey engineKey) { final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId(); if (!parameterMap.containsKey(startStopPar)) { - LOGGER.warn("parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", startStopPar); return null; } final String[] startStopValue = parameterMap.get(startStopPar); if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", startStopPar); return null; } @@ -173,8 +178,7 @@ public final class ParameterCheck { } else if (startStopValue[0].equalsIgnoreCase("stop")) { startStop = ParameterCheck.StartStop.STOP; } else { - LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar - + "\" not \"start\" or \"stop\""); + LOGGER.warn("value \"{}\" of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar); return null; } @@ -190,21 +194,21 @@ public final class ParameterCheck { */ public static long getLong(final Map<String, String[]> parameterMap, final String longName) { if (!parameterMap.containsKey(longName)) { - LOGGER.warn("parameter \"" + longName + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", longName); return -1; } final String[] longValue = parameterMap.get(longName); if (longValue.length == 0 || longValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + longName + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", longName); return -1; } try { return Long.parseLong(longValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e); + LOGGER.warn("value \"{}\"of parameter \"{}\" not a valid long", longValue[0], longName, e); return -1; } } |