Skip to content

Commit 3cfe426

Browse files
Rename policy to StorageContentValidationDecoderPolicy and move constants to Constants.java
Co-authored-by: gunjansingh-msft <[email protected]>
1 parent 742b860 commit 3cfe426

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/BuilderHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
141141
HttpPolicyProviders.addAfterRetryPolicies(policies);
142142

143143
// Add structured message decoder policy to handle structured message decoding
144-
policies.add(new StructuredMessageDecoderPolicy());
144+
policies.add(new StorageContentValidationDecoderPolicy());
145145

146146
policies.add(getResponseValidationPolicy());
147147

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/StructuredMessageDecoderPolicy.java renamed to sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/StorageContentValidationDecoderPolicy.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.azure.core.util.FluxUtil;
1414
import com.azure.core.util.logging.ClientLogger;
1515
import com.azure.storage.common.DownloadContentValidationOptions;
16+
import com.azure.storage.common.implementation.Constants;
1617
import com.azure.storage.common.implementation.structuredmessage.StructuredMessageDecodingStream;
1718
import reactor.core.publisher.Flux;
1819
import reactor.core.publisher.Mono;
@@ -24,24 +25,13 @@
2425
* This is a decoding policy in an {@link com.azure.core.http.HttpPipeline} to decode structured messages in blob
2526
* download requests. The policy checks for a context value to determine when to apply structured message decoding.
2627
*/
27-
public class StructuredMessageDecoderPolicy implements HttpPipelinePolicy {
28-
private static final ClientLogger LOGGER = new ClientLogger(StructuredMessageDecoderPolicy.class);
28+
public class StorageContentValidationDecoderPolicy implements HttpPipelinePolicy {
29+
private static final ClientLogger LOGGER = new ClientLogger(StorageContentValidationDecoderPolicy.class);
2930

3031
/**
31-
* Context key used to signal that structured message decoding should be applied.
32+
* Creates a new instance of {@link StorageContentValidationDecoderPolicy}.
3233
*/
33-
public static final String STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY = "azure-storage-structured-message-decoding";
34-
35-
/**
36-
* Context key used to pass DownloadContentValidationOptions to the policy.
37-
*/
38-
public static final String STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY =
39-
"azure-storage-structured-message-validation-options";
40-
41-
/**
42-
* Creates a new instance of {@link StructuredMessageDecoderPolicy}.
43-
*/
44-
public StructuredMessageDecoderPolicy() {
34+
public StorageContentValidationDecoderPolicy() {
4535
}
4636

4737
@Override
@@ -75,7 +65,7 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
7565
* @return true if decoding should be applied, false otherwise.
7666
*/
7767
private boolean shouldApplyDecoding(HttpPipelineCallContext context) {
78-
return context.getData(STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY)
68+
return context.getData(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY)
7969
.map(value -> value instanceof Boolean && (Boolean) value)
8070
.orElse(false);
8171
}
@@ -87,7 +77,7 @@ private boolean shouldApplyDecoding(HttpPipelineCallContext context) {
8777
* @return The validation options or null if not present.
8878
*/
8979
private DownloadContentValidationOptions getValidationOptions(HttpPipelineCallContext context) {
90-
return context.getData(STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY)
80+
return context.getData(Constants.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY)
9181
.filter(value -> value instanceof DownloadContentValidationOptions)
9282
.map(value -> (DownloadContentValidationOptions) value)
9383
.orElse(null);

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlobAsyncClientBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.azure.storage.blob.implementation.util.BlobSasImplUtil;
4747
import com.azure.storage.blob.implementation.util.ChunkedDownloadUtils;
4848
import com.azure.storage.blob.implementation.util.ModelHelper;
49-
import com.azure.storage.blob.implementation.util.StructuredMessageDecoderPolicy;
5049
import com.azure.storage.blob.models.AccessTier;
5150
import com.azure.storage.blob.models.BlobBeginCopySourceRequestConditions;
5251
import com.azure.storage.blob.models.BlobCopyInfo;
@@ -82,6 +81,7 @@
8281
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues;
8382
import com.azure.storage.common.StorageSharedKeyCredential;
8483
import com.azure.storage.common.Utility;
84+
import com.azure.storage.common.implementation.Constants;
8585
import com.azure.storage.common.implementation.SasImplUtils;
8686
import com.azure.storage.common.implementation.StorageImplUtils;
8787
import com.azure.storage.common.DownloadContentValidationOptions;
@@ -1341,9 +1341,9 @@ Mono<BlobDownloadAsyncResponse> downloadStreamWithResponse(BlobRange range, Down
13411341
if (contentValidationOptions != null
13421342
&& contentValidationOptions.isStructuredMessageValidationEnabled()) {
13431343
firstRangeContext = firstRangeContext.addData(
1344-
StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true);
1344+
Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true);
13451345
firstRangeContext = firstRangeContext.addData(
1346-
StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY,
1346+
Constants.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY,
13471347
contentValidationOptions);
13481348
}
13491349

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/implementation/util/StructuredMessageDecoderPolicyTest.java renamed to sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/implementation/util/StorageContentValidationDecoderPolicyTest.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.azure.core.http.HttpResponse;
1313
import com.azure.core.util.Context;
1414
import com.azure.storage.common.DownloadContentValidationOptions;
15+
import com.azure.storage.common.implementation.Constants;
1516
import org.junit.jupiter.api.Test;
1617
import org.mockito.Mockito;
1718
import reactor.core.publisher.Flux;
@@ -28,14 +29,14 @@
2829
import static org.mockito.Mockito.when;
2930

3031
/**
31-
* Unit tests for {@link StructuredMessageDecoderPolicy}.
32+
* Unit tests for {@link StorageContentValidationDecoderPolicy}.
3233
*/
33-
public class StructuredMessageDecoderPolicyTest {
34+
public class StorageContentValidationDecoderPolicyTest {
3435

3536
@Test
3637
public void shouldNotApplyDecodingWhenContextKeyNotPresent() throws MalformedURLException {
3738
// Arrange
38-
StructuredMessageDecoderPolicy policy = new StructuredMessageDecoderPolicy();
39+
StorageContentValidationDecoderPolicy policy = new StorageContentValidationDecoderPolicy();
3940
HttpPipelineCallContext context = createMockContext(null, null);
4041
HttpPipelineNextPolicy nextPolicy = createMockNextPolicy();
4142

@@ -54,8 +55,8 @@ public void shouldNotApplyDecodingWhenContextKeyNotPresent() throws MalformedURL
5455
@Test
5556
public void shouldNotApplyDecodingWhenContextKeyIsFalse() throws MalformedURLException {
5657
// Arrange
57-
StructuredMessageDecoderPolicy policy = new StructuredMessageDecoderPolicy();
58-
Context ctx = new Context(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, false);
58+
StorageContentValidationDecoderPolicy policy = new StorageContentValidationDecoderPolicy();
59+
Context ctx = new Context(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, false);
5960
HttpPipelineCallContext context = createMockContext(ctx, null);
6061
HttpPipelineNextPolicy nextPolicy = createMockNextPolicy();
6162

@@ -74,12 +75,12 @@ public void shouldNotApplyDecodingWhenContextKeyIsFalse() throws MalformedURLExc
7475
@Test
7576
public void shouldApplyDecodingWhenContextKeyIsTrue() throws MalformedURLException {
7677
// Arrange
77-
StructuredMessageDecoderPolicy policy = new StructuredMessageDecoderPolicy();
78+
StorageContentValidationDecoderPolicy policy = new StorageContentValidationDecoderPolicy();
7879
DownloadContentValidationOptions validationOptions = new DownloadContentValidationOptions()
7980
.setStructuredMessageValidationEnabled(true);
8081

81-
Context ctx = new Context(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true)
82-
.addData(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY, validationOptions);
82+
Context ctx = new Context(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true)
83+
.addData(Constants.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY, validationOptions);
8384

8485
HttpPipelineCallContext context = createMockContext(ctx, 1024L);
8586
HttpPipelineNextPolicy nextPolicy = createMockNextPolicy();
@@ -93,20 +94,20 @@ public void shouldApplyDecodingWhenContextKeyIsTrue() throws MalformedURLExcepti
9394
assertNotNull(response);
9495
assertEquals(200, response.getStatusCode());
9596
// Verify it's a DecodedResponse
96-
assertTrue(response instanceof StructuredMessageDecoderPolicy.DecodedResponse);
97+
assertTrue(response instanceof StorageContentValidationDecoderPolicy.DecodedResponse);
9798
})
9899
.verifyComplete();
99100
}
100101

101102
@Test
102103
public void shouldNotApplyDecodingForNonDownloadResponse() throws MalformedURLException {
103104
// Arrange
104-
StructuredMessageDecoderPolicy policy = new StructuredMessageDecoderPolicy();
105+
StorageContentValidationDecoderPolicy policy = new StorageContentValidationDecoderPolicy();
105106
DownloadContentValidationOptions validationOptions = new DownloadContentValidationOptions()
106107
.setStructuredMessageValidationEnabled(true);
107108

108-
Context ctx = new Context(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true)
109-
.addData(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY, validationOptions);
109+
Context ctx = new Context(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true)
110+
.addData(Constants.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY, validationOptions);
110111

111112
HttpPipelineCallContext context = createMockContext(ctx, null);
112113
// Create a non-GET request (POST)
@@ -126,7 +127,7 @@ public void shouldNotApplyDecodingForNonDownloadResponse() throws MalformedURLEx
126127
assertNotNull(response);
127128
assertEquals(200, response.getStatusCode());
128129
// Should not be a DecodedResponse
129-
assertFalse(response instanceof StructuredMessageDecoderPolicy.DecodedResponse);
130+
assertFalse(response instanceof StorageContentValidationDecoderPolicy.DecodedResponse);
130131
})
131132
.verifyComplete();
132133
}
@@ -138,10 +139,10 @@ private HttpPipelineCallContext createMockContext(Context ctx, Long contentLengt
138139
when(context.getHttpRequest()).thenReturn(request);
139140

140141
if (ctx != null) {
141-
when(context.getData(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY))
142-
.thenReturn(ctx.getData(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY));
143-
when(context.getData(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY))
144-
.thenReturn(ctx.getData(StructuredMessageDecoderPolicy.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY));
142+
when(context.getData(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY))
143+
.thenReturn(ctx.getData(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY));
144+
when(context.getData(Constants.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY))
145+
.thenReturn(ctx.getData(Constants.STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY));
145146
} else {
146147
when(context.getData(any())).thenReturn(java.util.Optional.empty());
147148
}

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/Constants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ public final class Constants {
9494

9595
public static final String SKIP_ECHO_VALIDATION_KEY = "skipEchoValidation";
9696

97+
/**
98+
* Context key used to signal that structured message decoding should be applied.
99+
*/
100+
public static final String STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY = "azure-storage-structured-message-decoding";
101+
102+
/**
103+
* Context key used to pass DownloadContentValidationOptions to the policy.
104+
*/
105+
public static final String STRUCTURED_MESSAGE_VALIDATION_OPTIONS_CONTEXT_KEY =
106+
"azure-storage-structured-message-validation-options";
107+
97108
private Constants() {
98109
}
99110

0 commit comments

Comments
 (0)