|
|
@ -64,7 +64,7 @@ public class FCMNotificationStrategy implements NotificationStrategy {
|
|
|
|
if (NOTIFIER_TYPE_FCM.equals(config.getType())) {
|
|
|
|
if (NOTIFIER_TYPE_FCM.equals(config.getType())) {
|
|
|
|
Device device = FCMDataHolder.getInstance().getDeviceManagementProviderService()
|
|
|
|
Device device = FCMDataHolder.getInstance().getDeviceManagementProviderService()
|
|
|
|
.getDeviceWithTypeProperties(ctx.getDeviceId());
|
|
|
|
.getDeviceWithTypeProperties(ctx.getDeviceId());
|
|
|
|
if(getFCMToken(device.getProperties()) != null) {
|
|
|
|
if(device.getProperties() != null && getFCMToken(device.getProperties()) != null) {
|
|
|
|
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
|
|
|
|
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -92,33 +92,35 @@ public class FCMNotificationStrategy implements NotificationStrategy {
|
|
|
|
|
|
|
|
|
|
|
|
private void sendWakeUpCall(String message, Device device) throws IOException,
|
|
|
|
private void sendWakeUpCall(String message, Device device) throws IOException,
|
|
|
|
PushNotificationExecutionFailedException {
|
|
|
|
PushNotificationExecutionFailedException {
|
|
|
|
OutputStream os = null;
|
|
|
|
if (device.getProperties() != null) {
|
|
|
|
byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes();
|
|
|
|
OutputStream os = null;
|
|
|
|
|
|
|
|
byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes();
|
|
|
|
HttpURLConnection conn = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
HttpURLConnection conn = null;
|
|
|
|
conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection();
|
|
|
|
try {
|
|
|
|
conn.setRequestProperty("Content-Type", "application/json");
|
|
|
|
conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection();
|
|
|
|
conn.setRequestProperty("Authorization", "key=" + config.getProperty(FCM_API_KEY));
|
|
|
|
conn.setRequestProperty("Content-Type", "application/json");
|
|
|
|
conn.setRequestMethod("POST");
|
|
|
|
conn.setRequestProperty("Authorization", "key=" + config.getProperty(FCM_API_KEY));
|
|
|
|
conn.setDoOutput(true);
|
|
|
|
conn.setRequestMethod("POST");
|
|
|
|
os = conn.getOutputStream();
|
|
|
|
conn.setDoOutput(true);
|
|
|
|
os.write(bytes);
|
|
|
|
os = conn.getOutputStream();
|
|
|
|
} finally {
|
|
|
|
os.write(bytes);
|
|
|
|
if (os != null) {
|
|
|
|
} finally {
|
|
|
|
os.close();
|
|
|
|
if (os != null) {
|
|
|
|
|
|
|
|
os.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn != null) {
|
|
|
|
|
|
|
|
conn.disconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (conn != null) {
|
|
|
|
int status = conn.getResponseCode();
|
|
|
|
conn.disconnect();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Result code: " + status + ", Message: " + conn.getResponseMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != HTTP_STATUS_CODE_OK) {
|
|
|
|
|
|
|
|
throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
|
|
|
|
|
|
|
|
"error code '" + status + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int status = conn.getResponseCode();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Result code: " + status + ", Message: " + conn.getResponseMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != HTTP_STATUS_CODE_OK) {
|
|
|
|
|
|
|
|
throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
|
|
|
|
|
|
|
|
"error code '" + status + "'");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|