Skip to content

Commit 3639256

Browse files
authored
Merge pull request MicrosoftDocs#77810 from pearj/patch-1
Specify the US locale for Java sample and clarify date format
2 parents 375684a + 2891253 commit 3639256

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

articles/azure-monitor/logs/data-collector-api.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ To use the HTTP Data Collector API, you create a POST request that includes the
4848
|:--- |:--- |
4949
| Authorization |The authorization signature. Later in the article, you can read about how to create an HMAC-SHA256 header. |
5050
| Log-Type |Specify the record type of the data that is being submitted. Can only contain letters, numbers, and underscore (_), and may not exceed 100 characters. |
51-
| x-ms-date |The date that the request was processed, in RFC 1123 format. |
51+
| x-ms-date |The date that the request was processed, in RFC 7234 format. |
5252
| x-ms-AzureResourceId | Resource ID of the Azure resource the data should be associated with. This populates the [_ResourceId](./log-standard-columns.md#_resourceid) property and allows the data to be included in [resource-context](./design-logs-deployment.md#access-mode) queries. If this field isn't specified, the data will not be included in resource-context queries. |
5353
| time-generated-field | The name of a field in the data that contains the timestamp of the data item. If you specify a field then its contents are used for **TimeGenerated**. If this field isn’t specified, the default for **TimeGenerated** is the time that the message is ingested. The contents of the message field should follow the ISO 8601 format YYYY-MM-DDThh:mm:ssZ. |
5454

@@ -593,15 +593,15 @@ public class ApiExample {
593593
String stringToHash = String
594594
.join("\n", httpMethod, String.valueOf(json.getBytes(StandardCharsets.UTF_8).length), contentType,
595595
xmsDate , resource);
596-
String hashedString = getHMAC254(stringToHash, sharedKey);
596+
String hashedString = getHMAC256(stringToHash, sharedKey);
597597
String signature = "SharedKey " + workspaceId + ":" + hashedString;
598598

599599
postData(signature, dateString, json);
600600
}
601601

602602
private static String getServerTime() {
603603
Calendar calendar = Calendar.getInstance();
604-
SimpleDateFormat dateFormat = new SimpleDateFormat(RFC_1123_DATE);
604+
SimpleDateFormat dateFormat = new SimpleDateFormat(RFC_1123_DATE, Locale.US);
605605
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
606606
return dateFormat.format(calendar.getTime());
607607
}
@@ -622,14 +622,14 @@ public class ApiExample {
622622
}
623623
}
624624

625-
private static String getHMAC254(String input, String key) throws InvalidKeyException, NoSuchAlgorithmException {
625+
private static String getHMAC256(String input, String key) throws InvalidKeyException, NoSuchAlgorithmException {
626626
String hash;
627-
Mac sha254HMAC = Mac.getInstance("HmacSHA256");
627+
Mac sha256HMAC = Mac.getInstance("HmacSHA256");
628628
Base64.Decoder decoder = Base64.getDecoder();
629629
SecretKeySpec secretKey = new SecretKeySpec(decoder.decode(key.getBytes(StandardCharsets.UTF_8)), "HmacSHA256");
630-
sha254HMAC.init(secretKey);
630+
sha256HMAC.init(secretKey);
631631
Base64.Encoder encoder = Base64.getEncoder();
632-
hash = new String(encoder.encode(sha254HMAC.doFinal(input.getBytes(StandardCharsets.UTF_8))));
632+
hash = new String(encoder.encode(sha256HMAC.doFinal(input.getBytes(StandardCharsets.UTF_8))));
633633
return hash;
634634
}
635635

0 commit comments

Comments
 (0)