diff --git a/sdk/storage/azure-storage-blob/pom.xml b/sdk/storage/azure-storage-blob/pom.xml index 674d32efef22..689874576caf 100644 --- a/sdk/storage/azure-storage-blob/pom.xml +++ b/sdk/storage/azure-storage-blob/pom.xml @@ -48,6 +48,7 @@ --add-opens com.azure.storage.blob/com.azure.storage.blob.implementation.util=ALL-UNNAMED --add-opens com.azure.storage.blob/com.azure.storage.blob.specialized=ALL-UNNAMED --add-opens com.azure.storage.blob/com.azure.storage.blob.changefeed=ALL-UNNAMED + --add-opens com.azure.storage.blob/com.azure.storage.blob.implementation.models=ALL-UNNAMED --add-reads com.azure.core=ALL-UNNAMED --add-reads com.azure.core.test=ALL-UNNAMED --add-reads com.azure.core.amqp=ALL-UNNAMED diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlockBlobItem.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlockBlobItem.java index 93f02a49484e..5f6a5d859205 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlockBlobItem.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlockBlobItem.java @@ -29,7 +29,9 @@ public class BlockBlobItem { * @param contentMd5 Content MD5 of the block blob. * @param isServerEncrypted Flag indicating if the block blob is encrypted on the server. * @param encryptionKeySha256 The encryption key used to encrypt the block blob. + * @deprecated Use {@link #BlockBlobItem(String, OffsetDateTime, byte[], Boolean, String, String, String)} instead. */ + @Deprecated public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5, final boolean isServerEncrypted, final String encryptionKeySha256) { this(eTag, lastModified, contentMd5, isServerEncrypted, encryptionKeySha256, null); @@ -44,7 +46,9 @@ public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final * @param isServerEncrypted Flag indicating if the block blob is encrypted on the server. * @param encryptionKeySha256 The encryption key used to encrypt the block blob. * @param encryptionScope The encryption scope used to encrypt the block blob. + * @deprecated Use {@link #BlockBlobItem(String, OffsetDateTime, byte[], Boolean, String, String, String)} instead. */ + @Deprecated public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5, final boolean isServerEncrypted, final String encryptionKeySha256, final String encryptionScope) { this(eTag, lastModified, contentMd5, isServerEncrypted, encryptionKeySha256, encryptionScope, null); @@ -60,10 +64,29 @@ public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final * @param encryptionKeySha256 The encryption key used to encrypt the block blob. * @param encryptionScope The encryption scope used to encrypt the block blob. * @param versionId The version identifier of the block blob. + * @deprecated Use {@link #BlockBlobItem(String, OffsetDateTime, byte[], Boolean, String, String, String)} instead. */ + @Deprecated public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5, - final boolean isServerEncrypted, final String encryptionKeySha256, - final String encryptionScope, final String versionId) { + final boolean isServerEncrypted, final String encryptionKeySha256, final String encryptionScope, + final String versionId) { + this(eTag, lastModified, contentMd5, (Boolean) isServerEncrypted, encryptionKeySha256, encryptionScope, versionId); + } + + /** + * Constructs a {@link BlockBlobItem}. + * + * @param eTag ETag of the block blob. + * @param lastModified Last modified time of the block blob. + * @param contentMd5 Content MD5 of the block blob. + * @param isServerEncrypted Flag indicating if the block blob is encrypted on the server. + * @param encryptionKeySha256 The encryption key used to encrypt the block blob. + * @param encryptionScope The encryption scope used to encrypt the block blob. + * @param versionId The version identifier of the block blob. + */ + public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5, + final Boolean isServerEncrypted, final String encryptionKeySha256, final String encryptionScope, + final String versionId) { this.eTag = eTag; this.lastModified = lastModified; this.contentMd5 = CoreUtils.clone(contentMd5); diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlockBlobAPITest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlockBlobAPITest.groovy index b7bc6f61e34e..c8a13d1b3342 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlockBlobAPITest.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlockBlobAPITest.groovy @@ -4,6 +4,7 @@ package com.azure.storage.blob.specialized import com.azure.core.exception.UnexpectedLengthException +import com.azure.core.http.HttpHeaders import com.azure.core.http.HttpMethod import com.azure.core.http.HttpPipelineCallContext import com.azure.core.http.HttpPipelineNextPolicy @@ -22,6 +23,7 @@ import com.azure.storage.blob.BlobServiceClientBuilder import com.azure.storage.blob.BlobServiceVersion import com.azure.storage.blob.BlobUrlParts import com.azure.storage.blob.ProgressReceiver +import com.azure.storage.blob.implementation.models.BlockBlobsPutBlobFromUrlHeaders import com.azure.storage.blob.models.AccessTier import com.azure.storage.blob.models.BlobCopySourceTagsMode import com.azure.storage.blob.models.BlobErrorCode @@ -29,6 +31,7 @@ import com.azure.storage.blob.models.BlobHttpHeaders import com.azure.storage.blob.models.BlobRange import com.azure.storage.blob.models.BlobRequestConditions import com.azure.storage.blob.models.BlobStorageException +import com.azure.storage.blob.models.BlockBlobItem import com.azure.storage.blob.models.BlockListType import com.azure.storage.blob.models.CustomerProvidedKey import com.azure.storage.blob.models.ParallelTransferOptions @@ -2607,4 +2610,28 @@ class BlockBlobAPITest extends APISpec { BlobCopySourceTagsMode.COPY | _ BlobCopySourceTagsMode.REPLACE | _ } + + def "BlockBlobItem null headers"() { + setup: + def headers = new HttpHeaders() + def hd = new BlockBlobsPutBlobFromUrlHeaders(headers) + + when: + def blockBlobItem = new BlockBlobItem(hd.getETag(), + hd.getLastModified(), + hd.getContentMD5(), + hd.isXMsRequestServerEncrypted(), + hd.getXMsEncryptionKeySha256(), + hd.getXMsEncryptionScope(), + hd.getXMsVersionId()) + + then: + blockBlobItem.getETag() == null + blockBlobItem.getLastModified() == null + blockBlobItem.getContentMd5() == null + blockBlobItem.isServerEncrypted() == null + blockBlobItem.getEncryptionKeySha256() == null + blockBlobItem.getEncryptionScope() == null + blockBlobItem.getVersionId() == null + } } diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlockBlobAPITestBlockBlobItemNullHeaders.json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlockBlobAPITestBlockBlobItemNullHeaders.json new file mode 100644 index 000000000000..b4d39590db1a --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlockBlobAPITestBlockBlobItemNullHeaders.json @@ -0,0 +1,77 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/7753539a07753539a653397613a74d390234b40b8bd1?restype=container", + "Headers" : { + "x-ms-version" : "2021-10-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.21.0-beta.1 (11.0.16.1; Windows 11; 10.0)", + "x-ms-client-request-id" : "d47a9d41-8830-4f02-8bd4-a6a99c504a6e" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2021-10-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "ETag" : "0x8DAD32434A9EF0D", + "Last-Modified" : "Wed, 30 Nov 2022 22:42:48 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "7a3dfffc-a01e-002a-790d-05a0a2000000", + "Date" : "Wed, 30 Nov 2022 22:42:47 GMT", + "x-ms-client-request-id" : "d47a9d41-8830-4f02-8bd4-a6a99c504a6e" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/7753539a07753539a653397613a74d390234b40b8bd1/7753539a17753539a65305102d347f2059158408485c", + "Headers" : { + "x-ms-version" : "2021-10-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.21.0-beta.1 (11.0.16.1; Windows 11; 10.0)", + "x-ms-client-request-id" : "f9787ccf-1c72-45f7-892d-7e9f0a693da3", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2021-10-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Wed, 30 Nov 2022 22:42:48 GMT", + "x-ms-version-id" : "2022-11-30T22:42:48.4748207Z", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Wed, 30 Nov 2022 22:42:47 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "ETag" : "0x8DAD32434D117AF", + "x-ms-request-id" : "7a3e0171-a01e-002a-500d-05a0a2000000", + "x-ms-client-request-id" : "f9787ccf-1c72-45f7-892d-7e9f0a693da3" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/7753539a07753539a653397613a74d390234b40b8bd1/7753539a27753539a653419280b35f19c474143abbb6", + "Headers" : { + "x-ms-version" : "2021-10-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.21.0-beta.1 (11.0.16.1; Windows 11; 10.0)", + "x-ms-client-request-id" : "bd083474-97e8-4bf3-85c0-981a4d7d0f38", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2021-10-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Wed, 30 Nov 2022 22:42:48 GMT", + "x-ms-version-id" : "2022-11-30T22:42:48.6337297Z", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Wed, 30 Nov 2022 22:42:47 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "ETag" : "0x8DAD32434E95711", + "x-ms-request-id" : "7a3e02a2-a01e-002a-6f0d-05a0a2000000", + "x-ms-client-request-id" : "bd083474-97e8-4bf3-85c0-981a4d7d0f38" + }, + "Exception" : null + } ], + "variables" : [ "7753539a07753539a653397613a74d390234b40b8bd1", "7753539a17753539a65305102d347f2059158408485c", "7753539a27753539a653419280b35f19c474143abbb6" ] +} \ No newline at end of file