use of gov.cms.ab2d.eventlogger.events.ApiResponseEvent in project ab2d by CMSgov.
the class ErrorHandler method handleInvalidContractErrors.
@ExceptionHandler({ InvalidContractException.class })
public ResponseEntity<Void> handleInvalidContractErrors(Exception ex, HttpServletRequest request) {
HttpStatus status = getErrorResponse(ex.getClass());
String description = API_INVALID_CONTRACT + " " + getRootCause(ex);
eventLogger.log(new ErrorEvent(MDC.get(ORGANIZATION), null, ErrorEvent.ErrorType.UNAUTHORIZED_CONTRACT, description));
ApiResponseEvent responseEvent = new ApiResponseEvent(MDC.get(ORGANIZATION), null, status, "API Error", description, (String) request.getAttribute(REQUEST_ID));
eventLogger.logAndAlert(responseEvent, Ab2dEnvironment.PROD_LIST);
return new ResponseEntity<>(null, null, status);
}
use of gov.cms.ab2d.eventlogger.events.ApiResponseEvent in project ab2d by CMSgov.
the class ErrorHandler method generateFHIRError.
private ResponseEntity<JsonNode> generateFHIRError(Exception e, HttpHeaders httpHeaders, HttpServletRequest request) throws IOException {
String msg = getRootCause(e);
HttpStatus httpStatus = getErrorResponse(e.getClass());
FhirVersion version = FhirVersion.fromAB2DUrl(request.getRequestURI());
IBaseResource operationOutcome = version.getErrorOutcome(msg);
String encoded = version.outcomePrettyToJSON(operationOutcome);
// Log so that Splunk can pick this up and alert
log.warn("{} {}", ExceptionUtils.getRootCause(e).getClass(), msg);
eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), null, ErrorHandler.getErrorResponse(e.getClass()), "FHIR Error", msg, (String) request.getAttribute(REQUEST_ID)));
return new ResponseEntity<>(new ObjectMapper().readTree(encoded), httpHeaders, httpStatus);
}
use of gov.cms.ab2d.eventlogger.events.ApiResponseEvent in project ab2d by CMSgov.
the class ApiCommon method returnStatusForJobCreation.
public ResponseEntity<Void> returnStatusForJobCreation(String jobGuid, String apiPrefix, String requestId, HttpServletRequest request) {
String statusURL = getUrl(apiPrefix + FHIR_PREFIX + "/Job/" + jobGuid + "/$status", request);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(CONTENT_LOCATION, statusURL);
eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), jobGuid, HttpStatus.ACCEPTED, "Job Created", "Job " + jobGuid + " was created", requestId));
return new ResponseEntity<>(null, responseHeaders, HttpStatus.ACCEPTED);
}
use of gov.cms.ab2d.eventlogger.events.ApiResponseEvent in project ab2d by CMSgov.
the class AuthenticationTests method testClientNoAuthorization.
@Test
public void testClientNoAuthorization() throws Exception {
PdpClient pdpClient = pdpClientRepository.findByClientId(TEST_PDP_CLIENT);
pdpClient.setRoles(Collections.emptySet());
pdpClientRepository.save(pdpClient);
this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + "/Patient/$export").header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(403));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(1, apiRequestEvents.size());
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(1, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
assertEquals(HttpStatus.FORBIDDEN.value(), responseEvent.getResponseCode());
assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
}
use of gov.cms.ab2d.eventlogger.events.ApiResponseEvent in project ab2d by CMSgov.
the class AuthenticationTests method testClientDoesNotExist.
@Test
public void testClientDoesNotExist() throws Exception {
PdpClient pdpClient = pdpClientRepository.findByClientId(TEST_PDP_CLIENT);
pdpClientRepository.delete(pdpClient);
this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + "/Patient/$export").header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(403));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(1, apiRequestEvents.size());
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(1, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
assertEquals(HttpStatus.FORBIDDEN.value(), responseEvent.getResponseCode());
assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
}
Aggregations