use of uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException 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);
}
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException in project integration-adaptor-111 by nhsconnect.
the class ItkValidator method checkAuditIdentity.
private void checkAuditIdentity(Element itkHeader) throws SoapClientException {
Node auditNode = xmlUtils.getSingleNode(itkHeader, ITK_AUDIT_IDENTITY_XPATH);
Node auditIdNode = xmlUtils.getSingleNode((Element) auditNode, AUDIT_IDENTITY_ID_XPATH);
String auditIdentity = ((Element) auditIdNode).getAttribute("uri");
if (!StringUtils.startsWith(auditIdentity, AUDIT_IDENTITY_PREFIX)) {
throw new SoapClientException(SOAP_VALIDATION_FAILED_MSG, "Invalid Audit Identity value: " + auditIdentity);
}
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException in project integration-adaptor-111 by nhsconnect.
the class ReportControllerTest method postReportInvalidItkRequest.
@Test
public void postReportInvalidItkRequest() throws SoapClientException {
doThrow(new SoapClientException("Soap validation failed", "ITK header missing")).when(itkValidator).checkItkConformance(any());
String invalidRequest = getValidXmlReportRequest();
ResponseEntity<String> response = reportController.postReport(invalidRequest);
assertThat(response.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR);
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException in project integration-adaptor-111 by nhsconnect.
the class ReportControllerTest method postReportInvalidItkAddressRequest.
@Test
public void postReportInvalidItkAddressRequest() throws SoapClientException {
doThrow(new SoapClientException("Soap validation failed", "Not supported ITK address")).when(itkAddressValidator).checkItkOdsAndDosId(any(Element.class));
String invalidRequest = getValidXmlReportRequest();
ResponseEntity<String> response = reportController.postReport(invalidRequest);
assertThat(response.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR);
}
use of uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException in project integration-adaptor-111 by nhsconnect.
the class SoapValidator method checkTimestamp.
private void checkTimestamp(Element soapHeader) throws SoapClientException {
Node timestamp = xmlUtils.getSingleNode(soapHeader, TIMESTAMP_XPATH);
if (timestamp == null) {
throw new SoapClientException("Soap validation failed", "Timestamp missing");
}
String created = xmlUtils.getSingleNode(timestamp, TIMESTAMP_CREATED_XPATH).getTextContent();
String expires = xmlUtils.getSingleNode(timestamp, TIMESTAMP_EXPIRES_XPATH).getTextContent();
if (OffsetDateTime.parse(created).isAfter(OffsetDateTime.parse(expires))) {
throw new SoapClientException("Soap validation failed", "Invalid timestamp");
}
}
Aggregations