From aaeac03cfbc4912ccfaabc4cb4f882089745f94f Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 30 May 2017 00:04:49 +0530 Subject: [PATCH] fixed issues in mqtt input adapter and thrift adapter after testing with multitenancy --- .../mgt/input/adapter/mqtt/util/MQTTAdapterListener.java | 6 ++++++ .../internal/ThriftEventAdapterServiceComponent.java | 2 +- .../authorization/DeviceAccessBasedMQTTAuthorizer.java | 8 +++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java index 635012538f..e6e9fe7001 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java @@ -206,8 +206,14 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { } try { mqttClient.subscribe(topic); + log.info("mqtt receiver subscribed to topic: " + topic); } catch (MqttException e) { log.error("Failed to subscribe to topic: " + topic + ", Retrying....."); + try { + mqttClient.disconnect(); + } catch (MqttException ex) { + // do nothing. + } return false; } return true; diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java index ad18ff6d1a..4d85851a29 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java @@ -137,7 +137,7 @@ public class ThriftEventAdapterServiceComponent { String tenantDomain = credentials.getDomainName(); if (objects != null && objects.length > 0) { if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { - String[] splitValues = ((String) objects[0]).split("@@"); + String[] splitValues = ((String) objects[0]).split("@"); if (splitValues.length > 1) { tenantDomain = splitValues[0]; } diff --git a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java index e158c726ef..568c567eca 100644 --- a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java +++ b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java @@ -72,7 +72,7 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { private static final String UI_EXECUTE = "ui.execute"; private static Log log = LogFactory.getLog(DeviceAccessBasedMQTTAuthorizer.class); - AuthorizationConfigurationManager MQTTAuthorizationConfiguration; + private AuthorizationConfigurationManager MQTTAuthorizationConfiguration; private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0"; private static final String CACHE_MANAGER_NAME = "mqttAuthorizationCacheManager"; private static final String CACHE_NAME = "mqttAuthorizationCache"; @@ -173,17 +173,15 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { } catch (FeignException e) { oAuthRequestInterceptor.resetApiApplicationKey(); if (e.getMessage().contains(GATEWAY_ERROR_CODE)) { - log.error("Failed to connect to the device authorization service."); + log.error("Failed to connect to the device authorization service.", e); } else { log.error(e.getMessage(), e); } - log.error(e.getMessage(), e); } + return false; } finally { PrivilegedCarbonContext.endTenantFlow(); } - - return false; } /**