From 4f6e68ad5a14b128258e68fd819406dbea585d7f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 12 Jul 2020 09:45:09 -0700 Subject: Add Traccar push notificator --- .../org/traccar/notificators/NotificatorFirebase.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/traccar/notificators/NotificatorFirebase.java') diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index 75d325de2..8a3deee92 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 - 2020 Anton Tananaev (anton@traccar.org) * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,9 +32,8 @@ public class NotificatorFirebase extends Notificator { private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorFirebase.class); - private static final String URL = "https://fcm.googleapis.com/fcm/send"; - - private String key; + private final String url; + private final String key; public static class Notification { @JsonProperty("body") @@ -49,7 +48,14 @@ public class NotificatorFirebase extends Notificator { } public NotificatorFirebase() { - key = Context.getConfig().getString("notificator.firebase.key"); + this( + "https://fcm.googleapis.com/fcm/send", + Context.getConfig().getString("notificator.firebase.key")); + } + + protected NotificatorFirebase(String url, String key) { + this.url = url; + this.key = key; } @Override @@ -64,7 +70,7 @@ public class NotificatorFirebase extends Notificator { message.tokens = user.getString("notificationTokens").split("[, ]"); message.notification = notification; - Context.getClient().target(URL).request() + Context.getClient().target(url).request() .header("Authorization", "key=" + key) .async().post(Entity.json(message), new InvocationCallback() { @Override -- cgit v1.2.3