use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.
the class SpineClient method sendScrData.
@SneakyThrows
@Override
@LogExecutionTime
public Response<String> sendScrData(String requestBody, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
var url = spineConfiguration.getUrl() + spineConfiguration.getScrEndpoint();
LOGGER.info("Sending SCR Upload request to SPINE. URL: {}", url);
LOGGER.debug("Body: {}", requestBody);
var request = new HttpPost(url);
setUploadScrHeaders(request, nhsdAsid, nhsdIdentity, nhsdSessionUrid);
request.setEntity(new StringEntity(requestBody, UTF_8));
var response = spineHttpClient.sendRequest(request, stringResponseHandler);
var statusCode = response.getStatusCode();
if (statusCode != ACCEPTED.value()) {
LOGGER.error("Unexpected spine SCR POST response: {} {}", statusCode, response.getBody());
throw new UnexpectedSpineResponseException("Unexpected spine 'send data' response " + statusCode);
}
LOGGER.info("Received Spine {} interaction response: HTTP status {}", UPLOAD_SCR_SOAP_ACTION, response.getStatusCode());
return response;
}
use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.
the class SpineClient method getScrProcessingResult.
@Override
@LogExecutionTime
public ProcessingResult getScrProcessingResult(String contentLocation, long initialWaitTime, String nhsdAsid, String nhsdIdentity, String nhsdSessionUrid) {
var repeatTimeout = spineConfiguration.getScrResultRepeatTimeout();
var template = RetryTemplate.builder().withinMillis(repeatTimeout).customBackoff(new ScrRetryBackoffPolicy()).retryOn(NoSpineResultException.class).build();
LOGGER.info("Starting polling result. First request in {}ms", initialWaitTime);
try {
Thread.sleep(initialWaitTime);
} catch (InterruptedException e) {
throw new ScrTimeoutException(e);
}
return template.execute(ctx -> {
LOGGER.info("Fetching SCR processing result. RetryCount={}", ctx.getRetryCount());
var request = new HttpGet(spineConfiguration.getUrl() + contentLocation);
setCommonHeaders(request, nhsdAsid, nhsdIdentity, nhsdSessionUrid);
var result = spineHttpClient.sendRequest(request, stringResponseHandler);
int statusCode = result.getStatusCode();
if (statusCode == OK.value()) {
LOGGER.info("{} processing result received.", statusCode);
return ProcessingResult.parseProcessingResult(result.getBody());
} else if (statusCode == ACCEPTED.value()) {
var nextRetryAfter = Long.parseLong(SpineHttpClient.getHeader(result.getHeaders(), RETRY_AFTER));
LOGGER.info("{} received. NextRetry in {}ms", statusCode, nextRetryAfter);
throw new NoSpineResultException(nextRetryAfter);
} else {
LOGGER.error("Unexpected spine polling response: {} {}", statusCode, result.getBody());
throw new UnexpectedSpineResponseException("Unexpected spine polling response " + statusCode);
}
});
}
use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.
the class UploadScrService method uploadScr.
@LogExecutionTime
public void uploadScr(RequestData requestData) {
Bundle bundle = fhirParser.parseResource(requestData.getBody(), Bundle.class);
var spineRequest = bundleMapper.map(bundle, requestData.getNhsdAsid());
checkPermission(bundle, requestData.getNhsdAsid(), requestData.getClientIp());
var response = spineClient.sendScrData(spineRequest, requestData.getNhsdAsid(), requestData.getNhsdIdentity(), requestData.getNhsdSessionUrid());
String contentLocation;
long retryAfter;
try {
contentLocation = getHeader(response.getHeaders(), CONTENT_LOCATION);
retryAfter = parseLong(getHeader(response.getHeaders(), RETRY_AFTER));
} catch (Exception ex) {
throw new UnexpectedSpineResponseException("Unable to extract required headers", ex);
}
var processingResult = spineClient.getScrProcessingResult(contentLocation, retryAfter, requestData.getNhsdAsid(), requestData.getNhsdIdentity(), requestData.getNhsdSessionUrid());
validateProcessingResult(processingResult);
}
use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.
the class SpineClient method sendGetScrId.
@SneakyThrows
@Override
@LogExecutionTime
public Response<Document> sendGetScrId(String requestBody, String nhsdAsid) {
LOGGER.info("Sending GET SCR ID Spine request");
LOGGER.debug("Body: {}", requestBody);
var request = new HttpPost(spineConfiguration.getUrl() + spineConfiguration.getPsisQueriesEndpoint());
setSoapHeaders(request, PSIS_EVENT_LIST_QUERY, TEXT_XML_VALUE);
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 ID response: {} {}", statusCode, serialize(response.getBody()));
throw new UnexpectedSpineResponseException("Unexpected spine send response " + statusCode);
}
LOGGER.info("Received Spine {} interaction response: HTTP status {}", PSIS_EVENT_LIST_QUERY, response.getStatusCode());
return response;
}
use of uk.nhs.adaptors.scr.exceptions.UnexpectedSpineResponseException in project summary-care-record-api by NHSDigital.
the class SpineClient method sendAcsData.
@SneakyThrows
@Override
@LogExecutionTime
public Response<Document> sendAcsData(String requestBody, String nhsdAsid) {
var url = spineConfiguration.getUrl() + spineConfiguration.getAcsEndpoint();
LOGGER.info("Sending ACS Set Permission Spine request. URL: {}", url);
LOGGER.debug("Body: {}", requestBody);
var request = new HttpPost(url);
setSoapHeaders(request, SET_PERMISSION_SOAP_ACTION, TEXT_XML_VALUE);
request.setHeader(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 ACS set permission response: {}", response);
throw new UnexpectedSpineResponseException("Unexpected spine 'send data' response " + statusCode);
}
LOGGER.info("Received Spine {} interaction response: HTTP status {}", SET_PERMISSION_SOAP_ACTION, response.getStatusCode());
return response;
}
Aggregations