diff --git a/blobstore/pom.xml b/blobstore/pom.xml index 55d2196e26..0dc537ff68 100644 --- a/blobstore/pom.xml +++ b/blobstore/pom.xml @@ -42,6 +42,10 @@ jclouds-core ${project.version} + + jakarta.ws.rs + jakarta.ws.rs-api + ${project.groupId} jclouds-core diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java index c5ed0effbd..b83a7d022d 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java @@ -42,6 +42,7 @@ import java.util.concurrent.ExecutorService; import jakarta.annotation.Resource; +import jakarta.ws.rs.core.Response.Status; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -640,29 +641,39 @@ public Blob getBlob(String containerName, String key, GetOptions options) { if (eTag != null) { eTag = maybeQuoteETag(eTag); if (options.getIfMatch() != null) { - if (!eTag.equals(maybeQuoteETag(options.getIfMatch()))) - throw returnResponseException(412); + if (!eTag.equals(maybeQuoteETag(options.getIfMatch()))) { + HttpResponse response = HttpResponse.builder().statusCode(Status.PRECONDITION_FAILED.getStatusCode()).addHeader(HttpHeaders.ETAG, eTag).build(); + throw new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub").build()), response); + } } if (options.getIfNoneMatch() != null) { - if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch()))) - throw returnResponseException(304); + if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch()))) { + HttpResponse response = HttpResponse.builder().statusCode(Status.NOT_MODIFIED.getStatusCode()).addHeader(HttpHeaders.ETAG, eTag).build(); + throw new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub").build()), response); + } } } if (options.getIfModifiedSince() != null) { Date modifiedSince = options.getIfModifiedSince(); if (blob.getMetadata().getLastModified().before(modifiedSince)) { - HttpResponse response = HttpResponse.builder().statusCode(304).build(); + HttpResponse.Builder response = HttpResponse.builder().statusCode(Status.NOT_MODIFIED.getStatusCode()); + if (eTag != null) { + response.addHeader(HttpHeaders.ETAG, eTag); + } throw new HttpResponseException(String.format("%1$s is before %2$s", blob - .getMetadata().getLastModified(), modifiedSince), null, response); + .getMetadata().getLastModified(), modifiedSince), null, response.build()); } } if (options.getIfUnmodifiedSince() != null) { Date unmodifiedSince = options.getIfUnmodifiedSince(); if (blob.getMetadata().getLastModified().after(unmodifiedSince)) { - HttpResponse response = HttpResponse.builder().statusCode(412).build(); + HttpResponse.Builder response = HttpResponse.builder().statusCode(Status.PRECONDITION_FAILED.getStatusCode()); + if (eTag != null) { + response.addHeader(HttpHeaders.ETAG, eTag); + } throw new HttpResponseException(String.format("%1$s is after %2$s", blob - .getMetadata().getLastModified(), unmodifiedSince), null, response); + .getMetadata().getLastModified(), unmodifiedSince), null, response.build()); } } blob = copyBlob(blob);