Search in sources :

Example 1 with OptimisticLockException

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);
    }
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) Header(org.apache.http.Header) Request(org.apache.http.client.fluent.Request) HttpResponse(org.apache.http.HttpResponse) OptimisticLockException(org.ehrbase.client.exception.OptimisticLockException) IOException(java.io.IOException) ClientException(org.ehrbase.client.exception.ClientException)

Example 2 with OptimisticLockException

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);
}
Also used : WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) OptimisticLockException(org.ehrbase.client.exception.OptimisticLockException) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ResourceVersionConflictException(ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException) OptimisticLockException(org.ehrbase.client.exception.OptimisticLockException) WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException)

Aggregations

OptimisticLockException (org.ehrbase.client.exception.OptimisticLockException)2 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)1 ResourceVersionConflictException (ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException)1 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)1 IOException (java.io.IOException)1 Header (org.apache.http.Header)1 HttpResponse (org.apache.http.HttpResponse)1 Request (org.apache.http.client.fluent.Request)1 ClientException (org.ehrbase.client.exception.ClientException)1 WrongStatusCodeException (org.ehrbase.client.exception.WrongStatusCodeException)1 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)1