diff options
author | Parshad Patel <pars.patel@samsung.com> | 2019-03-22 12:22:24 +0900 |
---|---|---|
committer | Parshad Patel <pars.patel@samsung.com> | 2019-03-22 12:25:30 +0900 |
commit | 16b23d59fdcb63f8b0eec4821a551b0c4c3838d2 (patch) | |
tree | 174e73832d1bccee31f1089bf5fef9c97ab3e970 /src | |
parent | 06fbe5a7ac9bd39af6ebb1fe8c50a7220b3eb279 (diff) |
Fix sonar issues in messagerouter-messageservice
Fix use a logger to log this exception issue
Fix a "NullPointerException" could be thrown issue
Issue-ID: DMAAP-894
Change-Id: I8e6b5c3495a9a4ca93cba45b7c632708885249e0
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/onap/dmaap/service/MMRestService.java | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/src/main/java/org/onap/dmaap/service/MMRestService.java b/src/main/java/org/onap/dmaap/service/MMRestService.java index 4a2c908..c5874ae 100644 --- a/src/main/java/org/onap/dmaap/service/MMRestService.java +++ b/src/main/java/org/onap/dmaap/service/MMRestService.java @@ -425,8 +425,7 @@ public class MMRestService { } } catch (IOException e) { - - e.printStackTrace(); + LOGGER.error("Error in callUpdateMirrorMaker:", e); } } // Send error response if user does not provide Authorization @@ -495,9 +494,9 @@ public class MMRestService { inStream = IOUtils.toInputStream(jsonOb.toString(), "UTF-8"); } catch (IOException ioe) { - ioe.printStackTrace(); + LOGGER.error("Error while converting string to an input stream:", ioe); } - JSONObject deleteMM = (JSONObject) jsonOb.getJSONObject("deleteMirrorMaker"); + JSONObject deleteMM = jsonOb.getJSONObject("deleteMirrorMaker"); JSONObject existMirrorMaker = validateMMExists(ctx, deleteMM.getString("name")); @@ -523,7 +522,7 @@ public class MMRestService { } } catch (IOException ioe) { - + LOGGER.error("Error in callDeleteMirrorMaker:", ioe); throw ioe; } @@ -673,7 +672,7 @@ public class MMRestService { } } catch (Exception e) { - + LOGGER.error("Error in callPubSub", e); throw e; } @@ -765,7 +764,7 @@ public class MMRestService { inStream = IOUtils.toInputStream(listAll.toString(), "UTF-8"); } catch (IOException ioe) { - ioe.printStackTrace(); + LOGGER.error("Error while converting string to an input stream:", ioe); } JSONObject listMirrorMaker = new JSONObject(); listMirrorMaker = callPubSub(randomStr, ctx, inStream, null, true); @@ -839,8 +838,7 @@ public class MMRestService { } } catch (IOException e) { - - e.printStackTrace(); + LOGGER.error("Error in listWhiteList", e); } } else { ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, @@ -928,7 +926,7 @@ public class MMRestService { inStream = IOUtils.toInputStream(listAll.toString(), "UTF-8"); } catch (IOException ioe) { - ioe.printStackTrace(); + LOGGER.error("Error while converting string to an input stream:", ioe); } String msgFrmSubscribe = mirrorService.subscribe(ctx, topic, consumergroup, consumerid); // call listAllMirrorMaker @@ -1139,7 +1137,7 @@ public class MMRestService { inStream = IOUtils.toInputStream(listAll.toString(), "UTF-8"); } catch (IOException ioe) { - ioe.printStackTrace(); + LOGGER.error("Error while converting string to an input stream:", ioe); } // call listAllMirrorMaker mirrorService.pushEvents(ctx, topic, inStream, null, null); @@ -1329,18 +1327,21 @@ public class MMRestService { jsonArrayNamespace = jsonObj.getJSONArray("listMirrorMaker"); } } + JSONObject finalJasonObj = new JSONObject(); JSONArray finalJsonArray = new JSONArray(); - for (int i = 0; i < jsonArrayNamespace.length(); i++) { + if (jsonArrayNamespace != null) { + for (int i = 0; i < jsonArrayNamespace.length(); i++) { - JSONObject mmObj = new JSONObject(); - mmObj = jsonArrayNamespace.getJSONObject(i); - if (mmObj.has("name") && mmName.equals(mmObj.getString("name"))) { + JSONObject mmObj = new JSONObject(); + mmObj = jsonArrayNamespace.getJSONObject(i); + if (mmObj.has("name") && mmName.equals(mmObj.getString("name"))) { - finalJsonArray.put(mmObj); - } + finalJsonArray.put(mmObj); + } + } } finalJasonObj.put("listMirrorMaker", finalJsonArray); @@ -1358,7 +1359,7 @@ public class MMRestService { } } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Error in callPubSubForWhitelist:", e); } } @@ -1391,8 +1392,7 @@ public class MMRestService { listAll.put("listAllMirrorMaker", new JSONObject()); } catch (JSONException e) { - - e.printStackTrace(); + LOGGER.error("Error while creating a listAllMirrorMaker Json object:", e); } // set a random number as messageID @@ -1405,7 +1405,7 @@ public class MMRestService { inStream = IOUtils.toInputStream(listAll.toString(), "UTF-8"); } catch (IOException ioe) { - ioe.printStackTrace(); + LOGGER.error("Error while converting string to an input stream:", ioe); } JSONObject listMirrorMaker = new JSONObject(); listMirrorMaker = callPubSub(randomStr, ctx, inStream, name, false); @@ -1414,8 +1414,11 @@ public class MMRestService { return listMirrorMaker; } - listMirrorMaker.put("exists", false); - return listMirrorMaker; + if(null != listMirrorMaker) { + listMirrorMaker.put("exists", false); + } + + return listMirrorMaker; } } |