Search in sources :

Example 6 with UnexpectedSpineResponseException

use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.

the class SpineClient method sendGetScr.

@SneakyThrows
@Override
@LogExecutionTime
public Response<Document> sendGetScr(String requestBody, String nhsdAsid) {
    var uri = spineConfiguration.getUrl() + spineConfiguration.getPsisQueriesEndpoint();
    var request = new HttpPost(uri);
    LOGGER.info("Sending GET SCR Spine request. URL: {}", uri);
    LOGGER.debug("Body: {}", requestBody);
    request.addHeader(SOAP_ACTION, PSIS_EVENT_QUERY_SOAP_ACTION);
    request.addHeader(CONTENT_TYPE, TEXT_XML_VALUE);
    request.addHeader(NHSD_ASID, nhsdAsid);
    request.setEntity(new StringEntity(requestBody, UTF_8));
    var response = spineHttpClient.sendRequest(request, xmlResponseHandler);
    var statusCode = response.getStatusCode();
    if (statusCode != OK.value()) {
        LOGGER.error("Unexpected spine GET SCR response: {} {}", statusCode, serialize(response.getBody()));
        throw new UnexpectedSpineResponseException("Unexpected spine send response " + statusCode);
    }
    LOGGER.info("Received Spine {} interaction response: HTTP status {}", PSIS_EVENT_QUERY_SOAP_ACTION, response.getStatusCode());
    return response;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime) SneakyThrows(lombok.SneakyThrows)

Example 7 with UnexpectedSpineResponseException

use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.

the class AlertService method sendAlert.

public void sendAlert(String body, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
    Response<String> response = spineClient.sendAlert(body, nhsdAsid, nhsdIdentity, nhsdSessionUrid);
    HttpStatus status = HttpStatus.resolve(response.getStatusCode());
    if (status == null || !status.is2xxSuccessful()) {
        OperationOutcome error = fhirParser.parseResource(response.getBody(), OperationOutcome.class);
        if (status != null && status.is4xxClientError()) {
            LOGGER.error("Spine processing error: {}", status);
            throw new BadRequestException(getErrorReason(error));
        } else {
            LOGGER.error("Spine processing error: {}", getErrorReason(error));
            throw new UnexpectedSpineResponseException(getErrorReason(error));
        }
    }
}
Also used : UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) HttpStatus(org.springframework.http.HttpStatus) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) BadRequestException(uk.nhs.adaptors.scr.exceptions.BadRequestException)

Example 8 with UnexpectedSpineResponseException

use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.

the class UploadScrService method validateProcessingResult.

@SneakyThrows
private void validateProcessingResult(ProcessingResult processingResult) {
    var hl7Document = parseDocument(processingResult.getHl7());
    var acknowledgementXPath = XPathFactory.newInstance().newXPath().compile("/MCCI_IN010000UK13/acknowledgement");
    var acknowledgementNode = ((NodeList) acknowledgementXPath.evaluate(hl7Document, XPathConstants.NODESET)).item(0);
    String acknowledgementTypeCode;
    try {
        acknowledgementTypeCode = acknowledgementNode.getAttributes().getNamedItem("typeCode").getNodeValue();
    } catch (Exception ex) {
        LOGGER.error("Unable to extract acknowledgement code:\n{}", processingResult.getHl7());
        throw new UnexpectedSpineResponseException("Unable to extract acknowledgement code");
    }
    if (!acknowledgementTypeCode.equals("AA")) {
        var errors = getErrors(hl7Document);
        LOGGER.error("Non success spine processing result:\n{}\n{}", processingResult.getSoapEnvelope(), processingResult.getHl7());
        throw new NonSuccessSpineProcessingResultException(errors);
    }
}
Also used : NonSuccessSpineProcessingResultException(uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) NodeList(org.w3c.dom.NodeList) XPathExpressionException(javax.xml.xpath.XPathExpressionException) UnexpectedSpineResponseException(uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException) NonSuccessSpineProcessingResultException(uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException) SneakyThrows(lombok.SneakyThrows)

Aggregations

UnexpectedSpineResponseException (uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException)8 LogExecutionTime (uk.nhs.adaptors.scr.logging.LogExecutionTime)6 SneakyThrows (lombok.SneakyThrows)5 HttpPost (org.apache.http.client.methods.HttpPost)4 StringEntity (org.apache.http.entity.StringEntity)4 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 NonSuccessSpineProcessingResultException (uk.nhs.adaptors.scr.exceptions.NonSuccessSpineProcessingResultException)2 HttpGet (org.apache.http.client.methods.HttpGet)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)1 HttpStatus (org.springframework.http.HttpStatus)1 BackOffInterruptedException (org.springframework.retry.backoff.BackOffInterruptedException)1 NodeList (org.w3c.dom.NodeList)1 BadRequestException (uk.nhs.adaptors.scr.exceptions.BadRequestException)1 NoSpineResultException (uk.nhs.adaptors.scr.exceptions.NoSpineResultException)1 ScrTimeoutException (uk.nhs.adaptors.scr.exceptions.ScrTimeoutException)1