aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Martinez <ivanfmartinez@users.noreply.github.com>2018-06-01 11:20:39 -0300
committerIvan Martinez <ivanfmartinez@users.noreply.github.com>2018-06-01 11:20:39 -0300
commit575deac9e2df1cbd0601328f7ea7a9f22029fa43 (patch)
treef9a28341f7e16f02ed7609bba988b38ae6f0122d /src
parent294c399e5b260313a2d49a0fed1516116a23fbd5 (diff)
downloadtraccar-server-575deac9e2df1cbd0601328f7ea7a9f22029fa43.tar.gz
traccar-server-575deac9e2df1cbd0601328f7ea7a9f22029fa43.tar.bz2
traccar-server-575deac9e2df1cbd0601328f7ea7a9f22029fa43.zip
option to instantiate a new SMSNotifier using a different SMSManager
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/Context.java18
-rw-r--r--src/org/traccar/notification/NotificationSms.java22
2 files changed, 27 insertions, 13 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index a7c1817cf..abf9f7a8a 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -372,6 +372,15 @@ public final class Context {
tripsConfig = initTripsConfig();
+ if (config.getBoolean("sms.smpp.enable")) {
+ final String smsManagerClass = config.getString("sms.manager.class", "org.traccar.smpp.SmppClient");
+ try {
+ smsManager = (SMSManager) Class.forName(smsManagerClass).newInstance();
+ } catch (ClassNotFoundException e) {
+ Log.warning("Error loading SMS Manager class : " + smsManagerClass, e);
+ }
+ }
+
if (config.getBoolean("event.enable")) {
initEventsModule();
}
@@ -394,15 +403,6 @@ public final class Context {
statisticsManager = new StatisticsManager();
- if (config.getBoolean("sms.smpp.enable")) {
- final String smsManagerClass = config.getString("sms.manager.class", "org.traccar.smpp.SmppClient");
- try {
- smsManager = (SMSManager) Class.forName(smsManagerClass).newInstance();
- } catch (ClassNotFoundException e) {
- Log.warning("Error loading SMS Manager class : " + smsManagerClass, e);
- }
- }
-
}
private static void initGeolocationModule() {
diff --git a/src/org/traccar/notification/NotificationSms.java b/src/org/traccar/notification/NotificationSms.java
index 804fa8527..63fd57895 100644
--- a/src/org/traccar/notification/NotificationSms.java
+++ b/src/org/traccar/notification/NotificationSms.java
@@ -20,16 +20,30 @@ import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.User;
+import org.traccar.sms.SMSManager;
import org.traccar.sms.SMSException;
public final class NotificationSms extends Notificator {
+ private final SMSManager sms;
+
+ public NotificationSms(String methodId) throws ClassNotFoundException,
+ InstantiationException, IllegalAccessException {
+ final String smsClass = Context.getConfig().getString("notificator." + methodId + ".sms.class", "");
+ if (smsClass.length() > 0) {
+ sms = (SMSManager) Class.forName(smsClass).newInstance();
+ } else {
+ sms = Context.getSmsManager();
+ }
+ }
+
+
@Override
public void sendAsync(long userId, Event event, Position position) {
- User user = Context.getPermissionsManager().getUser(userId);
+ final User user = Context.getPermissionsManager().getUser(userId);
if (user.getPhone() != null) {
Context.getStatisticsManager().registerSms();
- Context.getSmsManager().sendMessageAsync(user.getPhone(),
+ sms.sendMessageAsync(user.getPhone(),
NotificationFormatter.formatShortMessage(userId, event, position), false);
}
}
@@ -37,10 +51,10 @@ public final class NotificationSms extends Notificator {
@Override
public void sendSync(long userId, Event event, Position position) throws SMSException,
InterruptedException {
- User user = Context.getPermissionsManager().getUser(userId);
+ final User user = Context.getPermissionsManager().getUser(userId);
if (user.getPhone() != null) {
Context.getStatisticsManager().registerSms();
- Context.getSmsManager().sendMessageSync(user.getPhone(),
+ sms.sendMessageSync(user.getPhone(),
NotificationFormatter.formatShortMessage(userId, event, position), false);
}
}