From d2dc1f983a9b5fc579b24c406587260e726dc35d Mon Sep 17 00:00:00 2001 From: Subodh Ranadive Date: Sun, 7 Mar 2021 09:58:11 +0530 Subject: Minor fixes --- src/main/java/org/traccar/sms/SnsSmsClient.java | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/main/java/org/traccar/sms') diff --git a/src/main/java/org/traccar/sms/SnsSmsClient.java b/src/main/java/org/traccar/sms/SnsSmsClient.java index d79079f7a..81114e5f5 100644 --- a/src/main/java/org/traccar/sms/SnsSmsClient.java +++ b/src/main/java/org/traccar/sms/SnsSmsClient.java @@ -37,10 +37,9 @@ public class SnsSmsClient implements SmsManager { private final AmazonSNS snsClient; public SnsSmsClient() { - if (!Context.getConfig().getString(Keys.AWS_SNS_ENABLED).equals("true") + if (Context.getConfig().getString(Keys.AWS_REGION) == null || Context.getConfig().getString(Keys.AWS_ACCESS_KEY) == null - || Context.getConfig().getString(Keys.AWS_SECRET_KEY) == null - || Context.getConfig().getString(Keys.AWS_REGION) == null) { + || Context.getConfig().getString(Keys.AWS_SECRET_KEY) == null) { throw new RuntimeException("SNS Not Configured Properly. Please provide valid config."); } snsClient = awsSNSClient(); @@ -53,7 +52,9 @@ public class SnsSmsClient implements SmsManager { .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build(); } - public void sendSNSMessage(String message, String destAddress) { + @Override + public void sendMessageSync(String destAddress, String message, boolean command) + throws InterruptedException, MessageException { Map smsAttributes = new HashMap<>(); smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue().withStringValue("SNS").withDataType("String")); @@ -63,14 +64,14 @@ public class SnsSmsClient implements SmsManager { .withPhoneNumber(destAddress).withMessageAttributes(smsAttributes)); } - @Override - public void sendMessageSync(String destAddress, String message, boolean command) - throws InterruptedException, MessageException { - sendSNSMessage(message, destAddress); - } - @Override public void sendMessageAsync(String destAddress, String message, boolean command) { - sendSNSMessage(message, destAddress); + try { + sendMessageSync(destAddress, message, command); + } catch (InterruptedException interruptedException) { + LOGGER.warn("SMS send failed", interruptedException.getMessage()); + } catch (MessageException messageException) { + LOGGER.warn("SMS send failed", messageException.getMessage()); + } } } -- cgit v1.2.3