Fixing null pointer issue on mqtt notification strategy implementation

revert-70aa11f8
Rasika Perera 8 years ago
parent 1d3f5f39a7
commit c6c555abc6

@ -20,6 +20,8 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -32,6 +34,7 @@ import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterExc
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class MQTTNotificationStrategy implements NotificationStrategy {
@ -75,7 +78,16 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
@Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
Map<String, String> dynamicProperties = new HashMap<>();
dynamicProperties.put("topic", (String) ctx.getOperation().getProperties().get(MQTT_ADAPTER_TOPIC));
Properties properties = ctx.getOperation().getProperties();
if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) {
dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC));
} else {
Operation operation = ctx.getOperation();
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType();
dynamicProperties.put("topic", topic);
}
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
ctx.getOperation().getPayLoad());
}

Loading…
Cancel
Save