Search in sources :

Example 1 with SoapClientException

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);
    }
}
Also used : SoapMustUnderstandException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException) ReportItems(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ReportItems) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) ItkXmlException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException) XmlException(org.apache.xmlbeans.XmlException) SAXException(org.xml.sax.SAXException) SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) SoapMustUnderstandException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException) SAXException(org.xml.sax.SAXException) ResponseEntity(org.springframework.http.ResponseEntity) DistributionEnvelopeDocument(uk.nhs.itk.envelope.DistributionEnvelopeDocument) SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) ItkXmlException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException) XmlException(org.apache.xmlbeans.XmlException) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) ItkXmlException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with SoapClientException

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);
    }
}
Also used : SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 3 with SoapClientException

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);
}
Also used : SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with SoapClientException

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);
}
Also used : SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) Element(org.w3c.dom.Element) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with SoapClientException

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");
    }
}
Also used : SoapClientException(uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException) Node(org.w3c.dom.Node)

Aggregations

SoapClientException (uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapClientException)8 Node (org.w3c.dom.Node)5 Element (org.w3c.dom.Element)3 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 XmlException (org.apache.xmlbeans.XmlException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 SAXException (org.xml.sax.SAXException)1 ItkXmlException (uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.ItkXmlException)1 SoapMustUnderstandException (uk.nhs.adaptors.oneoneone.cda.report.controller.exceptions.SoapMustUnderstandException)1 ItkReportHeader (uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader)1 ReportItems (uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ReportItems)1 POCDMT000002UK01ClinicalDocument1 (uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1)1 DistributionEnvelopeDocument (uk.nhs.itk.envelope.DistributionEnvelopeDocument)1