-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
private static Logger logger = LoggerFactory.getInstance().getLogger(IndexApi.class.getName());
private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(IndexApi.class.getName());
+ private static final String MSG_AUTHENTICATION_FAILURE = "Authentication failure.";
+
public AnalyzerApi(@Qualifier("searchServiceApi") SearchServiceApi searchService) {
this.searchService = searchService;
}
ApiUtils apiUtils) {
HttpStatus responseCode = HttpStatus.INTERNAL_SERVER_ERROR;
- String responseString = "Undefined error";
+ String responseString;
// Initialize the MDC Context for logging purposes.
ApiUtils.initMdcContext(request, headers);
if (!searchService.validateRequest(headers, request, ApiUtils.Action.GET,
ApiUtils.SEARCH_AUTH_POLICY_NAME)) {
- logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE, "Authentication failure.");
+ logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE, MSG_AUTHENTICATION_FAILURE);
return ResponseEntity.status(HttpStatus.FORBIDDEN).contentType(MediaType.APPLICATION_JSON)
- .body("Authentication failure.");
+ .body(MSG_AUTHENTICATION_FAILURE);
}
} catch (Exception e) {
logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE,
"Unexpected authentication failure - cause: " + e.getMessage());
return ResponseEntity.status(HttpStatus.FORBIDDEN).contentType(MediaType.APPLICATION_JSON)
- .body("Authentication failure.");
+ .body(MSG_AUTHENTICATION_FAILURE);
}
try {
responseString = buildAnalyzerList(ElasticSearchHttpController.getInstance().getAnalysisConfig());
responseCode = HttpStatus.OK;
-
} catch (Exception e) {
-
logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE,
"Unexpected failure retrieving analysis configuration - cause: " + e.getMessage());
responseString = "Failed to retrieve analysis configuration. Cause: " + e.getMessage();
}
// Build the HTTP response.
- ResponseEntity response =
+ ResponseEntity<String> response =
ResponseEntity.status(responseCode).contentType(MediaType.APPLICATION_JSON).body(responseString);
// Generate our audit log.
+ String unknownLogField = "Unknown";
auditLogger.info(SearchDbMsgs.PROCESS_REST_REQUEST,
new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, responseCode.value())
.setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, responseCode.value()),
- (request != null) ? request.getMethod() : "Unknown",
- (request != null) ? request.getRequestURL().toString() : "Unknown",
- (request != null) ? request.getRemoteHost() : "Unknown",
+ (request != null) ? request.getMethod() : unknownLogField,
+ (request != null) ? request.getRequestURL().toString() : unknownLogField,
+ (request != null) ? request.getRemoteHost() : unknownLogField,
Integer.toString(response.getStatusCodeValue()));
// Clear the MDC context so that no other transaction inadvertently
return response;
}
-
/**
* This method takes a list of analyzer objects and generates a simple json structure to enumerate them.
*