From de45d40884d58e4d0e2b2a65b8827bb35634894e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 11 Jul 2020 21:27:01 -0700 Subject: Support request without auth --- src/main/java/org/traccar/sms/HttpSmsClient.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/sms/HttpSmsClient.java b/src/main/java/org/traccar/sms/HttpSmsClient.java index 8e2b67bf7..c6f3be0f1 100644 --- a/src/main/java/org/traccar/sms/HttpSmsClient.java +++ b/src/main/java/org/traccar/sms/HttpSmsClient.java @@ -52,8 +52,10 @@ public class HttpSmsClient implements SmsManager { if (authorization == null) { String user = Context.getConfig().getString("sms.http.user"); String password = Context.getConfig().getString("sms.http.password"); - authorization = "Basic " - + DataConverter.printBase64((user + ":" + password).getBytes(StandardCharsets.UTF_8)); + if (user != null && password != null) { + authorization = "Basic " + + DataConverter.printBase64((user + ":" + password).getBytes(StandardCharsets.UTF_8)); + } } template = Context.getConfig().getString("sms.http.template").trim(); if (template.charAt(0) == '{' || template.charAt(0) == '[') { @@ -80,8 +82,11 @@ public class HttpSmsClient implements SmsManager { } private Invocation.Builder getRequestBuilder() { - return Context.getClient().target(url).request() - .header(authorizationHeader, authorization); + Invocation.Builder builder = Context.getClient().target(url).request(); + if (authorization != null) { + builder = builder.header(authorizationHeader, authorization); + } + return builder; } @Override -- cgit v1.2.3