diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml
index b39b25ffc59c..9f2ab7237ea1 100755
--- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml
+++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml
@@ -473,6 +473,7 @@
+
+
+
+
+
+
+
@@ -603,11 +610,11 @@
-
+
-
+
diff --git a/eng/code-quality-reports/src/main/resources/revapi/revapi.json b/eng/code-quality-reports/src/main/resources/revapi/revapi.json
index bc69bcd19c16..c5ead03aa977 100644
--- a/eng/code-quality-reports/src/main/resources/revapi/revapi.json
+++ b/eng/code-quality-reports/src/main/resources/revapi/revapi.json
@@ -235,6 +235,17 @@
"code": "java\\.class\\.externalClassExposedInAPI",
"new": "(interface|class|enum) io\\.opentelemetry.*",
"justification": "Azure Monitor Exporter is allowed to use OpenTelemetry types in public APIs as it implements interfaces defined by OpenTelemetry"
+ },
+ {
+ "code": "java.annotation.attributeAdded",
+ "old": "class com.azure.messaging.eventhubs.EventHubClientBuilder",
+ "new": "class com.azure.messaging.eventhubs.EventHubClientBuilder",
+ "justification": "Setting protocol to AMQP in @ServiceClientBuilder annotation is not a breaking change"
+ },
+ {
+ "code": "java.annotation.added",
+ "new": "class com.azure.storage.blob.models.PageList",
+ "justification": "Annotation required to resolve deserialization bug."
}
]
}
diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml
index 9c83c11e658b..05a4da3620ee 100755
--- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml
+++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml
@@ -1333,6 +1333,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2441,4 +2458,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/eng/common/README.md b/eng/common/README.md
index e63b74367b74..7bda6ec94208 100644
--- a/eng/common/README.md
+++ b/eng/common/README.md
@@ -20,7 +20,6 @@ The 'Sync eng/common directory' PRs will be created in the language repositories
3. The `azure-sdk-tools - sync - eng-common` pipeline queues test runs for template pipelines in various languages. These help you test your changes in the **Tools PR**.
4. If there are changes in the **Tools PR** that will affect the release stage you should approve the release test pipelines by clicking the approval gate. The test (template) pipeline will automatically release the next eligible version without needing manual intervention for the versioning. Please approve your test releases as quickly as possible. A race condition may occur due to someone else queueing the pipeline and going all the way to release using your version while yours is still waiting. If this occurs manually rerun the pipeline that failed.
5. If you make additional changes to your **Tools PR** repeat steps 1 - 4 until you have completed the necessary testing of your changes. This includes full releases of the template package, if necessary.
-6. Sign off on CreateSyncPRs stage of the sync pipeline using the approval gate. This stage will create the **Sync PRs** in the various language repos with the `auto-merge` label applied. A link to each of the **Sync PRs** will show up in the **Tools PR** for you to click and review.
-7. Go review and approve each of your **Sync PRs**. The merging will happen automatically.
-8. Sign off on VerifyAndMerge stage of the sync pipeline using the approval gate. This stage will merge any remaining open **Sync PRs** and also append `auto-merge` to the **Tools PR** so it will automatically merge once the pipeline finishes.
-7. Sign Off on the VerifyAndMerge stage. This will merge any remaining open **Sync PR** and also append `auto-merge` to the **Tools PR**.
+6. Sign off on CreateSyncPRs stage of the sync pipeline using the approval gate. This stage will create the **Sync PRs** in the various language repos. A link to each of the **Sync PRs** will show up in the **Tools PR** for you to click and review.
+7. Go review and approve each of your **Sync PRs**.
+8. Sign Off on the VerifyAndMerge stage. This will merge any remaining open **Sync PR** and also append `auto-merge` to the **Tools PR**.
diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md
index 6fc15eefdb49..c41693c87666 100644
--- a/eng/common/TestResources/New-TestResources.ps1.md
+++ b/eng/common/TestResources/New-TestResources.ps1.md
@@ -449,7 +449,7 @@ Accept wildcard characters: False
```
### CommonParameters
-This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
+This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
diff --git a/eng/common/TestResources/Remove-TestResources.ps1.md b/eng/common/TestResources/Remove-TestResources.ps1.md
index 18317cec07cc..8c99997e0731 100644
--- a/eng/common/TestResources/Remove-TestResources.ps1.md
+++ b/eng/common/TestResources/Remove-TestResources.ps1.md
@@ -263,7 +263,7 @@ Accept wildcard characters: False
```
### CommonParameters
-This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
+This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
diff --git a/eng/common/pipelines/templates/steps/docs-metadata-release.yml b/eng/common/pipelines/templates/steps/docs-metadata-release.yml
index 2b57bcf7f413..45f12580f10e 100644
--- a/eng/common/pipelines/templates/steps/docs-metadata-release.yml
+++ b/eng/common/pipelines/templates/steps/docs-metadata-release.yml
@@ -8,8 +8,8 @@ parameters:
ScriptDirectory: eng/common/scripts
TargetDocRepoName: ''
TargetDocRepoOwner: ''
- PRBranchName: 'smoke-test-rdme'
- SourceBranchName: 'smoke-test'
+ PRBranchName: 'master-rdme'
+ SourceBranchName: 'master'
PRLabels: 'auto-merge'
ArtifactName: ''
Language: ''
diff --git a/eng/common/scripts/Delete-RemoteBranches.ps1 b/eng/common/scripts/Delete-RemoteBranches.ps1
index 0ca7c55be932..77cf7e506461 100644
--- a/eng/common/scripts/Delete-RemoteBranches.ps1
+++ b/eng/common/scripts/Delete-RemoteBranches.ps1
@@ -9,7 +9,7 @@ param(
LogDebug "Operating on Repo [ $RepoName ]"
try{
- $branches = (Get-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix").ref
+ $branches = (Get-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref "heads/$BranchPrefix" -AuthToken $AuthToken).ref
}
catch {
LogError "Get-GitHubSourceReferences failed with exception:`n$_"
@@ -22,7 +22,7 @@ foreach ($branch in $branches)
$branchName = $branch.Replace("refs/heads/","")
$head = "${RepoOwner}/${RepoName}:${branchName}"
LogDebug "Operating on branch [ $branchName ]"
- $pullRequests = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -head $head
+ $pullRequests = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName -State "all" -Head $head -AuthToken $AuthToken
}
catch
{
@@ -30,9 +30,9 @@ foreach ($branch in $branches)
exit 1
}
- if ($pullRequests.Count -eq 0)
+ if ($pullRequests -and (($pullRequests | ? { $_.State -eq "open" }).Count -eq 0))
{
- LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated Pull Request. Deleting Branch"
+ LogDebug "Branch [ $branchName ] in repo [ $RepoName ] has no associated open Pull Request. Deleting Branch"
try{
Remove-GitHubSourceReferences -RepoOwner $RepoOwner -RepoName $RepoName -Ref ($branch.Remove(0,5)) -AuthToken $AuthToken
}
diff --git a/eng/common/scripts/Verify-Links.ps1 b/eng/common/scripts/Verify-Links.ps1
index 9376564e3472..c9991a058894 100644
--- a/eng/common/scripts/Verify-Links.ps1
+++ b/eng/common/scripts/Verify-Links.ps1
@@ -200,6 +200,10 @@ function CheckLink ([System.Uri]$linkUri)
}
if ($checkLinkGuidance) {
+ if ($linkUri.Scheme -eq 'http') {
+ LogWarning "DO NOT use 'http' in $linkUri. Please use secure link with https instead. Check here for more information: https://aka.ms/azsdk/guideline/links"
+ $linkValid = $false
+ }
$link = $linkUri.ToString()
# Check if the url is relative links, suppress the archor link validation.
if (!$linkUri.IsAbsoluteUri -and !$link.StartsWith("#")) {
diff --git a/sdk/communication/azure-communication-administration/pom.xml b/sdk/communication/azure-communication-administration/pom.xml
index 5bda961599a0..951bea5a2777 100644
--- a/sdk/communication/azure-communication-administration/pom.xml
+++ b/sdk/communication/azure-communication-administration/pom.xml
@@ -57,12 +57,6 @@
azure-core1.9.0
-
- com.azure
- azure-core-http-netty
- 1.6.2
- test
- com.azureazure-communication-common
diff --git a/sdk/communication/azure-communication-chat/pom.xml b/sdk/communication/azure-communication-chat/pom.xml
index 2c44b8fc24f5..666eee2cab2d 100644
--- a/sdk/communication/azure-communication-chat/pom.xml
+++ b/sdk/communication/azure-communication-chat/pom.xml
@@ -51,12 +51,6 @@
azure-communication-administration1.0.0-beta.3
-
- com.azure
- azure-core-http-netty
- 1.6.2
- test
- com.azureazure-core-test
diff --git a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatClientTestBase.java b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatClientTestBase.java
index 8f5b5eb87c58..5e158ff24597 100644
--- a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatClientTestBase.java
+++ b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatClientTestBase.java
@@ -11,16 +11,12 @@
import com.azure.communication.chat.models.*;
import com.azure.communication.common.CommunicationUserCredential;
import com.azure.core.exception.HttpResponseException;
-import com.azure.core.http.policy.FixedDelay;
-import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.HttpClient;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestMode;
import com.azure.core.util.Configuration;
import com.azure.core.util.logging.ClientLogger;
-
-import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -44,8 +40,6 @@ public class ChatClientTestBase extends TestBase {
protected static final String CONNSTRING = Configuration.getGlobalConfiguration()
.get("COMMUNICATION_SERVICES_CONNECTION_STRING", "pw==");
- protected static final FixedDelay RETRY_STRATEGY = new FixedDelay(3, Duration.ofMillis(1000));
-
protected ChatClientBuilder getChatClientBuilder(String token, HttpClient httpClient) {
ChatClientBuilder builder = new ChatClientBuilder();
@@ -60,10 +54,7 @@ protected ChatClientBuilder getChatClientBuilder(String token, HttpClient httpCl
builder.credential(new CommunicationUserCredential(token));
}
- if (interceptorManager.isLiveMode()) {
- builder.addPolicy(new RetryPolicy(RETRY_STRATEGY));
- }
- else {
+ if (getTestMode() == TestMode.RECORD) {
builder.addPolicy(interceptorManager.getRecordPolicy());
}
diff --git a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatThreadAsyncClientTest.java b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatThreadAsyncClientTest.java
index 4de7058cccc6..ecbf507a668b 100644
--- a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatThreadAsyncClientTest.java
+++ b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatThreadAsyncClientTest.java
@@ -5,6 +5,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@@ -176,8 +178,7 @@ public void canAddListAndRemoveMembersWithResponseAsync(HttpClient httpClient) t
}
assertTrue(returnedMembers.size() == 4);
- })
- .verifyComplete();
+ });
for (ChatThreadMember member: options.getMembers()) {
StepVerifier.create(chatThreadClient.removeMemberWithResponse(member.getUser()))
@@ -408,6 +409,9 @@ public void canSendTypingNotificationWithResponse(HttpClient httpClient) {
@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
+ @DisabledIfEnvironmentVariable(
+ named = "SKIP_LIVE_TEST",
+ matches = "(?i)(true)")
public void canSendThenListReadReceipts(HttpClient httpClient) throws InterruptedException {
// Arrange
setupTest(httpClient);
@@ -431,16 +435,16 @@ public void canSendThenListReadReceipts(HttpClient httpClient) throws Interrupte
assertEquals(resp.getStatusCode(), 200);
resp.getItems().forEach(item -> returnedReadReceipts.add(item));
});
-
- if (interceptorManager.isPlaybackMode()) {
- assertTrue(returnedReadReceipts.size() > 0);
- checkReadReceiptListContainsMessageId(returnedReadReceipts, messageResponseRef.get().getId());
- }
+ assertTrue(returnedReadReceipts.size() > 0);
+ checkReadReceiptListContainsMessageId(returnedReadReceipts, messageResponseRef.get().getId());
});
}
@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
+ @DisabledIfEnvironmentVariable(
+ named = "SKIP_LIVE_TEST",
+ matches = "(?i)(true)")
public void canSendThenListReadReceiptsWithResponse(HttpClient httpClient) throws InterruptedException {
// Arrange
setupTest(httpClient);
@@ -466,12 +470,9 @@ public void canSendThenListReadReceiptsWithResponse(HttpClient httpClient) throw
resp.getItems().forEach(item -> returnedReadReceipts.add(item));
});
- if (interceptorManager.isPlaybackMode()) {
- assertTrue(returnedReadReceipts.size() > 0);
- checkReadReceiptListContainsMessageId(returnedReadReceipts, messageResponseRef.get().getId());
- }
- })
- .verifyComplete();
+ assertTrue(returnedReadReceipts.size() > 0);
+ checkReadReceiptListContainsMessageId(returnedReadReceipts, messageResponseRef.get().getId());
+ });
}
}
diff --git a/sdk/communication/tests.yml b/sdk/communication/tests.yml
index a35bb4f6fb49..a435579fb140 100644
--- a/sdk/communication/tests.yml
+++ b/sdk/communication/tests.yml
@@ -9,8 +9,10 @@ jobs:
safeName: azurecommunicationadministration
- name: azure-communication-chat
groupId: com.azure
- safeName: azurecommunicationchatclient
+ safeName: azurecommunicationchat
ServiceDirectory: communication
EnvVars:
AZURE_TEST_MODE: LIVE
SKIP_PHONENUMBER_INTEGRATION_TESTS: TRUE
+ SKIP_LIVE_TEST: TRUE
+
diff --git a/sdk/compute/mgmt-v2017_09_01/pom.xml b/sdk/compute/mgmt-v2017_09_01/pom.xml
index 512ed7415d5f..ff10be84ec04 100644
--- a/sdk/compute/mgmt-v2017_09_01/pom.xml
+++ b/sdk/compute/mgmt-v2017_09_01/pom.xml
@@ -11,15 +11,15 @@
com.microsoft.azureazure-arm-parent
- 1.2.0
- ../../parents/azure-arm-parent
+ 1.1.0
+ ../../../pom.management.xmlazure-mgmt-compute1.0.0-betajarMicrosoft Azure SDK for Compute ManagementThis package contains Microsoft Compute Management SDK.
- https://github.com/Azure/azure-libraries-for-java
+ https://github.com/Azure/azure-sdk-for-javaThe MIT License (MIT)
@@ -28,8 +28,8 @@
- scm:git:https://github.com/Azure/azure-libraries-for-java
- scm:git:git@github.com:Azure/azure-libraries-for-java.git
+ scm:git:https://github.com/Azure/azure-sdk-for-java
+ scm:git:git@github.com:Azure/azure-sdk-for-java.gitHEAD
@@ -71,6 +71,8 @@
azure-arm-client-runtimetest-jartest
+
+ 1.6.5
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapabilities.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapabilities.java
index 01c94ba90cea..b877a757d633 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapabilities.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapabilities.java
@@ -11,7 +11,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
/**
- * Describes The SKU capabilites object.
+ * Describes The SKU capabilities object.
*/
public class ResourceSkuCapabilities {
/**
@@ -27,7 +27,7 @@ public class ResourceSkuCapabilities {
private String value;
/**
- * Get the name value.
+ * Get an invariant to describe the feature.
*
* @return the name value
*/
@@ -36,7 +36,7 @@ public String name() {
}
/**
- * Get the value value.
+ * Get an invariant if the feature is measured by quantity.
*
* @return the value value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapacity.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapacity.java
index 0a164a574154..bae4e0326b52 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapacity.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCapacity.java
@@ -40,7 +40,7 @@ public class ResourceSkuCapacity {
private ResourceSkuCapacityScaleType scaleType;
/**
- * Get the minimum value.
+ * Get the minimum capacity.
*
* @return the minimum value
*/
@@ -49,7 +49,7 @@ public Long minimum() {
}
/**
- * Get the maximum value.
+ * Get the maximum capacity that can be set.
*
* @return the maximum value
*/
@@ -58,7 +58,7 @@ public Long maximum() {
}
/**
- * Get the defaultProperty value.
+ * Get the default capacity.
*
* @return the defaultProperty value
*/
@@ -67,7 +67,7 @@ public Long defaultProperty() {
}
/**
- * Get the scaleType value.
+ * Get the scale type applicable to the sku. Possible values include: 'Automatic', 'Manual', 'None'.
*
* @return the scaleType value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCosts.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCosts.java
index 65f7e352fdbc..ea00d71771c2 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCosts.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuCosts.java
@@ -33,7 +33,7 @@ public class ResourceSkuCosts {
private String extendedUnit;
/**
- * Get the meterID value.
+ * Get used for querying price from commerce.
*
* @return the meterID value
*/
@@ -42,7 +42,7 @@ public String meterID() {
}
/**
- * Get the quantity value.
+ * Get the multiplier is needed to extend the base metered cost.
*
* @return the quantity value
*/
@@ -51,7 +51,7 @@ public Long quantity() {
}
/**
- * Get the extendedUnit value.
+ * Get an invariant to show the extended unit.
*
* @return the extendedUnit value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuLocationInfo.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuLocationInfo.java
index 1e205d572573..4c3a86ebb0e4 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuLocationInfo.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuLocationInfo.java
@@ -28,7 +28,7 @@ public class ResourceSkuLocationInfo {
private List zones;
/**
- * Get the location value.
+ * Get location of the SKU.
*
* @return the location value
*/
@@ -37,7 +37,7 @@ public String location() {
}
/**
- * Get the zones value.
+ * Get list of availability zones where the SKU is supported.
*
* @return the zones value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictionInfo.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictionInfo.java
index e539c9d6b63c..ea3f4b180536 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictionInfo.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictionInfo.java
@@ -28,7 +28,7 @@ public class ResourceSkuRestrictionInfo {
private List zones;
/**
- * Get the locations value.
+ * Get locations where the SKU is restricted.
*
* @return the locations value
*/
@@ -37,7 +37,7 @@ public List locations() {
}
/**
- * Get the zones value.
+ * Get list of availability zones where the SKU is restricted.
*
* @return the zones value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictions.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictions.java
index 6a32797609df..e7a4794c43b8 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictions.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/ResourceSkuRestrictions.java
@@ -42,7 +42,7 @@ public class ResourceSkuRestrictions {
private ResourceSkuRestrictionsReasonCode reasonCode;
/**
- * Get the type value.
+ * Get the type of restrictions. Possible values include: 'Location', 'Zone'.
*
* @return the type value
*/
@@ -51,7 +51,7 @@ public ResourceSkuRestrictionsType type() {
}
/**
- * Get the values value.
+ * Get the value of restrictions. If the restriction type is set to location. This would be different locations where the SKU is restricted.
*
* @return the values value
*/
@@ -60,7 +60,7 @@ public List values() {
}
/**
- * Get the restrictionInfo value.
+ * Get the information about the restriction where the SKU cannot be used.
*
* @return the restrictionInfo value
*/
@@ -69,7 +69,7 @@ public ResourceSkuRestrictionInfo restrictionInfo() {
}
/**
- * Get the reasonCode value.
+ * Get the reason for restriction. Possible values include: 'QuotaId', 'NotAvailableForSubscription'.
*
* @return the reasonCode value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ComputeManagementClientImpl.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ComputeManagementClientImpl.java
index 681827e15dd0..8cf4c58e73cb 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ComputeManagementClientImpl.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ComputeManagementClientImpl.java
@@ -63,11 +63,11 @@ public String apiVersion() {
return this.apiVersion;
}
- /** Gets or sets the preferred language for the response. */
+ /** The preferred language for the response. */
private String acceptLanguage;
/**
- * Gets Gets or sets the preferred language for the response.
+ * Gets The preferred language for the response.
*
* @return the acceptLanguage value.
*/
@@ -76,7 +76,7 @@ public String acceptLanguage() {
}
/**
- * Sets Gets or sets the preferred language for the response.
+ * Sets The preferred language for the response.
*
* @param acceptLanguage the acceptLanguage value.
* @return the service client itself
@@ -86,11 +86,11 @@ public ComputeManagementClientImpl withAcceptLanguage(String acceptLanguage) {
return this;
}
- /** Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. */
+ /** The retry timeout in seconds for Long Running Operations. Default value is 30. */
private int longRunningOperationRetryTimeout;
/**
- * Gets Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30.
+ * Gets The retry timeout in seconds for Long Running Operations. Default value is 30.
*
* @return the longRunningOperationRetryTimeout value.
*/
@@ -99,7 +99,7 @@ public int longRunningOperationRetryTimeout() {
}
/**
- * Sets Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30.
+ * Sets The retry timeout in seconds for Long Running Operations. Default value is 30.
*
* @param longRunningOperationRetryTimeout the longRunningOperationRetryTimeout value.
* @return the service client itself
@@ -109,11 +109,11 @@ public ComputeManagementClientImpl withLongRunningOperationRetryTimeout(int long
return this;
}
- /** When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. */
+ /** Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. */
private boolean generateClientRequestId;
/**
- * Gets When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.
+ * Gets Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.
*
* @return the generateClientRequestId value.
*/
@@ -122,7 +122,7 @@ public boolean generateClientRequestId() {
}
/**
- * Sets When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.
+ * Sets Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.
*
* @param generateClientRequestId the generateClientRequestId value.
* @return the service client itself
@@ -191,6 +191,6 @@ protected void initialize() {
*/
@Override
public String userAgent() {
- return String.format("%s (%s, %s)", super.userAgent(), "ComputeManagementClient", "2017-09-01");
+ return String.format("%s (%s, %s, auto-generated)", super.userAgent(), "ComputeManagementClient", "2017-09-01");
}
}
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkuInner.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkuInner.java
index cc07679eb97e..da5b155234ac 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkuInner.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkuInner.java
@@ -103,7 +103,7 @@ public class ResourceSkuInner {
private List restrictions;
/**
- * Get the resourceType value.
+ * Get the type of resource the SKU applies to.
*
* @return the resourceType value
*/
@@ -112,7 +112,7 @@ public String resourceType() {
}
/**
- * Get the name value.
+ * Get the name of SKU.
*
* @return the name value
*/
@@ -121,7 +121,7 @@ public String name() {
}
/**
- * Get the tier value.
+ * Get specifies the tier of virtual machines in a scale set.<br /><br /> Possible Values:<br /><br /> **Standard**<br /><br /> **Basic**.
*
* @return the tier value
*/
@@ -130,7 +130,7 @@ public String tier() {
}
/**
- * Get the size value.
+ * Get the Size of the SKU.
*
* @return the size value
*/
@@ -139,7 +139,7 @@ public String size() {
}
/**
- * Get the family value.
+ * Get the Family of this particular SKU.
*
* @return the family value
*/
@@ -148,7 +148,7 @@ public String family() {
}
/**
- * Get the kind value.
+ * Get the Kind of resources that are supported in this SKU.
*
* @return the kind value
*/
@@ -157,7 +157,7 @@ public String kind() {
}
/**
- * Get the capacity value.
+ * Get specifies the number of virtual machines in the scale set.
*
* @return the capacity value
*/
@@ -166,7 +166,7 @@ public ResourceSkuCapacity capacity() {
}
/**
- * Get the locations value.
+ * Get the set of locations that the SKU is available.
*
* @return the locations value
*/
@@ -175,7 +175,7 @@ public List locations() {
}
/**
- * Get the locationInfo value.
+ * Get a list of locations and availability zones in those locations where the SKU is available.
*
* @return the locationInfo value
*/
@@ -184,7 +184,7 @@ public List locationInfo() {
}
/**
- * Get the apiVersions value.
+ * Get the api versions that support this SKU.
*
* @return the apiVersions value
*/
@@ -193,7 +193,7 @@ public List apiVersions() {
}
/**
- * Get the costs value.
+ * Get metadata for retrieving price info.
*
* @return the costs value
*/
@@ -202,7 +202,7 @@ public List costs() {
}
/**
- * Get the capabilities value.
+ * Get a name value pair to describe the capability.
*
* @return the capabilities value
*/
@@ -211,7 +211,7 @@ public List capabilities() {
}
/**
- * Get the restrictions value.
+ * Get the restrictions because of which SKU cannot be used. This is empty if there are no restrictions.
*
* @return the restrictions value
*/
diff --git a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkusImpl.java b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkusImpl.java
index a9f341529dea..68d8220ac874 100644
--- a/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkusImpl.java
+++ b/sdk/compute/mgmt-v2017_09_01/src/main/java/com/microsoft/azure/management/compute/v2017_09_01/implementation/ResourceSkusImpl.java
@@ -37,7 +37,8 @@ public Observable listAsync() {
public Iterable call(Page page) {
return page.items();
}
- }) .map(new Func1() {
+ })
+ .map(new Func1() {
@Override
public ResourceSku call(ResourceSkuInner inner) {
return new ResourceSkuImpl(inner, manager());
diff --git a/sdk/core/azure-core-experimental/CHANGELOG.md b/sdk/core/azure-core-experimental/CHANGELOG.md
index 369cd8bcefe5..9ed249c7810f 100644
--- a/sdk/core/azure-core-experimental/CHANGELOG.md
+++ b/sdk/core/azure-core-experimental/CHANGELOG.md
@@ -2,6 +2,7 @@
## 1.0.0-beta.7 (2020-10-08)
+- Added API `fromObject()` in `BinaryData` which uses `JsonSerializer` present in the classpath.
- Added APIs to `JsonPatchDocument` which accept pre-serialized JSON.
- Updated `azure-core` dependency to released version.
diff --git a/sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java b/sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
index 2979599d21ca..060cda67f27b 100644
--- a/sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
+++ b/sdk/core/azure-core-experimental/src/main/java/com/azure/core/experimental/util/BinaryData.java
@@ -5,7 +5,9 @@
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
+import com.azure.core.util.serializer.JsonSerializerProviders;
import com.azure.core.util.serializer.ObjectSerializer;
+import com.azure.core.util.serializer.JsonSerializer;
import com.azure.core.util.serializer.TypeReference;
import static com.azure.core.util.FluxUtil.monoError;
@@ -18,18 +20,20 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
/**
* This class is an abstraction over many different ways that binary data can be represented. The {@link BinaryData}
- * can be created from {@link InputStream}, {@link Flux} of {@link ByteBuffer}, {@link String}, {@link Object} and byte
- * array. The data is collected from provided sources and stored into a byte array.
+ * can be created from {@link InputStream}, {@link Flux} of {@link ByteBuffer}, {@link String}, {@link Object}, or byte
+ * array.
+ *
Immutable data
+ * {@link BinaryData} is constructed by copying the given data. Once {@link BinaryData} is instantiated, it can not be
+ * changed. It provides various convenient APIs to get data out of {@link BinaryData}, they all start with the 'to'
+ * prefix, for example {@link BinaryData#toBytes()}.
*
- * It also provides a way to serialize and deserialize an {@link Object} into {@link BinaryData} given an
- * {@link ObjectSerializer}. Code samples are explained below.
+ * Code samples are presented below.
*
*
+ * {@codesnippet com.azure.core.experimental.util.BinaryDocument.from#Object}
+ *
* @see ObjectSerializer
+ * @see JsonSerializer
+ * @see More about serialization
*/
public final class BinaryData {
private static final ClientLogger LOGGER = new ClientLogger(BinaryData.class);
- private final byte[] data;
+ private static final BinaryData EMPTY_DATA = new BinaryData(new byte[0]);
- /**
- * Create instance of {@link BinaryData} given the data.
- * @param data to represent as bytes.
- * @throws NullPointerException If {@code data} is null.
- */
- BinaryData(byte[] data) {
- Objects.requireNonNull(data, "'data' cannot be null.");
- this.data = Arrays.copyOf(data, data.length);
- }
+ private static final Object LOCK = new Object();
- /**
- * Provides {@link InputStream} for the data represented by this {@link BinaryData} object.
- *
- *
Get InputStream from BinaryData
- * {@codesnippet com.azure.core.experimental.util.BinaryDocument.to#Stream}
- *
- * @return {@link InputStream} representing the binary data.
- */
- public InputStream toStream() {
- return new ByteArrayInputStream(this.data);
- }
+ private final byte[] data;
+
+ private static volatile JsonSerializer defaultJsonSerializer;
/**
- * Provides {@link Mono} of {@link InputStream} for the data represented by this {@link BinaryData} object.
+ * Create an instance of {@link BinaryData} from the given data.
*
- * @return {@link InputStream} representation of the {@link BinaryData}.
+ * @param data to represent as bytes.
*/
- public Mono toStreamAsync() {
- return Mono.fromCallable(() -> toStream());
+ BinaryData(byte[] data) {
+ this.data = data;
}
/**
- * Create {@link BinaryData} instance with given {@link InputStream} as source of data. The {@link InputStream} is
- * not closed by this function.
+ * Creates a {@link BinaryData} instance with given {@link InputStream} as source of data. The {@link InputStream}
+ * is not closed by this function.
*
*
Create an instance from InputStream
* {@codesnippet com.azure.core.experimental.util.BinaryDocument.from#Stream}
*
* @param inputStream to read bytes from.
* @throws UncheckedIOException If any error in reading from {@link InputStream}.
- * @throws NullPointerException if {@code inputStream} is null.
+ * @throws NullPointerException If {@code inputStream} is null.
* @return {@link BinaryData} representing the binary data.
*/
public static BinaryData fromStream(InputStream inputStream) {
- Objects.requireNonNull(inputStream, "'inputStream' cannot be null.");
+ if (Objects.isNull(inputStream)) {
+ return EMPTY_DATA;
+ }
final int bufferSize = 1024;
try {
@@ -103,98 +98,125 @@ public static BinaryData fromStream(InputStream inputStream) {
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
dataOutputBuffer.write(data, 0, nRead);
}
+ dataOutputBuffer.flush();
+
+ return new BinaryData(dataOutputBuffer.toByteArray());
- return fromBytes(dataOutputBuffer.toByteArray());
} catch (IOException ex) {
throw LOGGER.logExceptionAsError(new UncheckedIOException(ex));
}
}
/**
- * Asynchronously create {@link BinaryData} instance with given {@link InputStream} as source of data. The
- * {@link InputStream} is not closed by this function.
+ * Asynchronously creates a {@link BinaryData} instance with the given {@link InputStream} as source of data. The
+ * {@link InputStream} is not closed by this function. If the {@link InputStream} is {@code null}, an empty
+ * {@link BinaryData} will be returned.
*
* @param inputStream to read bytes from.
- * @throws NullPointerException if {@code inputStream} is null.
* @return {@link Mono} of {@link BinaryData} representing the binary data.
*/
public static Mono fromStreamAsync(InputStream inputStream) {
- Objects.requireNonNull(inputStream, "'inputStream' cannot be null.");
-
return Mono.fromCallable(() -> fromStream(inputStream));
}
/**
- * Create {@link BinaryData} instance with given {@link Flux} of {@link ByteBuffer} as source of data. It will
- * collect all the bytes from {@link ByteBuffer} into {@link BinaryData}.
+ * Creates a {@link BinaryData} instance with given {@link Flux} of {@link ByteBuffer} as source of data. It will
+ * collect all the bytes from {@link ByteBuffer} into {@link BinaryData}. If the {@link Flux} is {@code null}, an
+ * empty {@link BinaryData} will be returned.
*
*
Create an instance from String
* {@codesnippet com.azure.core.experimental.util.BinaryDocument.from#Flux}
*
* @param data to use.
- * @throws NullPointerException if {@code inputStream} is null.
* @return {@link Mono} of {@link BinaryData} representing binary data.
*/
public static Mono fromFlux(Flux data) {
if (Objects.isNull(data)) {
- return monoError(LOGGER, new NullPointerException("'data' cannot be null."));
+ return Mono.just(EMPTY_DATA);
}
return FluxUtil.collectBytesInByteBufferStream(data)
- .flatMap(bytes -> Mono.just(fromBytes(bytes)));
+ .flatMap(bytes -> Mono.just(new BinaryData(bytes)));
}
/**
- * Create {@link BinaryData} instance with given data and character set.
- *
- *
Create an instance from String
- * {@codesnippet com.azure.core.experimental.util.BinaryDocument.from#String}
+ * Creates a {@link BinaryData} instance with given data. The {@link String} is converted into bytes using UTF_8
+ * character set. If the String is {@code null}, an empty {@link BinaryData} will be returned.
*
* @param data to use.
- * @param charSet to use.
- * @throws NullPointerException if {@code inputStream} is null.
- * @return {@link BinaryData} representing the binary data.
+ * @return {@link BinaryData} representing binary data.
*/
- public static BinaryData fromString(String data, Charset charSet) {
- Objects.requireNonNull(data, "'data' cannot be null.");
+ public static BinaryData fromString(String data) {
+ if (Objects.isNull(data) || data.length() == 0) {
+ return EMPTY_DATA;
+ }
- return new BinaryData(data.getBytes(charSet));
+ return new BinaryData(data.getBytes(StandardCharsets.UTF_8));
}
/**
- * Create {@link BinaryData} instance with given data. The {@link String} is converted into bytes using
- * {@link StandardCharsets#UTF_8} character set.
+ * Creates a {@link BinaryData} instance with given byte array data. If the byte array is {@code null}, an empty
+ * {@link BinaryData} will be returned.
*
* @param data to use.
- * @throws NullPointerException if {@code inputStream} is null.
- * @return {@link BinaryData} representing binary data.
+ * @return {@link BinaryData} representing the binary data.
*/
- public static BinaryData fromString(String data) {
- Objects.requireNonNull(data, "'data' cannot be null.");
+ public static BinaryData fromBytes(byte[] data) {
+ if (Objects.isNull(data) || data.length == 0) {
+ return EMPTY_DATA;
+ }
- return new BinaryData(data.getBytes(StandardCharsets.UTF_8));
+ return new BinaryData(Arrays.copyOf(data, data.length));
}
/**
- * Create {@link BinaryData} instance with given byte array data.
+ * Serialize the given {@link Object} into {@link BinaryData} using json serializer which is available on classpath.
+ * The serializer on classpath must implement {@link JsonSerializer} interface. If the given Object is {@code null},
+ * an empty {@link BinaryData} will be returned.
+ *
Code sample
+ * {@codesnippet com.azure.core.experimental.util.BinaryDocument.from.default.serializer#Object}
+
+ * @param data The {@link Object} which needs to be serialized into bytes.
+ * @throws IllegalStateException If a {@link JsonSerializer} cannot be found on the classpath.
+ * @return {@link BinaryData} representing the JSON serialized object.
*
- * @param data to use.
- * @return {@link BinaryData} representing the binary data.
+ * @see JsonSerializer
+ * @see More about serialization
*/
- public static BinaryData fromBytes(byte[] data) {
- return new BinaryData(data);
+ public static BinaryData fromObject(Object data) {
+ if (Objects.isNull(data)) {
+ return EMPTY_DATA;
+ }
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ getDefaultSerializer().serialize(outputStream, data);
+
+ return new BinaryData(outputStream.toByteArray());
}
/**
* Serialize the given {@link Object} into {@link BinaryData} using the provided {@link ObjectSerializer}.
+ * If the Object is {@code null}, an empty {@link BinaryData} will be returned.
+ *
You can provide your custom implementation of {@link ObjectSerializer} interface or use one provided in azure
+ * sdk by adding them as dependency. These implementations could be found at
+ * Json Jackson serializer
+ * and Gson based serializer.
+ *
+ *
Create an instance from Object
+ * {@codesnippet com.azure.core.experimental.util.BinaryDocument.from#Object}
*
* @param data The {@link Object} which needs to be serialized into bytes.
* @param serializer to use for serializing the object.
- * @throws NullPointerException if {@code inputStream} or {@code serializer} is null.
+ * @throws NullPointerException If {@code serializer} is null.
* @return {@link BinaryData} representing binary data.
+ * @see ObjectSerializer
+ * @see JsonSerializer
+ * @see More about serialization
*/
public static BinaryData fromObject(Object data, ObjectSerializer serializer) {
- Objects.requireNonNull(data, "'data' cannot be null.");
+ if (Objects.isNull(data)) {
+ return EMPTY_DATA;
+ }
+
Objects.requireNonNull(serializer, "'serializer' cannot be null.");
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -204,19 +226,25 @@ public static BinaryData fromObject(Object data, ObjectSerializer serializer) {
/**
* Serialize the given {@link Object} into {@link Mono} {@link BinaryData} using the provided
- * {@link ObjectSerializer}.
+ * {@link ObjectSerializer}. If the Object is {@code null}, an empty {@link BinaryData} will be returned.
+ *
+ *
You can provide your custom implementation of {@link ObjectSerializer} interface or use one provided in azure
+ * sdk by adding them as dependency. These implementations could be found at
+ * Json Jackson serializer
+ * and Gson based serializer.
*
* @param data The {@link Object} which needs to be serialized into bytes.
* @param serializer to use for serializing the object.
- * @throws NullPointerException if {@code inputStream} or {@code serializer} is null.
+ * @throws NullPointerException If {@code serializer} is null.
* @return {@link Mono} of {@link BinaryData} representing the binary data.
+ * @see ObjectSerializer
+ * @see More about serialization
*/
public static Mono fromObjectAsync(Object data, ObjectSerializer serializer) {
- Objects.requireNonNull(data, "'data' cannot be null.");
- Objects.requireNonNull(serializer, "'serializer' cannot be null.");
-
+ if (Objects.isNull(serializer)) {
+ return monoError(LOGGER, new NullPointerException("'serializer' cannot be null."));
+ }
return Mono.fromCallable(() -> fromObject(data, serializer));
-
}
/**
@@ -230,7 +258,7 @@ public byte[] toBytes() {
/**
* Provides {@link String} representation of this {@link BinaryData} object. The bytes are converted into
- * {@link String} using {@link StandardCharsets#UTF_8} character set.
+ * {@link String} using the UTF-8 character set.
*
* @return {@link String} representation of the data.
*/
@@ -238,23 +266,21 @@ public String toString() {
return new String(this.data, StandardCharsets.UTF_8);
}
- /**
- * Provides {@link String} representation of this {@link BinaryData} object given a character set.
- *
- * @param charSet to use to convert bytes into {@link String}.
- * @return {@link String} representation of the the binary data.
- */
- public String toString(Charset charSet) {
- return new String(this.data, charSet);
- }
-
/**
* Deserialize the bytes into the {@link Object} of given type by applying the provided {@link ObjectSerializer} on
* the data.
*
+ *
You can provide your custom implementation of {@link ObjectSerializer} interface or use one provided in azure
+ * sdk by adding them as dependency. These implementations could be found at
+ * Json Jackson serializer
+ * and Gson based serializer.
+ *
+ *
Code sample
+ * {@codesnippet com.azure.core.experimental.util.BinaryDocument.to#Object}
* @param clazz representing the type of the Object.
* @param serializer to use deserialize data into type.
* @param Generic type that the data is deserialized into.
+ * @throws NullPointerException If {@code serializer} or {@code clazz} is null.
* @return The {@link Object} of given type after deserializing the bytes.
*/
public T toObject(Class clazz, ObjectSerializer serializer) {
@@ -267,8 +293,13 @@ public T toObject(Class clazz, ObjectSerializer serializer) {
}
/**
- * Return a {@link Mono} by deserialize the bytes into the {@link Object} of given type after applying the provided
- * {@link ObjectSerializer} on the {@link BinaryData}.
+ * Return a {@link Mono} by deserializing the bytes into the {@link Object} of given type after applying the
+ * provided {@link ObjectSerializer} on the {@link BinaryData}.
+ *
+ *
You can provide your custom implementation of {@link ObjectSerializer} interface or use one provided in azure
+ * sdk by adding them as dependency. These implementations could be found at
+ * Json Jackson serializer
+ * and Gson based serializer.
*
*
Gets the specified object
* {@codesnippet com.azure.core.experimental.util.BinaryDocument.to#ObjectAsync}
@@ -276,10 +307,77 @@ public T toObject(Class clazz, ObjectSerializer serializer) {
* @param clazz representing the type of the Object.
* @param serializer to use deserialize data into type.
* @param Generic type that the data is deserialized into.
- * @throws NullPointerException if {@code clazz} or {@code serializer} is null.
+ * @throws NullPointerException If {@code clazz} or {@code serializer} is null.
* @return The {@link Object} of given type after deserializing the bytes.
*/
public Mono toObjectAsync(Class clazz, ObjectSerializer serializer) {
+
+ if (Objects.isNull(clazz)) {
+ return monoError(LOGGER, new NullPointerException("'clazz' cannot be null."));
+ } else if (Objects.isNull(serializer)) {
+ return monoError(LOGGER, new NullPointerException("'serializer' cannot be null."));
+ }
return Mono.fromCallable(() -> toObject(clazz, serializer));
}
+
+ /**
+ * Deserialize the bytes into the {@link Object} of given type by using json serializer which is available in
+ * classpath. The serializer must implement {@link JsonSerializer} interface. A singleton instance of
+ * {@link JsonSerializer} is kept for this class to use.
+ *
+ * @param clazz representing the type of the Object.
+ * @param Generic type that the data is deserialized into.
+ * @throws NullPointerException If {@code clazz} is null.
+ * @return The {@link Object} of given type after deserializing the bytes.
+ */
+ public T toObject(Class clazz) {
+ Objects.requireNonNull(clazz, "'clazz' cannot be null.");
+
+ TypeReference ref = TypeReference.createInstance(clazz);
+ InputStream jsonStream = new ByteArrayInputStream(this.data);
+ return getDefaultSerializer().deserialize(jsonStream, ref);
+ }
+
+ /**
+ * Return a {@link Mono} by deserializing the bytes into the {@link Object} of given type after applying the Json
+ * serializer found on classpath.
+ *
+ *
Gets the specified object
+ * {@codesnippet com.azure.core.experimental.util.BinaryDocument.to#ObjectAsync}
+ *
+ * @param clazz representing the type of the Object.
+ * @param Generic type that the data is deserialized into.
+ * @throws NullPointerException If {@code clazz} is null.
+ * @return The {@link Object} of given type after deserializing the bytes.
+ */
+ public Mono toObjectAsync(Class clazz) {
+ if (Objects.isNull(clazz)) {
+ return monoError(LOGGER, new NullPointerException("'clazz' cannot be null."));
+ }
+ return Mono.fromCallable(() -> toObject(clazz));
+ }
+
+ /**
+ * Provides {@link InputStream} for the data represented by this {@link BinaryData} object.
+ *
+ *
Get InputStream from BinaryData
+ * {@codesnippet com.azure.core.experimental.util.BinaryDocument.to#Stream}
+ *
+ * @return {@link InputStream} representing the binary data.
+ */
+ public InputStream toStream() {
+ return new ByteArrayInputStream(this.data);
+ }
+
+ /* This will ensure lazy instantiation to avoid hard dependency on Json Serializer. */
+ private static JsonSerializer getDefaultSerializer() {
+ if (defaultJsonSerializer == null) {
+ synchronized (LOCK) {
+ if (defaultJsonSerializer == null) {
+ defaultJsonSerializer = JsonSerializerProviders.createInstance();
+ }
+ }
+ }
+ return defaultJsonSerializer;
+ }
}
diff --git a/sdk/core/azure-core-experimental/src/samples/java/com/azure/core/experimental/util/BinaryDateJavaDocCodeSnippet.java b/sdk/core/azure-core-experimental/src/samples/java/com/azure/core/experimental/util/BinaryDateJavaDocCodeSnippet.java
index d4999b654cf2..a7211d27ca89 100644
--- a/sdk/core/azure-core-experimental/src/samples/java/com/azure/core/experimental/util/BinaryDateJavaDocCodeSnippet.java
+++ b/sdk/core/azure-core-experimental/src/samples/java/com/azure/core/experimental/util/BinaryDateJavaDocCodeSnippet.java
@@ -58,8 +58,8 @@ public void createFromString() {
*/
public void createFromStream() {
// BEGIN: com.azure.core.experimental.util.BinaryDocument.from#Stream
- final byte[] data = "Some Data".getBytes(StandardCharsets.UTF_8);
- BinaryData binaryData = BinaryData.fromStream(new ByteArrayInputStream(data));
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream("Some Data".getBytes(StandardCharsets.UTF_8));
+ BinaryData binaryData = BinaryData.fromStream(inputStream);
System.out.println(binaryData.toString());
// END: com.azure.core.experimental.util.BinaryDocument.from#Stream
}
@@ -88,6 +88,40 @@ public void createFromFlux() throws InterruptedException {
// END: com.azure.core.experimental.util.BinaryDocument.from#Flux
}
+ /**
+ * Codesnippets for {@link BinaryData#fromObject(Object, ObjectSerializer)}.
+ */
+ public void createFromObject() {
+ // BEGIN: com.azure.core.experimental.util.BinaryDocument.from#Object
+ // Lets say we have Person object which could be serialized into json.
+ class Person {
+ @JsonProperty
+ private String name;
+
+ @JsonSetter
+ public Person setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @JsonGetter
+ public String getName() {
+ return name;
+ }
+ }
+ final Person data = new Person().setName("John");
+
+ // Provide your custom serializer or use Azure provided serializers.
+ // https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-jackson or
+ // https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-gson
+
+ final ObjectSerializer serializer =
+ new MyJsonSerializer(); // Replace this with your Serializer or from above libraries.
+ BinaryData binaryData = BinaryData.fromObject(data, serializer);
+ System.out.println(binaryData.toString());
+ // END: com.azure.core.experimental.util.BinaryDocument.from#Object
+ }
+
/**
* Codesnippets for {@link BinaryData#toStream()}.
*/
@@ -124,8 +158,7 @@ public String getName() {
}
final Person data = new Person().setName("John");
- // Ensure your classpath have the Serializer to use to serialize object. For example you can use one of
- // following library.
+ // Provide your custom serializer or use Azure provided serializers.
// https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-jackson or
// https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-gson
@@ -133,7 +166,6 @@ public String getName() {
new MyJsonSerializer(); // Replace this with your Serializer
BinaryData binaryData = BinaryData.fromObject(data, serializer);
- // Lets print the value of BinaryData
Disposable subscriber = binaryData
.toObjectAsync(Person.class, serializer)
.map(person -> {
@@ -148,6 +180,78 @@ public String getName() {
// END: com.azure.core.experimental.util.BinaryDocument.to#ObjectAsync
}
+ /**
+ * Codesnippets for {@link BinaryData#toObject(Class, ObjectSerializer)}.
+ */
+ public void createToObject() {
+ // BEGIN: com.azure.core.experimental.util.BinaryDocument.to#Object
+ // Lets say we have Person object which could be serialized into json.
+ class Person {
+ @JsonProperty
+ private String name;
+
+ @JsonSetter
+ public Person setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @JsonGetter
+ public String getName() {
+ return name;
+ }
+ }
+ final Person data = new Person().setName("John");
+
+ // Provide your custom serializer or use Azure provided serializers.
+ // https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-jackson or
+ // https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-gson
+
+ final ObjectSerializer serializer =
+ new MyJsonSerializer(); // Replace this with your Serializer
+ BinaryData binaryData = BinaryData.fromObject(data, serializer);
+
+ Person person = binaryData.toObject(Person.class, serializer);
+ // Lets print the name
+ System.out.println("Name : " + person.getName());
+
+ // END: com.azure.core.experimental.util.BinaryDocument.to#Object
+ }
+
+ /**
+ * Codesnippets for {@link BinaryData#fromObject(Object)}.
+ */
+ public void createFromObjectDefaultSerializer() {
+ // BEGIN: com.azure.core.experimental.util.BinaryDocument.from.default.serializer#Object
+ // Lets say we have Person object which could be serialized into json.
+ class Person {
+ @JsonProperty
+ private String name;
+
+ @JsonSetter
+ public Person setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @JsonGetter
+ public String getName() {
+ return name;
+ }
+ }
+ final Person data = new Person().setName("John");
+
+ // Ensure your classpath have the Serializer to serialize the object which implement implement
+ // com.azure.core.util.serializer.JsonSerializer interface.
+ // Or use Azure provided libraries for this.
+ // https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-jackson or
+ // https://mvnrepository.com/artifact/com.azure/azure-core-serializer-json-gson
+
+ BinaryData binaryData = BinaryData.fromObject(data);
+ System.out.println(binaryData.toString());
+ // END: com.azure.core.experimental.util.BinaryDocument.from.default.serializer#Object
+ }
+
public static class MyJsonSerializer implements JsonSerializer {
private final ClientLogger logger = new ClientLogger(BinaryDataTest.MyJsonSerializer.class);
private final ObjectMapper mapper;
@@ -192,4 +296,3 @@ public Mono serializeAsync(OutputStream stream, Object value) {
}
}
}
-
diff --git a/sdk/core/azure-core-experimental/src/test/java/com/azure/core/experimental/util/BinaryDataTest.java b/sdk/core/azure-core-experimental/src/test/java/com/azure/core/experimental/util/BinaryDataTest.java
index e0afe19e16d3..157b7d8ea094 100644
--- a/sdk/core/azure-core-experimental/src/test/java/com/azure/core/experimental/util/BinaryDataTest.java
+++ b/sdk/core/azure-core-experimental/src/test/java/com/azure/core/experimental/util/BinaryDataTest.java
@@ -85,34 +85,75 @@ public void createFromString() {
}
@Test
- public void createFromStringCharSet() {
+ public void createFromByteArray() {
// Arrange
- final String expected = "Doe";
+ final byte[] expected = "Doe".getBytes(StandardCharsets.UTF_8);
// Act
- final BinaryData data = BinaryData.fromString(expected, StandardCharsets.UTF_8);
+ final BinaryData data = new BinaryData(expected);
// Assert
- assertArrayEquals(expected.getBytes(), data.toBytes());
- assertEquals(expected, data.toString(StandardCharsets.UTF_8));
+ assertArrayEquals(expected, data.toBytes());
}
@Test
- public void createFromByteArray() {
+ public void createFromNullStream() throws IOException {
// Arrange
- final byte[] expected = "Doe".getBytes(StandardCharsets.UTF_8);
+ final byte[] expected = new byte[0];
// Act
- final BinaryData data = new BinaryData(expected);
+ BinaryData data = BinaryData.fromStream(null);
+ final byte[] actual = new byte[0];
+ (data.toStream()).read(actual, 0, expected.length);
// Assert
assertArrayEquals(expected, data.toBytes());
+ assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void createFromNullByteArray() {
+ // Arrange
+ final byte[] expected = new byte[0];
+
+ // Act
+ BinaryData actual = BinaryData.fromBytes(null);
+
+ // Assert
+ assertArrayEquals(expected, actual.toBytes());
+ }
+
+ @Test
+ public void createFromNullObject() {
+ // Arrange
+ final byte[] expected = new byte[0];
+
+ // Act
+ BinaryData actual = BinaryData.fromObject(null);
+
+ // Assert
+ assertArrayEquals(expected, actual.toBytes());
}
@Test
public void createFromStream() throws IOException {
// Arrange
final byte[] expected = "Doe".getBytes(StandardCharsets.UTF_8);
+
+ // Act
+ BinaryData data = BinaryData.fromStream(new ByteArrayInputStream(expected));
+ final byte[] actual = new byte[expected.length];
+ (data.toStream()).read(actual, 0, expected.length);
+
+ // Assert
+ assertArrayEquals(expected, data.toBytes());
+ assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void createFromEmptyStream() throws IOException {
+ // Arrange
+ final byte[] expected = "".getBytes();
final byte[] actual = new byte[expected.length];
// Act
@@ -140,7 +181,7 @@ public void createFromFlux() {
}
@Test
- public void createFromStreamAsync() throws IOException {
+ public void createFromStreamAsync() {
// Arrange
final byte[] expected = "Doe".getBytes(StandardCharsets.UTF_8);
@@ -152,27 +193,6 @@ public void createFromStreamAsync() throws IOException {
.verifyComplete();
}
- @Test
- public void createToStreamAsync() {
- // Arrange
- final byte[] expected = "Doe".getBytes(StandardCharsets.UTF_8);
- final BinaryData actual = BinaryData.fromStreamAsync(new ByteArrayInputStream(expected)).block();
- // Act & Assert
- StepVerifier.create(actual.toStreamAsync())
- .assertNext(inutStream -> {
- byte[] actualBytes = new byte[expected.length];
-
- // Act
- try {
- inutStream.read(actualBytes, 0, expected.length);
- } catch (IOException e) {
- e.printStackTrace();
- }
- Assertions.assertArrayEquals(expected, actualBytes);
- })
- .verifyComplete();
- }
-
@Test
public void createFromObjectAsync() {
// Arrange
@@ -189,6 +209,58 @@ public void createFromObjectAsync() {
.verifyComplete();
}
+
+ @Test
+ public void createFromEmptyString() {
+ // Arrange
+ final String expected = "";
+
+ // Act
+ final BinaryData data = BinaryData.fromString(expected);
+
+ // Assert
+ assertArrayEquals(expected.getBytes(), data.toBytes());
+ assertEquals(expected, data.toString());
+ }
+
+ @Test
+ public void createFromEmptyByteArray() {
+ // Arrange
+ final byte[] expected = new byte[0];
+
+ // Act
+ final BinaryData data = BinaryData.fromBytes(expected);
+
+ // Assert
+ assertArrayEquals(expected, data.toBytes());
+ }
+
+ @Test
+ public void createFromNullString() {
+ // Arrange
+ final String expected = null;
+
+ // Arrange & Act
+ final BinaryData data = BinaryData.fromString(expected);
+
+ // Assert
+ assertArrayEquals(new byte[0], data.toBytes());
+ assertEquals("", data.toString());
+ }
+
+ @Test
+ public void createFromNullByte() {
+ // Arrange
+ final byte[] expected = null;
+
+ // Arrange & Act
+ final BinaryData data = BinaryData.fromBytes(expected);
+
+ // Assert
+ assertArrayEquals(new byte[0], data.toBytes());
+ assertEquals("", data.toString());
+ }
+
public static class MyJsonSerializer implements JsonSerializer {
private final ClientLogger logger = new ClientLogger(MyJsonSerializer.class);
private final ObjectMapper mapper;
diff --git a/sdk/core/azure-core/pom.xml b/sdk/core/azure-core/pom.xml
index 62533be9e2e8..82714f23f444 100644
--- a/sdk/core/azure-core/pom.xml
+++ b/sdk/core/azure-core/pom.xml
@@ -183,6 +183,23 @@
+
+
+
+ com.github.spotbugs
+ spotbugs-maven-plugin
+ 3.1.12.2
+
+
+
+ com.h3xstream.findsecbugs
+ findsecbugs-plugin
+ 1.9.0
+
+
+
+
+
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/HttpClientProviders.java b/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/HttpClientProviders.java
index 96b3d24120c8..fe826da4c305 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/HttpClientProviders.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/HttpClientProviders.java
@@ -13,8 +13,11 @@
*/
public final class HttpClientProviders {
private static HttpClientProvider defaultProvider;
- private static final String CANNOT_FIND_HTTP_CLIENT =
- "Cannot find any HttpClient provider on the classpath - unable to create a default HttpClient instance";
+ private static final String CANNOT_FIND_HTTP_CLIENT = "A request was made to load the default HttpClient provider "
+ + "but one could not be found on the classpath. If you are using a dependency manager, consider including a "
+ + "dependency on azure-core-http-netty or azure-core-http-okhttp. Depending on your existing dependencies, you "
+ + "have the choice of Netty or OkHttp implementations. Additionally, refer to "
+ + "https://aka.ms/azsdk/java/docs/custom-httpclient to learn about writing your own implementation.";
static {
ServiceLoader serviceLoader = ServiceLoader.load(HttpClientProvider.class);
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocument.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocument.java
index 2fd4f3d7a7f9..7cdb9feff4f1 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocument.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocument.java
@@ -7,8 +7,7 @@
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.JsonSerializer;
import com.azure.core.util.serializer.JsonSerializerProviders;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonValue;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -20,19 +19,15 @@
/**
* Represents a JSON Patch document.
*/
-//@JsonSerialize(using = JsonPatchDocumentSerializer.class)
-public class JsonPatchDocument {
+@JsonSerialize(using = JsonPatchDocumentSerializer.class)
+public final class JsonPatchDocument {
private static final Object SERIALIZER_INSTANTIATION_SYNCHRONIZER = new Object();
private static volatile JsonSerializer defaultSerializer;
- @JsonIgnore
private final ClientLogger logger = new ClientLogger(JsonPatchDocument.class);
- @JsonValue
- private final List operations;
-
- @JsonIgnore
private final JsonSerializer serializer;
+ private final List operations;
/**
* Creates a new JSON Patch document.
@@ -53,7 +48,14 @@ public JsonPatchDocument(JsonSerializer serializer) {
this.serializer = serializer;
}
- List getOperations() {
+ /**
+ * Gets a representation of the {@link JsonPatchOperation JSON patch operations} in this JSON patch document.
+ *
+ * Modifications to the returned list won't mutate the operations in the document.
+ *
+ * @return The JSON patch operations in this JSON patch document.
+ */
+ public List getOperations() {
return new ArrayList<>(operations);
}
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocumentSerializer.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocumentSerializer.java
index 31eba6abd7d2..08e0ff8b4a92 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocumentSerializer.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchDocumentSerializer.java
@@ -13,7 +13,7 @@
/**
* Handles serialization of a {@link JsonPatchDocument}.
*/
-class JsonPatchDocumentSerializer extends JsonSerializer {
+final class JsonPatchDocumentSerializer extends JsonSerializer {
@Override
public void serialize(JsonPatchDocument value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperation.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperation.java
index cab3bd1528db..f9c6d9d18cf4 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperation.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperation.java
@@ -3,6 +3,7 @@
package com.azure.core.util;
+import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.Objects;
@@ -11,8 +12,9 @@
/**
* Represents a JSON Patch operation.
*/
+@Immutable
@JsonSerialize(using = JsonPatchOperationSerializer.class)
-final class JsonPatchOperation {
+public final class JsonPatchOperation {
private final JsonPatchOperationKind op;
private final String from;
private final String path;
@@ -41,7 +43,7 @@ final class JsonPatchOperation {
*
* @return The kind of operation.
*/
- JsonPatchOperationKind getOp() {
+ public JsonPatchOperationKind getOp() {
return op;
}
@@ -50,7 +52,7 @@ JsonPatchOperationKind getOp() {
*
* @return The operation from target path.
*/
- String getFrom() {
+ public String getFrom() {
return from;
}
@@ -59,16 +61,18 @@ String getFrom() {
*
* @return The operation target path.
*/
- String getPath() {
+ public String getPath() {
return path;
}
/**
* Gets the operation value.
+ *
+ * If the operation doesn't take a value {@link Option#uninitialized()} will be returned.
*
* @return The operation value.
*/
- Option getValue() {
+ public Option getValue() {
return value;
}
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationKind.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationKind.java
index 57fe594f7bc5..2520e1f15572 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationKind.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationKind.java
@@ -8,7 +8,7 @@
/**
* Represents the JSON Patch operation kind.
*/
-enum JsonPatchOperationKind {
+public enum JsonPatchOperationKind {
/**
* Add operation.
*/
@@ -45,6 +45,11 @@ enum JsonPatchOperationKind {
this.op = op;
}
+ /**
+ * Gets the string representation of the JSON patch operation kind.
+ *
+ * @return The string representation of the JSON patch operation kind.
+ */
@JsonValue
public String toString() {
return op;
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationSerializer.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationSerializer.java
index acc60d4dee84..38ae5b5439a4 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationSerializer.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/JsonPatchOperationSerializer.java
@@ -12,7 +12,7 @@
/**
* Handles serialization of a {@link JsonPatchOperation}.
*/
-class JsonPatchOperationSerializer extends JsonSerializer {
+final class JsonPatchOperationSerializer extends JsonSerializer {
@Override
public void serialize(JsonPatchOperation value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java
index 090072a409e1..eb390c706729 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java
@@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.Objects;
+import java.util.regex.Pattern;
/**
* This is a fluent logger helper class that wraps a pluggable {@link Logger}.
@@ -35,6 +36,7 @@
* @see Configuration
*/
public class ClientLogger {
+ private static final Pattern CRLF_PATTERN = Pattern.compile("[\r\n]");
private final Logger logger;
/**
@@ -70,7 +72,7 @@ public ClientLogger(String className) {
*/
public void verbose(String message) {
if (logger.isDebugEnabled()) {
- logger.debug(message);
+ logger.debug(sanitizeLogMessageInput(message));
}
}
@@ -106,7 +108,7 @@ public void verbose(String format, Object... args) {
*/
public void info(String message) {
if (logger.isInfoEnabled()) {
- logger.info(message);
+ logger.info(sanitizeLogMessageInput(message));
}
}
@@ -142,7 +144,7 @@ public void info(String format, Object... args) {
*/
public void warning(String message) {
if (logger.isWarnEnabled()) {
- logger.warn(message);
+ logger.warn(sanitizeLogMessageInput(message));
}
}
@@ -178,7 +180,7 @@ public void warning(String format, Object... args) {
*/
public void error(String message) {
if (logger.isErrorEnabled()) {
- logger.error(message);
+ logger.error(sanitizeLogMessageInput(message));
}
}
@@ -327,6 +329,7 @@ private void performLogging(LogLevel logLevel, boolean isExceptionLogging, Strin
}
}
+ sanitizeLogMessageInput(format);
switch (logLevel) {
case VERBOSE:
logger.debug(format, args);
@@ -401,4 +404,14 @@ private boolean doesArgsHaveThrowable(Object... args) {
private Object[] removeThrowable(Object... args) {
return Arrays.copyOf(args, args.length - 1);
}
+
+ /**
+ * Removes CRLF pattern in the {@code logMessage}.
+ *
+ * @param logMessage The log message to sanitize.
+ * @return The updated logMessage.
+ */
+ private static String sanitizeLogMessageInput(String logMessage) {
+ return CRLF_PATTERN.matcher(logMessage).replaceAll("");
+ }
}
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/serializer/JsonSerializerProviders.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/serializer/JsonSerializerProviders.java
index f080043d7799..82131dd5b04a 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/serializer/JsonSerializerProviders.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/serializer/JsonSerializerProviders.java
@@ -10,8 +10,12 @@
* This class is a proxy for using a {@link JsonSerializerProvider} loaded from the classpath.
*/
public final class JsonSerializerProviders {
- private static final String CANNOT_FIND_JSON_SERIALIZER_PROVIDER =
- "Cannot find any JSON serializer provider on the classpath.";
+ private static final String CANNOT_FIND_JSON_SERIALIZER_PROVIDER = "A request was made to load the default JSON "
+ + "serializer provider but one could not be found on the classpath. If you are using a dependency manager, "
+ + "consider including a dependency on azure-core-serializer-json-jackson or azure-core-serializer-json-gson. "
+ + "Depending on your existing dependencies, you have the choice of Jackson or GSON implementations. "
+ + "Additionally, refer to https://aka.ms/azsdk/java/docs/custom-jsonserializer to learn about writing your own "
+ + "implementation.";
private static JsonSerializerProvider defaultProvider;
private static boolean attemptedLoad;
diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/util/JsonPatchDocumentTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/util/JsonPatchDocumentTests.java
index 96e31e26bb4c..e530bd35731e 100644
--- a/sdk/core/azure-core/src/test/java/com/azure/core/util/JsonPatchDocumentTests.java
+++ b/sdk/core/azure-core/src/test/java/com/azure/core/util/JsonPatchDocumentTests.java
@@ -42,6 +42,13 @@ public void jsonifyDocument(JsonPatchDocument document, String expected) throws
assertEquals(expected, SERIALIZER.serialize(document, SerializerEncoding.JSON).replace(" ", ""));
}
+ @ParameterizedTest
+ @MethodSource("formattingSupplier")
+ public void jsonifyOperations(JsonPatchDocument document, String expected) throws IOException {
+ assertEquals(expected, SERIALIZER.serialize(document.getOperations(), SerializerEncoding.JSON)
+ .replace(" ", ""));
+ }
+
private static Stream formattingSupplier() {
JsonPatchDocument complexDocument = newDocument()
.appendTest("/a/b/c", "foo")
diff --git a/sdk/core/azure-core/src/test/java/com/azure/core/util/logging/ClientLoggerTests.java b/sdk/core/azure-core/src/test/java/com/azure/core/util/logging/ClientLoggerTests.java
index 91b4c78d6845..11d6a8a804da 100644
--- a/sdk/core/azure-core/src/test/java/com/azure/core/util/logging/ClientLoggerTests.java
+++ b/sdk/core/azure-core/src/test/java/com/azure/core/util/logging/ClientLoggerTests.java
@@ -80,6 +80,30 @@ public void logSimpleMessage(LogLevel logLevelToConfigure, LogLevel logLevelToUs
assertEquals(logContainsMessage, logValues.contains(logMessage));
}
+ /**
+ * Test whether a log will be captured when the ClientLogger and message are configured to the passed log levels.
+ */
+ @ParameterizedTest
+ @MethodSource("logMaliciousErrorSupplier")
+ @ResourceLock("SYSTEM_OUT")
+ public void logMaliciousMessage(LogLevel logLevelToConfigure, LogLevel logLevelToUse)
+ throws UnsupportedEncodingException {
+ String logMessage = "You have successfully authenticated, \r\n[INFO] User dummy was not"
+ + " successfully authenticated.";
+
+ String expectedMessage = "You have successfully authenticated, [INFO] User dummy was not"
+ + " successfully authenticated.";
+
+ String originalLogLevel = setupLogLevel(logLevelToConfigure.getLogLevel());
+ logMessage(new ClientLogger(ClientLoggerTests.class), logLevelToUse, logMessage);
+
+ setPropertyToOriginalOrClear(originalLogLevel);
+
+ String logValues = logCaptureStream.toString("UTF-8");
+ System.out.println(logValues);
+ assertEquals(true, logValues.contains(expectedMessage));
+ }
+
@ParameterizedTest
@MethodSource("singleLevelCheckSupplier")
@ResourceLock("SYSTEM_OUT")
@@ -461,6 +485,41 @@ private static Stream multiLevelCheckSupplier() {
);
}
+ private static Stream logMaliciousErrorSupplier() {
+ return Stream.of(
+ // Supported logging level set to VERBOSE.
+ // Checking VERBOSE.
+ Arguments.of(LogLevel.VERBOSE, LogLevel.VERBOSE, true),
+
+ // Checking INFORMATIONAL.
+ Arguments.of(LogLevel.VERBOSE, LogLevel.INFORMATIONAL, true),
+
+ // Checking WARNING.
+ Arguments.of(LogLevel.VERBOSE, LogLevel.WARNING, true),
+
+ // Checking ERROR.
+ Arguments.of(LogLevel.VERBOSE, LogLevel.ERROR, true),
+
+ // Checking INFORMATIONAL.
+ Arguments.of(LogLevel.INFORMATIONAL, LogLevel.INFORMATIONAL, true),
+
+ // Checking WARNING.
+ Arguments.of(LogLevel.INFORMATIONAL, LogLevel.WARNING, true),
+
+ // Checking ERROR.
+ Arguments.of(LogLevel.INFORMATIONAL, LogLevel.ERROR, true),
+
+ // Checking WARNING.
+ Arguments.of(LogLevel.WARNING, LogLevel.WARNING, true),
+
+ // Checking ERROR.
+ Arguments.of(LogLevel.WARNING, LogLevel.ERROR, true),
+
+ // Checking ERROR.
+ Arguments.of(LogLevel.ERROR, LogLevel.ERROR, true)
+ );
+ }
+
private static Stream logExceptionAsWarningSupplier() {
return Stream.of(
Arguments.of(LogLevel.VERBOSE, true, true),
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentProducer.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentProducer.java
index d7bd9a56153b..7f3622d00374 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentProducer.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/DocumentProducer.java
@@ -147,7 +147,9 @@ public DocumentProducer(
this.correlatedActivityId = correlatedActivityId;
- this.cosmosQueryRequestOptions = cosmosQueryRequestOptions != null ? cosmosQueryRequestOptions : new CosmosQueryRequestOptions();
+ this.cosmosQueryRequestOptions = cosmosQueryRequestOptions != null ?
+ ModelBridgeInternal.createQueryRequestOptions(cosmosQueryRequestOptions)
+ : new CosmosQueryRequestOptions();
ModelBridgeInternal.setQueryRequestOptionsContinuationToken(this.cosmosQueryRequestOptions, initialContinuationToken);
this.lastResponseContinuationToken = initialContinuationToken;
this.resourceType = resourceType;
diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java
index 1f7374d2502d..84949cab3a39 100644
--- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java
+++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java
@@ -741,13 +741,13 @@ Mono> listIncomingRelationshipsNextSinglePag
*
* {@codesnippet com.azure.digitaltwins.core.asyncClient.createModels#Iterable}
*
- * @param models The list of models to create. Each string corresponds to exactly one model.
+ * @param dtdlModels The list of models to create. Each string corresponds to exactly one model.
* @return A List of created models. Each {@link DigitalTwinsModelData} instance in this list
* will contain metadata about the created model, but will not contain the model itself.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
- public Mono> createModels(Iterable models) {
- return createModelsWithResponse(models, null)
+ public Mono> createModels(Iterable dtdlModels) {
+ return createModelsWithResponse(dtdlModels, null)
.map(Response::getValue);
}
@@ -758,19 +758,19 @@ public Mono> createModels(Iterable model
*
* {@codesnippet com.azure.digitaltwins.core.asyncClient.createModelsWithResponse#Iterable-Options}
*
- * @param models The list of models to create. Each string corresponds to exactly one model.
+ * @param dtdlModels The list of models to create. Each string corresponds to exactly one model.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link Response} containing the list of created models. Each {@link DigitalTwinsModelData} instance in this list
* will contain metadata about the created model, but will not contain the model itself.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
- public Mono>> createModelsWithResponse(Iterable models, CreateModelsOptions options) {
- return withContext(context -> createModelsWithResponse(models, options, context));
+ public Mono>> createModelsWithResponse(Iterable dtdlModels, CreateModelsOptions options) {
+ return withContext(context -> createModelsWithResponse(dtdlModels, options, context));
}
- Mono>> createModelsWithResponse(Iterable models, CreateModelsOptions options, Context context) {
+ Mono>> createModelsWithResponse(Iterable dtdlModels, CreateModelsOptions options, Context context) {
List