use of uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException in project integration-adaptor-111 by nhsconnect.
the class ReportController method postReport.
@PostMapping(value = "/report", consumes = { APPLICATION_XML_VALUE, TEXT_XML_VALUE }, produces = TEXT_XML_VALUE)
@ResponseStatus(value = ACCEPTED)
public ResponseEntity<String> postReport(@RequestBody String reportXml) {
String toAddress = null;
String messageId;
try {
ReportItems reportItems = reportParserUtil.parseReportXml(reportXml);
itkValidator.checkItkConformance(reportItems);
soapValidator.checkSoapItkConformance(reportItems.getSoapHeader());
itkAddressValidator.checkItkOdsAndDosId(reportItems.getItkHeader());
ItkReportHeader headerValues = headerParserUtil.getHeaderValues(reportItems.getItkHeader());
toAddress = getValueOrDefaultAddress(reportItems.getSoapAddress());
LOGGER.info("ITK SOAP message received. MessageId: {}, ItkTrackingId: {}", reportItems.getMessageId(), headerValues.getTrackingId());
DistributionEnvelopeDocument distributionEnvelope = reportRequestUtils.extractDistributionEnvelope(reportItems.getDistributionEnvelope());
validate(distributionEnvelope);
POCDMT000002UK01ClinicalDocument1 clinicalDocument = reportRequestUtils.extractClinicalDocument(distributionEnvelope);
validate(clinicalDocument);
encounterReportService.transformAndPopulateToGP(clinicalDocument, reportItems.getMessageId(), headerValues);
return new ResponseEntity<>(itkResponseUtil.createSuccessResponseEntity(reportItems.getMessageId(), randomUUID().toString().toUpperCase()), OK);
} catch (SAXException e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, "This is not a valid XML message", e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (XmlException e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, "schema validation failed", e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (ItkXmlException e) {
LOGGER.error(e.getReason(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (SoapClientException e) {
LOGGER.error(e.getReason(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_CLIENT, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (SoapMustUnderstandException e) {
LOGGER.error(e.getReason(), e);
return new ResponseEntity<>(createErrorResponseBody(DEFAULT_ADDRESS, CLIENT_ERROR_CODE, FAULT_CODE_MUSTUNDERSTAND, e.getReason(), e.getMessage()), INTERNAL_SERVER_ERROR);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(createErrorResponseBody(toAddress, INTERNAL_PROCESSING_ERROR_CODE, FAULT_CODE_CLIENT, INTERNAL_USER_ERROR_MESSAGE, INTERNAL_ERROR_MESSAGE), INTERNAL_SERVER_ERROR);
}
}
Aggregations