aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-editor
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-09-14 16:45:06 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-09-14 16:45:17 +0100
commita65e4772f4557a109917532b2d9c49680ce3bb15 (patch)
tree1669786f0b3ce82e005debc53218825d537841c8 /client/client-editor
parent6d72a4a1e5d8678ecd8b093480ea9543089015b0 (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-editor')
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java23
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java10
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java1
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java9
4 files changed, 27 insertions, 16 deletions
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
index 3f54467cd..ea4f206ce 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
@@ -95,9 +95,8 @@ public class ApexEditorMain {
// Get and check the parameters
parameters = parser.parse(args);
} catch (final ApexEditorParameterException e) {
- throw new ApexEditorParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n'
- + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, "
+ + e.getMessage() + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()), e);
}
if (parameters.isHelpSet()) {
@@ -107,9 +106,8 @@ public class ApexEditorMain {
// Validate the parameters
final String validationMessage = parameters.validate();
if (validationMessage.length() > 0) {
- throw new ApexEditorParameterException(
- REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage
- + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, "
+ + validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()));
}
state = EditorState.READY;
@@ -119,8 +117,8 @@ public class ApexEditorMain {
* 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 +133,7 @@ public class ApexEditorMain {
if (parameters.getTimeToLive() == ApexEditorParameters.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 +150,9 @@ public class ApexEditorMain {
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 (apexEditor != null) {
apexEditor.shutdown();
@@ -181,7 +180,7 @@ public class ApexEditorMain {
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-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
index 55d10c1a1..5c0c5eb7c 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
@@ -23,12 +23,18 @@ package org.onap.policy.apex.client.editor.rest;
import java.net.URI;
import java.net.URISyntaxException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
/**
* This class reads and handles command line parameters to the Apex CLI editor.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexEditorParameters {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorParameters.class);
+
/** The default port for connecting to the Web editor on. */
public static final int DEFAULT_REST_PORT = 18989;
@@ -120,7 +126,9 @@ public class ApexEditorParameters {
new URI(getBaseUri().toString()).parseServerAuthority();
return "";
} catch (final URISyntaxException e) {
- return "listen address is not valid. " + e.getMessage() + "\n";
+ String message = "listen address is not valid. " + e.getMessage() + "\n";
+ LOGGER.warn(message, e);
+ return message;
}
}
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
index 8bed63d28..72c294169 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
@@ -2000,6 +2000,7 @@ public class ApexEditorRestResource {
objecttochange.addProperty(DESCRIPTION, desc);
augmessages.add(gson.toJson(jsonObject));
} catch (final Exception e) {
+ LOGGER.debug("error adding key information", e);
augmessages.add(message);
}
}
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java
index b2222f827..c3f249fb4 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java
@@ -27,6 +27,9 @@ import java.lang.reflect.Method;
* The base class for Beans.
*/
public abstract class BeanBase {
+ // Recurring string constants
+ private static final String PROBLEM_RETRIEVING_FIELD_PREFIX = "Problem retrieving field called ('";
+ private static final String JSON_BEAN_SUFFIX = "') from JSON bean ";
/**
* Gets a named field from the bean.
@@ -44,7 +47,7 @@ public abstract class BeanBase {
return (String) method.invoke(this);
} catch (final Exception e) {
throw new IllegalArgumentException(
- "Problem retrieving field called ('" + field + "') from JSON bean " + this, e);
+ PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
}
}
}
@@ -59,9 +62,9 @@ public abstract class BeanBase {
}
} catch (final Exception e) {
throw new IllegalArgumentException(
- "Problem retrieving field called ('" + field + "') from JSON bean " + this, e);
+ PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
}
}
- throw new IllegalArgumentException("Problem retrieving field called ('" + field + "') from JSON bean " + this);
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this);
}
}