diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-29 22:20:03 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-29 22:20:03 -0800 |
commit | 8fe1e679935688676f7139bb9ed6dc61838d0e2f (patch) | |
tree | 75704a42322d85d7245658b8d06aea9def6132a1 /src/main/java/org/traccar/sms | |
parent | 7f0692101a017f33ffb984e6df92e5dbef6ce71b (diff) | |
download | traccar-server-8fe1e679935688676f7139bb9ed6dc61838d0e2f.tar.gz traccar-server-8fe1e679935688676f7139bb9ed6dc61838d0e2f.tar.bz2 traccar-server-8fe1e679935688676f7139bb9ed6dc61838d0e2f.zip |
Migrate SMS config keys
Diffstat (limited to 'src/main/java/org/traccar/sms')
-rw-r--r-- | src/main/java/org/traccar/sms/HttpSmsClient.java | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/main/java/org/traccar/sms/HttpSmsClient.java b/src/main/java/org/traccar/sms/HttpSmsClient.java index f65c9e83e..6234eabb8 100644 --- a/src/main/java/org/traccar/sms/HttpSmsClient.java +++ b/src/main/java/org/traccar/sms/HttpSmsClient.java @@ -16,19 +16,18 @@ */ package org.traccar.sms; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.InvocationCallback; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.Context; -import org.traccar.api.SecurityRequestFilter; +import org.traccar.config.Keys; import org.traccar.helper.DataConverter; import org.traccar.notification.MessageException; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.InvocationCallback; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; @@ -39,25 +38,27 @@ public class HttpSmsClient implements SmsManager { private final String url; private final String authorizationHeader; - private String authorization; + private final String authorization; private final String template; private final boolean encode; private final MediaType mediaType; 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"); - String password = Context.getConfig().getString("sms.http.password"); + url = Context.getConfig().getString(Keys.SMS_HTTP_URL); + authorizationHeader = Context.getConfig().getString(Keys.SMS_HTTP_AUTHORIZATION_HEADER); + if (Context.getConfig().hasKey(Keys.SMS_HTTP_AUTHORIZATION)) { + authorization = Context.getConfig().getString(Keys.SMS_HTTP_AUTHORIZATION); + } else { + String user = Context.getConfig().getString(Keys.SMS_HTTP_USER); + String password = Context.getConfig().getString(Keys.SMS_HTTP_PASSWORD); if (user != null && password != null) { authorization = "Basic " + DataConverter.printBase64((user + ":" + password).getBytes(StandardCharsets.UTF_8)); + } else { + authorization = null; } } - template = Context.getConfig().getString("sms.http.template").trim(); + template = Context.getConfig().getString(Keys.SMS_HTTP_TEMPLATE).trim(); if (template.charAt(0) == '{' || template.charAt(0) == '[') { encode = false; mediaType = MediaType.APPLICATION_JSON_TYPE; |