aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorSyed Mujeer Hashmi <mujeerhashmi@gmail.com>2018-12-27 19:38:37 +0530
committerSyed Mujeer Hashmi <mujeerhashmi@gmail.com>2018-12-27 23:34:57 +0530
commit93d3854a62e80b54a67a4bc47722e5ca896d0afa (patch)
treedcfeb5dd4c673e64a0720f8ec340b4d4bd484a39 /src/org
parent0c0df0ff62a4b14aba8ef2ebd8642d1ee3dd4148 (diff)
downloadtraccar-server-93d3854a62e80b54a67a4bc47722e5ca896d0afa.tar.gz
traccar-server-93d3854a62e80b54a67a4bc47722e5ca896d0afa.tar.bz2
traccar-server-93d3854a62e80b54a67a4bc47722e5ca896d0afa.zip
SMS client: Changes to support msg91
The authorization header may require different name:value pair for specifying token by the service provider. Add a config parameter "sms.http.authorizationName" to support this. In case of msg91, the name required is "authkey". The newline at the end of short templates are causing invalid json in request. Get rid of the newline using trim(). The required config to enable msg91 sms notifications are <entry key='notificator.types'>web,mail,sms</entry> <entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry> <entry key='sms.http.url'>http://api.msg91.com/api/v2/sendsms</entry> <entry key="sms.http.authorizationName">authkey</entry> <entry key='sms.http.authorization'>[YOUR TOKEN]</entry> <entry key='sms.http.template'> { "sender": "SOCKET", "route": "4", "country": "91", "sms": [ { "message": "{message}", "to": ["{phone}"] } ] } </entry> Signed-off-by: Syed Mujeer Hashmi <mujeerhashmi@gmail.com>
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/sms/HttpSmsClient.java7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/org/traccar/sms/HttpSmsClient.java b/src/org/traccar/sms/HttpSmsClient.java
index 994e2db4e..8e2b67bf7 100644
--- a/src/org/traccar/sms/HttpSmsClient.java
+++ b/src/org/traccar/sms/HttpSmsClient.java
@@ -38,6 +38,7 @@ public class HttpSmsClient implements SmsManager {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpSmsClient.class);
private String url;
+ private String authorizationHeader;
private String authorization;
private String template;
private boolean encode;
@@ -45,6 +46,8 @@ public class HttpSmsClient implements SmsManager {
public HttpSmsClient() {
url = Context.getConfig().getString("sms.http.url");
+ authorizationHeader = Context.getConfig().getString("sms.http.authorizationHeader",
+ SecurityRequestFilter.AUTHORIZATION_HEADER);
authorization = Context.getConfig().getString("sms.http.authorization");
if (authorization == null) {
String user = Context.getConfig().getString("sms.http.user");
@@ -70,7 +73,7 @@ public class HttpSmsClient implements SmsManager {
try {
return template
.replace("{phone}", prepareValue(destAddress))
- .replace("{message}", prepareValue(message));
+ .replace("{message}", prepareValue(message.trim()));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
@@ -78,7 +81,7 @@ public class HttpSmsClient implements SmsManager {
private Invocation.Builder getRequestBuilder() {
return Context.getClient().target(url).request()
- .header(SecurityRequestFilter.AUTHORIZATION_HEADER, authorization);
+ .header(authorizationHeader, authorization);
}
@Override