- JSONObject jsonObject = new JSONObject(formattedString);
- switch (dmaapMessage.getOperation()) {
- case "getPolicySchemas":
- ricName = (String) jsonObject.get("ricName");
- logger.debug("Received the request for getPolicySchemas with Ric Name- {}", ricName);
- return policyController.getPolicySchemas(ricName);
- case "getPolicySchema":
- String policyTypeId = (String) jsonObject.get("id");
- logger.debug("Received the request for getPolicySchema with Policy Type Id- {}", policyTypeId);
- System.out.println("policyTypeId" + policyTypeId);
- return policyController.getPolicySchema(policyTypeId);
- case "getPolicyTypes":
- ricName = (String) jsonObject.get("ricName");
- logger.debug("Received the request for getPolicyTypes with Ric Name- {}", ricName);
- return policyController.getPolicyTypes(ricName);
- case "getPolicy":
- instance = (String) jsonObject.get("instance");
- logger.debug("Received the request for getPolicy with Instance- {}", instance);
- return policyController.getPolicy(instance);
- case "deletePolicy":
- instance = (String) jsonObject.get("instance");
- logger.debug("Received the request for deletePolicy with Instance- {}", instance);
- return null;// policyController.deletePolicy(deleteInstance);
- case "putPolicy":
- String type = (String) jsonObject.get("type");
- String putPolicyInstance = (String) jsonObject.get("instance");
- String putPolicyRic = (String) jsonObject.get("ric");
- String service = (String) jsonObject.get("service");
- String jsonBody = (String) jsonObject.get("jsonBody");
- return null;// policyController.putPolicy(type, putPolicyInstance, putPolicyRic, service, jsonBody);
- case "getPolicies":
- String getPolicyType = (String) jsonObject.get("type");
- String getPolicyRic = (String) jsonObject.get("ric");
- String getPolicyService = (String) jsonObject.get("service");
- return policyController.getPolicies(getPolicyType, getPolicyRic, getPolicyService);
- default:
- break;
+ }
+
+ private Mono<ResponseEntity<String>> handleAgentCallError(Throwable error,
+ DmaapRequestMessage dmaapRequestMessage) {
+ logger.debug("Agent call failed: {}", error.getMessage());
+ HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
+ String errorMessage = error.getMessage();
+ if (error instanceof WebClientResponseException) {
+ WebClientResponseException exception = (WebClientResponseException) error;
+ status = exception.getStatusCode();
+ errorMessage = exception.getResponseBodyAsString();
+ } else if (error instanceof ServiceException) {
+ status = HttpStatus.BAD_REQUEST;
+ errorMessage = error.getMessage();
+ } else if (!(error instanceof WebClientException)) {
+ logger.warn("Unexpected exception ", error);