aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorSubodh Ranadive <subodh.ranadive@ekzero.com>2021-03-04 14:53:05 +0530
committerSubodh Ranadive <subodh.ranadive@ekzero.com>2021-03-24 15:30:31 +0530
commit49b8cdc68d4ea2ab2e93e6d9d1622f3e828a7776 (patch)
treea593bb4a5c5ed662488c6f4692cdea296673facd /src/main
parentd2dc1f983a9b5fc579b24c406587260e726dc35d (diff)
downloadtrackermap-server-49b8cdc68d4ea2ab2e93e6d9d1622f3e828a7776.tar.gz
trackermap-server-49b8cdc68d4ea2ab2e93e6d9d1622f3e828a7776.tar.bz2
trackermap-server-49b8cdc68d4ea2ab2e93e6d9d1622f3e828a7776.zip
feature : added support of AWS SNS messaging
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/Context.java2
-rw-r--r--src/main/java/org/traccar/config/Keys.java6
-rw-r--r--src/main/java/org/traccar/sms/SnsSmsClient.java17
3 files changed, 13 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 934006347..fe494dabf 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -318,7 +318,7 @@ public final class Context {
if (config.hasKey(Keys.SMS_HTTP_URL)) {
smsManager = new HttpSmsClient();
- } else if (config.hasKey(Keys.AWS_REGION)) {
+ } else if (config.hasKey(Keys.SMS_AWS_REGION)) {
smsManager = new SnsSmsClient();
}
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index c3dce88c4..d2e5bbd99 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -690,14 +690,14 @@ public final class Keys {
/**
* AWS Access Key with SNS permission.
*/
- public static final ConfigKey<String> AWS_ACCESS_KEY = new ConfigKey<>(
+ public static final ConfigKey<String> SMS_AWS_ACCESS = new ConfigKey<>(
"sms.aws.access",
Collections.singletonList(KeyType.GLOBAL));
/**
* AWS Secret Access Key with SNS permission.
*/
- public static final ConfigKey<String> AWS_SECRET_KEY = new ConfigKey<>(
+ public static final ConfigKey<String> SMS_AWS_SECRET = new ConfigKey<>(
"sms.aws.secret",
Collections.singletonList(KeyType.GLOBAL));
@@ -705,7 +705,7 @@ public final class Keys {
* AWS Region for SNS service.
* Make sure to use regions that are supported for messaging.
*/
- public static final ConfigKey<String> AWS_REGION = new ConfigKey<>(
+ public static final ConfigKey<String> SMS_AWS_REGION = new ConfigKey<>(
"sms.aws.region",
Collections.singletonList(KeyType.GLOBAL));
diff --git a/src/main/java/org/traccar/sms/SnsSmsClient.java b/src/main/java/org/traccar/sms/SnsSmsClient.java
index 81114e5f5..0c2be0bd2 100644
--- a/src/main/java/org/traccar/sms/SnsSmsClient.java
+++ b/src/main/java/org/traccar/sms/SnsSmsClient.java
@@ -21,6 +21,7 @@ import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.MessageAttributeValue;
import com.amazonaws.services.sns.model.PublishRequest;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
@@ -30,25 +31,25 @@ import org.traccar.notification.MessageException;
import java.util.HashMap;
import java.util.Map;
-
public class SnsSmsClient implements SmsManager {
private static final Logger LOGGER = LoggerFactory.getLogger(SnsSmsClient.class);
private final AmazonSNS snsClient;
public SnsSmsClient() {
- if (Context.getConfig().getString(Keys.AWS_REGION) == null
- || Context.getConfig().getString(Keys.AWS_ACCESS_KEY) == null
- || Context.getConfig().getString(Keys.AWS_SECRET_KEY) == null) {
+ if (Context.getConfig().hasKey(Keys.SMS_AWS_REGION)
+ && Context.getConfig().hasKey(Keys.SMS_AWS_ACCESS)
+ && Context.getConfig().hasKey(Keys.SMS_AWS_SECRET)) {
+ snsClient = awsSNSClient();
+ } else {
throw new RuntimeException("SNS Not Configured Properly. Please provide valid config.");
}
- snsClient = awsSNSClient();
}
public AmazonSNS awsSNSClient() {
- BasicAWSCredentials awsCredentials = new BasicAWSCredentials(Context.getConfig().getString(Keys.AWS_ACCESS_KEY),
- Context.getConfig().getString(Keys.AWS_SECRET_KEY));
- return AmazonSNSClientBuilder.standard().withRegion(Context.getConfig().getString(Keys.AWS_REGION))
+ BasicAWSCredentials awsCredentials = new BasicAWSCredentials(Context.getConfig().getString(Keys.SMS_AWS_ACCESS),
+ Context.getConfig().getString(Keys.SMS_AWS_SECRET));
+ return AmazonSNSClientBuilder.standard().withRegion(Context.getConfig().getString(Keys.SMS_AWS_REGION))
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build();
}