Merge branch 'master' into 'master'

Fix FCM and configuration fetching issues

See merge request entgra/carbon-device-mgt!742
revert-70ac1926
Dharmakeerthi Lasantha 4 years ago
commit 8c50af1631

@ -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 + "'");
} }
} }

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ProfileOperation extends ConfigOperation implements Serializable { public class ProfileOperation extends ConfigOperation implements Serializable {
private static final long serialVersionUID = -3322674908775087365L;
private List<Integer> correctiveActionIds; private List<Integer> correctiveActionIds;
private List<Integer> reactiveActionIds; private List<Integer> reactiveActionIds;

@ -36,6 +36,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
@ -336,7 +337,19 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private Map<String, String> getConfigProperty(List<ConfigurationEntry> configs) { private Map<String, String> getConfigProperty(List<ConfigurationEntry> configs) {
Map<String, String> propertMap = new HashMap<>(); Map<String, String> propertMap = new HashMap<>();
for (ConfigurationEntry entry : configs) { for (ConfigurationEntry entry : configs) {
propertMap.put(entry.getName(), entry.getValue().toString()); if (entry != null && entry.getValue() != null && entry.getName() != null) {
propertMap.put(entry.getName(), entry.getValue().toString());
} else {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
String domain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String message = "Could not find a property in tenant id: " + tenantId + ", " +
"domain: " + domain;
if (entry != null && entry.getName() != null) {
message += ", missing value for properly: " + entry.getName();
}
log.error(message);
}
} }
return propertMap; return propertMap;
} }

Loading…
Cancel
Save