}
} catch (IOException e) {
-
- e.printStackTrace();
+ LOGGER.error("Error in callUpdateMirrorMaker:", e);
}
}
// Send error response if user does not provide Authorization
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"));
}
} catch (IOException ioe) {
-
+ LOGGER.error("Error in callDeleteMirrorMaker:", ioe);
throw ioe;
}
}
} catch (Exception e) {
-
+ LOGGER.error("Error in callPubSub", e);
throw e;
}
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);
}
} catch (IOException e) {
-
- e.printStackTrace();
+ LOGGER.error("Error in listWhiteList", e);
}
} else {
ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
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
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);
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);
}
} catch (Exception e) {
- e.printStackTrace();
+ LOGGER.error("Error in callPubSubForWhitelist:", e);
}
}
- private String getWhitelistByNamespace(String originalWhitelist, String namespace) {
-
- String whitelist = null;
- List<String> resultList = new ArrayList<>();
- List<String> whitelistList = new ArrayList<>();
- whitelistList = Arrays.asList(originalWhitelist.split(","));
-
- for (String topic : whitelistList) {
- if (StringUtils.isNotBlank(originalWhitelist) && getNamespace(topic).equals(namespace)) {
- resultList.add(topic);
- }
- }
- if (!resultList.isEmpty()) {
- whitelist = StringUtils.join(resultList, ",");
- }
-
- return whitelist;
- }
- private JSONArray getListMirrorMaker(String msgFrmSubscribe, String randomStr) {
- JSONObject jsonObj;
- JSONArray jsonArray;
+ public JSONArray getListMirrorMaker(String msgFrmSubscribe, String randomStr) {
+ JSONObject jsonObj = new JSONObject();
+ JSONArray jsonArray = new JSONArray();
JSONArray listMirrorMaker = new JSONArray();
-
+
msgFrmSubscribe = removeExtraChar(msgFrmSubscribe);
jsonArray = new JSONArray(msgFrmSubscribe);
-
+ jsonObj = jsonArray.getJSONObject(0);
+
for (int i = 0; i < jsonArray.length(); i++) {
jsonObj = jsonArray.getJSONObject(i);
-
- JSONObject obj = new JSONObject();
- if (jsonObj.has(MESSAGE)) {
- obj = jsonObj.getJSONObject(MESSAGE);
- }
- if (obj.has("messageID") && obj.get("messageID").equals(randomStr) && obj.has(LISTMIRRORMAKER)) {
- listMirrorMaker = obj.getJSONArray(LISTMIRRORMAKER);
+
+ if (jsonObj.has("messageID") && jsonObj.get("messageID").equals(randomStr) && jsonObj.has("listMirrorMaker")) {
+ listMirrorMaker = jsonObj.getJSONArray("listMirrorMaker");
break;
}
}
- return listMirrorMaker;
+ return listMirrorMaker;
}
+
public JSONObject validateMMExists(DMaaPContext ctx, String name) throws Exception {
// Create a listAllMirrorMaker Json object
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
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);
return listMirrorMaker;
}
- listMirrorMaker.put("exists", false);
- return listMirrorMaker;
+ if(null != listMirrorMaker) {
+ listMirrorMaker.put("exists", false);
+ }
+
+ return listMirrorMaker;
}
}