From 11ceb76848b63d80dfe14fdb82990f719e51e661 Mon Sep 17 00:00:00 2001 From: pankajjangid05 Date: Tue, 23 May 2023 17:25:17 +0530 Subject: [PATCH] added static fcm token for testing notification --- .../web/FirebaseNotificationService.java | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/uci/adapter/firebase/web/FirebaseNotificationService.java b/src/main/java/com/uci/adapter/firebase/web/FirebaseNotificationService.java index caaac91..b28fa26 100644 --- a/src/main/java/com/uci/adapter/firebase/web/FirebaseNotificationService.java +++ b/src/main/java/com/uci/adapter/firebase/web/FirebaseNotificationService.java @@ -25,17 +25,17 @@ public class FirebaseNotificationService { * @return */ public Mono sendNotificationMessage(String serviceKey, String token, String title, String body, String click_action, String phone, String channelMessageId, String notificationKeyEnable, Map data) { -// WebClient client = WebClient.builder() -// .baseUrl(url) -// .defaultHeaders(httpHeaders -> { -// httpHeaders.set("Authorization", "key=" + serviceKey); -// httpHeaders.set("Content-Type", "application/json"); -// }) -// .build(); - + WebClient client = WebClient.builder() + .baseUrl(url) + .defaultHeaders(httpHeaders -> { + httpHeaders.set("Authorization", "key=" + serviceKey); + httpHeaders.set("Content-Type", "application/json"); + }) + .build(); + String token1 = "d6oo7uBfIHlJvQktBLpF31:APA91bEXkLLFFgoesrBC4yfMahjvFz8AWBqL_C-uS-91_qMm2GohIwZ4EdpB6BoDCIps6xhrlpVuYlWHiXEsElVfLagwaWg1LAIb1wbNnXAvD0c6GozuEtk14VN5oX1gmMwMDQf-EEeG";; ObjectMapper mapper = new ObjectMapper(); ObjectNode node = mapper.createObjectNode(); - node.put("to", token); + node.put("to", token1); node.put("collapse_key", "type_a"); // Notification Key Enable and Disable from Payload if (notificationKeyEnable != null && notificationKeyEnable.equalsIgnoreCase("true")) { @@ -53,7 +53,7 @@ public Mono sendNotificationMessage(String serviceKey, String token, St dataNode.put("title", title); dataNode.put("externalId", channelMessageId); dataNode.put("destAdd", phone); - dataNode.put("fcmDestAdd", token); + dataNode.put("fcmDestAdd", token1); dataNode.put("click_action", click_action); if (data != null) { @@ -65,27 +65,25 @@ public Mono sendNotificationMessage(String serviceKey, String token, St } node.put("data", dataNode); - log.info("Notification triggered success : " + phone + " fcm token : " + token); - return Mono.just(true); -// return client.post().bodyValue(node.toString()).retrieve().bodyToMono(String.class).map(response -> { -// if (response != null) { -// try { -// ObjectNode resultNode = (ObjectNode) mapper.readTree(response); -// if (resultNode.get("success") != null && Integer.parseInt(resultNode.get("success").toString()) >= 1) { -// log.info("Notification triggered success : " + phone + " fcm token : " + token + " FCM Response : " + resultNode.toString()); -// return true; -// } else { -// log.error("Notification not sent : " + phone + " fcm Token : " + token + " error :" + resultNode.toString()); -// } -// } catch (JsonProcessingException jsonMappingException) { -// log.error("Exception in sendNotificationMessage: " + jsonMappingException.getMessage()); -// } catch (NumberFormatException ex) { -// log.error("Exception in sendNotificationMessage: " + ex.getMessage()); -// } -// } -// return false; -// }); + return client.post().bodyValue(node.toString()).retrieve().bodyToMono(String.class).map(response -> { + if (response != null) { + try { + ObjectNode resultNode = (ObjectNode) mapper.readTree(response); + if (resultNode.get("success") != null && Integer.parseInt(resultNode.get("success").toString()) >= 1) { + log.info("Notification triggered success : " + phone + " fcm token : " + token1 + " FCM Response : " + resultNode.toString()); + return true; + } else { + log.error("Notification not sent : " + phone + " fcm Token : " + token1 + " error :" + resultNode.toString()); + } + } catch (JsonProcessingException jsonMappingException) { + log.error("Exception in sendNotificationMessage: " + jsonMappingException.getMessage()); + } catch (NumberFormatException ex) { + log.error("Exception in sendNotificationMessage: " + ex.getMessage()); + } + } + return false; + }); } // public Mono sendNotificationMessage2(String token, String title, String body) {