use of org.ehrbase.client.exception.OptimisticLockException in project openEHR_SDK by ehrbase.
the class DefaultRestClient method httpPut.
protected VersionUid httpPut(URI uri, Locatable body, VersionUid versionUid, Map<String, String> headers) {
try {
Request request = Request.Put(uri).addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()).addHeader(HttpHeaders.IF_MATCH, versionUid.toString()).bodyString(new CanonicalJson().marshal(body), ContentType.APPLICATION_JSON);
if (headers != null) {
headers.forEach(request::addHeader);
}
HttpResponse response = executor.execute(request).returnResponse();
checkStatus(response, HttpStatus.SC_OK, HttpStatus.SC_NO_CONTENT, HttpStatus.SC_PRECONDITION_FAILED);
if (HttpStatus.SC_PRECONDITION_FAILED == response.getStatusLine().getStatusCode()) {
throw new OptimisticLockException("Entity outdated");
}
Header eTag = response.getFirstHeader(HttpHeaders.ETAG);
return buildVersionUidFromETag(eTag);
} catch (IOException e) {
throw new ClientException(e.getMessage(), e);
}
}
use of org.ehrbase.client.exception.OptimisticLockException in project fhir-bridge by ehrbase.
the class OpenEhrClientExceptionHandler method process.
@Override
public void process(Exchange exchange) throws Exception {
Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
Assert.notNull(ex, "Exception must not be null");
if (ex instanceof WrongStatusCodeException) {
handleWrongStatusCode((WrongStatusCodeException) ex);
} else if (ex instanceof OptimisticLockException) {
handleOptimisticLock((OptimisticLockException) ex);
}
handleException(ex);
}
Aggregations