Skip to content

Commit

Permalink
Catch IllegalArgumentException when message key is not found
Browse files Browse the repository at this point in the history
Signed-off-by: nx673747 <nafi.xhafa@broadcom.com>
  • Loading branch information
nx673747 committed Aug 28, 2024
1 parent 8abc553 commit acaf3fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SafResourceAccessEndpoint implements SafResourceAccessVerifying {

private static final String URL_VARIABLE_SUFFIX = "/{entity}/{level}";

@Value("${apiml.security.authorization.endpoint.url:http://localhost:8542/saf-auth}")
@Value("${apiml.security.authorization.endpoint.url:'http://localhost:8542/saf-auth'}")
private String endpointUrl;

private final RestTemplate restTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.zowe.apiml.message.core.Message;
import org.zowe.apiml.message.core.MessageService;
import org.zowe.apiml.message.core.MessageType;
import org.zowe.apiml.message.template.MessageTemplate;
import org.zowe.apiml.util.ObjectUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -67,16 +68,24 @@ public static ApimlLogger empty() {
* @param parameters for message
*/
public Message log(String key, Object... parameters) {
ObjectUtil.requireNotNull(key, "key can't be null");
ObjectUtil.requireNotNull(parameters, "parameters can't be null");
Message message;
try {
ObjectUtil.requireNotNull(key, "key can't be null");
ObjectUtil.requireNotNull(parameters, "parameters can't be null");

if (messageService != null) {
Message message = messageService.createMessage(key, parameters);
log(message);
return message;
if (messageService == null) {
return null;
}
message = messageService.createMessage(key, parameters);
} catch (IllegalArgumentException exception) {
message = (messageService == null ? Message.of(Message.INVALID_KEY_MESSAGE,
new MessageTemplate(Message.INVALID_KEY_MESSAGE, "ZWEAM102", MessageType.ERROR,
"Internal error: Invalid message key '%s' provided. No default message found. " +
"Please contact support of further assistance."), new Object[]{key}) :
messageService.createMessage(Message.INVALID_KEY_MESSAGE));
}

return null;
log(message);
return message;
}

/**
Expand All @@ -94,9 +103,9 @@ public void log(Message message) {
/**
* Method which allows to log text in its level type.
*
* @param messageType type of the message
* @param text text for message
* @param arguments arguments for message text
* @param messageType type of the message
* @param text text for message
* @param arguments arguments for message text
* @throws IllegalArgumentException when parameters are null
*/
@SuppressWarnings("squid:S2629")
Expand Down

0 comments on commit acaf3fb

Please sign in to comment.