-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes for javadoc and logger #4552
Changes from all commits
1ec9438
78db8d4
69026ba
be429c3
b00cdc6
da7ebb6
78ea66b
84d562f
8dfecc3
44fb56e
fe9559f
577f463
6b8d9d3
0fe4ec2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,13 +118,11 @@ public String computeHmac256(final String stringToSign) { | |
byte[] utf8Bytes = stringToSign.getBytes(StandardCharsets.UTF_8); | ||
return Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes)); | ||
} catch (final NoSuchAlgorithmException e) { | ||
String errorMsg = "There is no such algorithm. Error Details: " + e.getMessage(); | ||
logger.warning(errorMsg); | ||
throw new RuntimeException(errorMsg); | ||
logger.logAndThrow(new RuntimeException("There is no such algorithm. Error Details: " + e.getMessage())); | ||
return null; | ||
} catch (InvalidKeyException e) { | ||
String errorMsg = "Please double check the account key. Error details: " + e.getMessage(); | ||
logger.warning(errorMsg); | ||
throw new RuntimeException(errorMsg); | ||
logger.logAndThrow(new RuntimeException("Please double check the account key. Error details: " + e.getMessage())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to |
||
return null; | ||
} | ||
} | ||
|
||
|
@@ -236,8 +234,8 @@ private String computeHMACSHA256(String stringToSign) { | |
String signature = Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes)); | ||
return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature); | ||
} catch (NoSuchAlgorithmException | InvalidKeyException ex) { | ||
logger.warning(ex.getMessage()); | ||
throw new Error(ex); | ||
logger.logAndThrow(new RuntimeException(ex.getMessage())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass in the exception itself into the constructor and change this to use |
||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
* SharedKey credential policy that is put into a header to authorize requests. | ||
*/ | ||
public final class SharedKeyCredential { | ||
private static final ClientLogger LOGGER = new ClientLogger(SharedKeyCredential.class); | ||
private final ClientLogger logger = new ClientLogger(SharedKeyCredential.class); | ||
private static final String AUTHORIZATION_HEADER_FORMAT = "SharedKey %s:%s"; | ||
|
||
// Pieces of the connection string that are needed. | ||
|
@@ -101,8 +101,10 @@ public String generateAuthorizationHeader(URL requestURL, String httpMethod, Map | |
* @param stringToSign The UTF-8-encoded string to sign. | ||
* @return A {@code String} that contains the HMAC-SHA256-encoded signature. | ||
* @throws RuntimeException for one of the following cases: | ||
* - If the HMAC-SHA256 signature for {@code sharedKeyCredentials} fails to generate. | ||
* - If the an invalid key has been given to the client. | ||
* <ul> | ||
* <li>If the HMAC-SHA256 signature for {@code sharedKeyCredentials} fails to generate.</li> | ||
* <li>If the an invalid key has been given to the client.</li> | ||
* </ul> | ||
*/ | ||
public String computeHmac256(final String stringToSign) { | ||
try { | ||
|
@@ -116,11 +118,11 @@ public String computeHmac256(final String stringToSign) { | |
byte[] utf8Bytes = stringToSign.getBytes(StandardCharsets.UTF_8); | ||
return Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes)); | ||
} catch (final NoSuchAlgorithmException e) { | ||
LOGGER.error(e.getMessage()); | ||
throw new RuntimeException(e); | ||
logger.logAndThrow(new RuntimeException(e)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to |
||
return null; | ||
} catch (InvalidKeyException e) { | ||
LOGGER.error("Please double check the account key. Error details: " + e.getMessage()); | ||
throw new RuntimeException("Please double check the account key. Error details: " + e.getMessage()); | ||
logger.logAndThrow(new RuntimeException("Please double check the account key. Error details: " + e.getMessage())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to |
||
return null; | ||
} | ||
} | ||
|
||
|
@@ -232,8 +234,8 @@ private String computeHMACSHA256(String stringToSign) { | |
String signature = Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes)); | ||
return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature); | ||
} catch (NoSuchAlgorithmException | InvalidKeyException ex) { | ||
LOGGER.error(ex.getMessage()); | ||
throw new Error(ex); | ||
logger.logAndThrow(new RuntimeException(ex.getMessage())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass in the exception itself into the constructor and change this to use IllegalStateException as that better aligns with the spec. |
||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ | |
* @see SASTokenCredential | ||
*/ | ||
public final class QueueAsyncClient { | ||
private static final ClientLogger LOGGER = new ClientLogger(QueueAsyncClient.class); | ||
private final ClientLogger logger = new ClientLogger(QueueAsyncClient.class); | ||
private final AzureQueueStorageImpl client; | ||
private final String queueName; | ||
|
||
|
@@ -94,8 +94,8 @@ public URL getQueueUrl() { | |
try { | ||
return new URL(client.getUrl()); | ||
} catch (MalformedURLException ex) { | ||
LOGGER.error("Queue URL is malformed"); | ||
throw new RuntimeException("Queue URL is malformed"); | ||
logger.logAndThrow(new RuntimeException("Queue URL is malformed")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to |
||
return null; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ | |
* @see SharedKeyCredential | ||
*/ | ||
public final class QueueClientBuilder { | ||
private static final ClientLogger LOGGER = new ClientLogger(QueueClientBuilder.class); | ||
private final ClientLogger logger = new ClientLogger(QueueClientBuilder.class); | ||
private static final String ACCOUNT_NAME = "accountname"; | ||
private final List<HttpPipelinePolicy> policies; | ||
|
||
|
@@ -138,8 +138,8 @@ public QueueAsyncClient buildAsyncClient() { | |
Objects.requireNonNull(queueName); | ||
|
||
if (sasTokenCredential == null && sharedKeyCredential == null) { | ||
LOGGER.error("Credentials are required for authorization"); | ||
throw new IllegalArgumentException("Credentials are required for authorization"); | ||
logger.logAndThrow(new IllegalArgumentException("Credentials are required for authorization")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to |
||
return null; | ||
} | ||
|
||
if (pipeline != null) { | ||
|
@@ -205,8 +205,8 @@ public QueueClientBuilder endpoint(String endpoint) { | |
this.sasTokenCredential = credential; | ||
} | ||
} catch (MalformedURLException ex) { | ||
LOGGER.error("The Azure Storage Queue endpoint url is malformed. Endpoint: " + endpoint); | ||
throw new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed. Endpoint: " + endpoint); | ||
logger.logAndThrow(new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed. Endpoint: " + endpoint)); | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to return null here, only use that when the code analyzer thinks there is no return case when one is needed. |
||
} | ||
|
||
return this; | ||
|
@@ -273,10 +273,8 @@ private void getEndPointFromConnectionString(String connectionString) { | |
try { | ||
this.endpoint = new URL(String.format("https://%s.queue.core.windows.net", accountName)); | ||
} catch (MalformedURLException e) { | ||
LOGGER.error("There is no valid account for the connection string. " | ||
+ "Connection String: %s", connectionString); | ||
throw new IllegalArgumentException(String.format("There is no valid account for the connection string. " | ||
+ "Connection String: %s", connectionString)); | ||
logger.logAndThrow(new IllegalArgumentException(String.format("There is no valid account for the connection string. " | ||
+ "Connection String: %s", connectionString))); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
* @see SASTokenCredential | ||
*/ | ||
public final class QueueServiceAsyncClient { | ||
private static final ClientLogger LOGGER = new ClientLogger(QueueServiceAsyncClient.class); | ||
private final ClientLogger logger = new ClientLogger(QueueServiceAsyncClient.class); | ||
private final AzureQueueStorageImpl client; | ||
|
||
/** | ||
|
@@ -71,8 +71,8 @@ public URL getQueueServiceUrl() { | |
try { | ||
return new URL(client.getUrl()); | ||
} catch (MalformedURLException ex) { | ||
LOGGER.error("Queue Service URL is malformed"); | ||
throw new RuntimeException("Storage account URL is malformed"); | ||
logger.logAndThrow(new RuntimeException("Storage account URL is malformed")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this |
||
return null; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ | |
* @see SharedKeyCredential | ||
*/ | ||
public final class QueueServiceClientBuilder { | ||
private static final ClientLogger LOGGER = new ClientLogger(QueueServiceClientBuilder.class); | ||
private final ClientLogger logger = new ClientLogger(QueueServiceClientBuilder.class); | ||
private static final String ACCOUNT_NAME = "accountname"; | ||
private final List<HttpPipelinePolicy> policies; | ||
|
||
|
@@ -112,8 +112,8 @@ public QueueServiceAsyncClient buildAsyncClient() { | |
Objects.requireNonNull(endpoint); | ||
|
||
if (sasTokenCredential == null && sharedKeyCredential == null) { | ||
LOGGER.error("Credentials are required for authorization"); | ||
throw new IllegalArgumentException("Credentials are required for authorization"); | ||
logger.logAndThrow(new IllegalArgumentException("Credentials are required for authorization")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this |
||
return null; | ||
} | ||
|
||
if (pipeline != null) { | ||
|
@@ -189,8 +189,8 @@ public QueueServiceClientBuilder endpoint(String endpoint) { | |
this.sasTokenCredential = credential; | ||
} | ||
} catch (MalformedURLException ex) { | ||
LOGGER.error("The Azure Storage Queue endpoint url is malformed."); | ||
throw new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed."); | ||
logger.logAndThrow(new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed.")); | ||
return null; | ||
} | ||
|
||
return this; | ||
|
@@ -245,10 +245,8 @@ private void getEndPointFromConnectionString(String connectionString) { | |
try { | ||
this.endpoint = new URL(String.format("https://%s.queue.core.windows.net", accountName)); | ||
} catch (MalformedURLException e) { | ||
LOGGER.error("There is no valid account for the connection string. " | ||
+ "Connection String: %s", connectionString); | ||
throw new IllegalArgumentException(String.format("There is no valid account for the connection string. " | ||
+ "Connection String: %s", connectionString)); | ||
logger.logAndThrow(new IllegalArgumentException(String.format("There is no valid account for the connection string. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this |
||
+ "Connection String: %s", connectionString))); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to
IllegalStateException
as it better aligns with the spec.