From 8381070bf6bf56d95a7dd2bf2c3f50b4be947b48 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 1 Jun 2017 17:21:23 +0530 Subject: [PATCH 01/14] Implemented Pull Notification Support --- .../mqtt/util/MQTTAdapterListener.java | 8 +- .../DeviceAccessBasedMQTTAuthorizer.java | 9 ++ components/extensions/pom.xml | 1 + .../pom.xml | 110 ++++++++++++++++++ ...eviceTypeOperationAdapterSubscription.java | 65 +++++++++++ .../listener/NotificationMessage.java | 49 ++++++++ ...ullNotificationMqttContentTransformer.java | 65 +++++++++++ .../PullNotificationStartupListener.java | 61 ++++++++++ .../internal/MqttNotificationDataHolder.java | 51 ++++++++ ...lNotificationListenerServiceComponent.java | 89 ++++++++++++++ .../util/MqttNotificationListener.java | 71 +++++++++++ .../pull-notification-listeners/pom.xml | 58 +++++++++ .../impl/EventReceiverServiceImpl.java | 7 +- .../impl/AndroidDeviceManagementService.java | 6 + .../impl/WindowsDeviceManagementService.java | 6 + .../pom.xml | 61 ++++++++++ .../src/main/resources/build.properties | 19 +++ .../src/main/resources/p2.inf | 1 + features/extensions-feature/pom.xml | 3 +- pom.xml | 8 +- 20 files changed, 739 insertions(+), 9 deletions(-) create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationStartupListener.java create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/MqttNotificationDataHolder.java create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java create mode 100644 components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java create mode 100644 components/extensions/pull-notification-listeners/pom.xml create mode 100644 features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml create mode 100644 features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/build.properties create mode 100644 features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/p2.inf 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 e6e9fe7001..4d83480569 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 @@ -91,6 +91,10 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { this.topic = PropertyUtils.replaceTenantDomainProperty(topic); this.eventAdapterListener = inputEventAdapterListener; this.tenantDomain = this.topic.split("/")[0]; + //this is to allow server listener from IoT Core to connect. + if (this.tenantDomain.equals("+")) { + this.tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + } //SORTING messages until the server fetches them String temp_directory = System.getProperty("java.io.tmpdir"); @@ -126,8 +130,8 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { .getContentTransformer(contentTransformerType); } } catch (MqttException e) { - log.error("Exception occurred while subscribing to MQTT broker at " - + mqttBrokerConnectionConfiguration.getBrokerUrl()); + log.error("Exception occurred while creating an mqtt client to " + + mqttBrokerConnectionConfiguration.getBrokerUrl() + " reason code:" + e.getReasonCode()); throw new InputEventAdapterRuntimeException(e); } } 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 568c567eca..9d4e609d8d 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 @@ -74,11 +74,13 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { private static Log log = LogFactory.getLog(DeviceAccessBasedMQTTAuthorizer.class); private AuthorizationConfigurationManager MQTTAuthorizationConfiguration; private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0"; + private static final String DEFAULT_ADMIN_PERMISSION = "permission/admin/device-mgt"; private static final String CACHE_MANAGER_NAME = "mqttAuthorizationCacheManager"; private static final String CACHE_NAME = "mqttAuthorizationCache"; private static DeviceAccessAuthorizationAdminService deviceAccessAuthorizationAdminService; private static OAuthRequestInterceptor oAuthRequestInterceptor; private static final String GATEWAY_ERROR_CODE = "404"; + private static final String ALL_TENANT_DOMAIN = "+"; public DeviceAccessBasedMQTTAuthorizer() { oAuthRequestInterceptor = new OAuthRequestInterceptor(); @@ -102,6 +104,13 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { try { String topics[] = topic.split("/"); String tenantDomainFromTopic = topics[0]; + if ("+".equals(tenantDomainFromTopic)) { + if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(authorizationSubject.getTenantDomain()) + && isUserAuthorized(authorizationSubject, DEFAULT_ADMIN_PERMISSION, UI_EXECUTE)) { + return true; + } + return false; + } if (!tenantDomainFromTopic.equals(authorizationSubject.getTenantDomain())) { return false; } diff --git a/components/extensions/pom.xml b/components/extensions/pom.xml index 639275b5a2..0cef1ecda0 100644 --- a/components/extensions/pom.xml +++ b/components/extensions/pom.xml @@ -37,6 +37,7 @@ cdmf-transport-adapters mb-extensions siddhi-extensions + pull-notification-listeners diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml new file mode 100644 index 0000000000..612800260f --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml @@ -0,0 +1,110 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + pull-notification-listeners + 3.0.37-SNAPSHOT + ../pom.xml + + + + 4.0.0 + org.wso2.carbon.device.mgt.mqtt.notification.listener + bundle + WSO2 Carbon - MQTT Pull Notification Listener Implementation + WSO2 Carbon - MQTT Pull Notification Lister Implementation + http://wso2.org + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.input.adapter.core + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.input.adapter.extension + + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.devicemgt.plugins.version} + MQTT Pull Notification Provider Bundle + + !org.wso2.carbon.device.mgt.mqtt.notification.listener.internal, + org.wso2.carbon.device.mgt.mqtt.notification.listener.* + + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.core.service, + com.google.gson, + org.wso2.carbon.context, + org.wso2.carbon.device.mgt.input.adapter.extension, + org.wso2.carbon.event.input.adapter.core, + org.wso2.carbon.event.input.adapter.core.exception, + org.wso2.carbon.user.api, + org.wso2.carbon.core, + org.wso2.carbon.device.mgt.core.config, + org.wso2.carbon.device.mgt.core.config.pull.notification + + + + + + + + diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java new file mode 100644 index 0000000000..b2896991fc --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener; + +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.pull.notification.NotificationContext; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.internal.MqttNotificationDataHolder; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterSubscription; +import org.wso2.carbon.user.api.UserStoreException; + +/** + * Creates a event subscription for the input adapter. + */ +public class DeviceTypeOperationAdapterSubscription implements InputEventAdapterSubscription { + private static final Log log = LogFactory.getLog(DeviceTypeOperationAdapterSubscription.class); + + @Override + public void onEvent(Object o) { + + if (o == null || !(o instanceof NotificationMessage)) { + return; + } + + NotificationMessage notificationMessage = (NotificationMessage) o; + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(notificationMessage.getTenantDomain(), + true); + String deviceType = ""; + try { + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(PrivilegedCarbonContext. + getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName()); + NotificationContext notificationContext = notificationMessage.getNotificationContext(); + deviceType = notificationContext.getDeviceId().getType(); + MqttNotificationDataHolder.getInstance().getDeviceManagementProviderService() + .executePullNotification(deviceType, notificationContext); + } catch (UserStoreException e) { + log.error("Failed to retrieve tenant username", e); + } catch (PullNotificationExecutionFailedException e) { + log.error("Failed to execute device type pull notification subscriber execution for device type" + deviceType, + e); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + + } +} diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java new file mode 100644 index 0000000000..3fdb6e7bc1 --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener; + +import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext; + +public class NotificationMessage { + + private String tenantDomain; + private NotificationContext notificationContext; + + public NotificationMessage(String tenantDomain, NotificationContext notificationContext) { + this.tenantDomain = tenantDomain; + this.notificationContext = notificationContext; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public void setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + } + + public NotificationContext getNotificationContext() { + return notificationContext; + } + + public void setNotificationContext( + NotificationContext notificationContext) { + this.notificationContext = notificationContext; + } +} diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java new file mode 100644 index 0000000000..18b9a331b0 --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext; +import org.wso2.carbon.device.mgt.common.pull.notification.NotificationPayload; +import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer; + +import java.util.Map; + +/** + * This transforms the incomming message payload to notification message, inorder to pass this + * information before its passed to the input adapter subscriber. + */ +public class PullNotificationMqttContentTransformer implements ContentTransformer { + + public static final String MQTT_NOTIFICATION_MESSAGE_TRANSFORMER = "mqtt-notification-transformer"; + + @Override + public String getType() { + return MQTT_NOTIFICATION_MESSAGE_TRANSFORMER; + } + + @Override + public Object transform(Object message, Map dynamicProperties) { + String topic = (String) dynamicProperties.get("topic"); + String[] topicParams = topic.split("/"); + String tenantDomain = topicParams[0]; + String deviceType = topicParams[1]; + String deviceId = topicParams[2]; + Gson gson = new Gson(); + try { + NotificationPayload notificationPayload = gson.fromJson((String) message, NotificationPayload.class); + NotificationContext notificationContext = new NotificationContext + (new DeviceIdentifier(deviceId, deviceType), notificationPayload); + return new NotificationMessage(tenantDomain, notificationContext); + } catch (Exception e) { + //Avoid notification listener to fail. + return new Object(); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + +} diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationStartupListener.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationStartupListener.java new file mode 100644 index 0000000000..5db5acadfa --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationStartupListener.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.internal.MqttNotificationDataHolder; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.util.MqttNotificationListener; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; + +/** + * Startup listener is been used to make sure the reciever gets activated after the server start up to avoid + * Bundle not loading issues. + */ +public class PullNotificationStartupListener implements ServerStartupObserver { + + private static final Log log = LogFactory.getLog(PullNotificationStartupListener.class); + + @Override + public void completingServerStartup() { + } + + @Override + public void completedServerStartup() { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); + try { + //TODO DeviceConfiguration Either need to be a osgi service or need to add those variable to system variables. + boolean isEnabled = DeviceConfigurationManager.getInstance().getDeviceManagementConfig() + .getPullNotificationConfiguration().isEnabled(); + if (isEnabled) { + MqttNotificationListener.setupMqttInputAdapter(); + MqttNotificationDataHolder.getInstance().getInputEventAdapterService().start(); + log.info("Mqtt operation listener activated"); + } + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + +} diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/MqttNotificationDataHolder.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/MqttNotificationDataHolder.java new file mode 100644 index 0000000000..4a95c543fe --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/MqttNotificationDataHolder.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener.internal; + +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService; + +public class MqttNotificationDataHolder { + + private DeviceManagementProviderService deviceManagementProviderService; + private InputEventAdapterService inputEventAdapterService; + + private static MqttNotificationDataHolder thisInstance = new MqttNotificationDataHolder(); + + public static MqttNotificationDataHolder getInstance() { + return thisInstance; + } + + public DeviceManagementProviderService getDeviceManagementProviderService() { + return deviceManagementProviderService; + } + + public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) { + this.deviceManagementProviderService = deviceManagementProviderService; + } + + public InputEventAdapterService getInputEventAdapterService() { + return inputEventAdapterService; + } + + public void setInputEventAdapterService( + InputEventAdapterService inputEventAdapterService) { + this.inputEventAdapterService = inputEventAdapterService; + } +} diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java new file mode 100644 index 0000000000..df15fe2cf2 --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.PullNotificationMqttContentTransformer; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.PullNotificationStartupListener; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.util.MqttNotificationListener; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService; + +/** + * @scr.component name="org.wso2.carbon.device.mgt.mqtt.notification.listener.internal.PullNotificationListenerServiceComponent" immediate="true" + * @scr.reference name="carbon.device.mgt.provider" + * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDeviceManagementProviderService" + * unbind="unsetDeviceManagementProviderService" + * @scr.reference name="event.input.adapter.service" + * interface="org.wso2.carbon.event.input.adapter.core.InputEventAdapterService" + * cardinality="1..1" + * policy="dynamic" + * bind="setInputEventAdapterService" + * unbind="unsetInputEventAdapterService" + */ +public class PullNotificationListenerServiceComponent { + + private static final Log log = LogFactory.getLog(PullNotificationListenerServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + try { + //Do nothing + if (log.isDebugEnabled()) { + log.debug("pull notification provider implementation bundle has been successfully " + + "initialized"); + } + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(ServerStartupObserver.class.getName(), new PullNotificationStartupListener(), + null); + bundleContext.registerService(ContentTransformer.class.getName(), new PullNotificationMqttContentTransformer(), null); + } catch (Throwable e) { + log.error("Error occurred while initializing pull notification provider implementation bundle", e); + } + } + + protected void deactivate(ComponentContext componentContext) { + //Do nothing + } + + protected void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) { + MqttNotificationDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); + } + + protected void unsetDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) { + MqttNotificationDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); + } + + protected void setInputEventAdapterService(InputEventAdapterService inputEventAdapterService) { + MqttNotificationDataHolder.getInstance().setInputEventAdapterService(inputEventAdapterService); + } + + protected void unsetInputEventAdapterService(InputEventAdapterService inputEventAdapterService) { + MqttNotificationDataHolder.getInstance().setInputEventAdapterService(null); + } + +} diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java new file mode 100644 index 0000000000..3f0c4048f5 --- /dev/null +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.mqtt.notification.listener.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.DeviceTypeOperationAdapterSubscription; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.PullNotificationMqttContentTransformer; +import org.wso2.carbon.device.mgt.mqtt.notification.listener.internal.MqttNotificationDataHolder; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration; +import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; + +import java.util.HashMap; +import java.util.Map; + +/** + * This creates a link between input adapter and the subscription of the input adpater. + */ +public class MqttNotificationListener { + private static final Log log = LogFactory.getLog(MqttNotificationListener.class); + + private static final String TOPIC = "topic"; + private static final String SUBSCRIBED_TOPIC = "+/+/+/update/operation"; + private static final String TYPE = "oauth-mqtt"; + private static final String JSON = "json"; + private static final String NAME = "iot_core_server_adapter"; + private static final String CONTENT_TRANSFORMER_TYPE = "contentTransformer"; + + + public static void setupMqttInputAdapter() { + InputEventAdapterConfiguration inputEventAdapterConfiguration = new InputEventAdapterConfiguration(); + inputEventAdapterConfiguration.setName(NAME); + inputEventAdapterConfiguration.setType(TYPE); + inputEventAdapterConfiguration.setMessageFormat(JSON); + Map mqttAdapterProperties = new HashMap<>(); + mqttAdapterProperties.put(TOPIC, SUBSCRIBED_TOPIC); + mqttAdapterProperties.put(CONTENT_TRANSFORMER_TYPE, + PullNotificationMqttContentTransformer.MQTT_NOTIFICATION_MESSAGE_TRANSFORMER); + inputEventAdapterConfiguration.setProperties(mqttAdapterProperties); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants + .SUPER_TENANT_DOMAIN_NAME, true); + MqttNotificationDataHolder.getInstance().getInputEventAdapterService() + .create(inputEventAdapterConfiguration, new DeviceTypeOperationAdapterSubscription()); + } catch (InputEventAdapterException e) { + log.error("Unable to create Input Event Adapter for pull notification.", e); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + +} diff --git a/components/extensions/pull-notification-listeners/pom.xml b/components/extensions/pull-notification-listeners/pom.xml new file mode 100644 index 0000000000..54240211b2 --- /dev/null +++ b/components/extensions/pull-notification-listeners/pom.xml @@ -0,0 +1,58 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + extensions + 3.0.37-SNAPSHOT + ../pom.xml + + + 4.0.0 + pull-notification-listeners + pom + WSO2 Carbon - Pull Notification Extension + http://wso2.org + + + org.wso2.carbon.device.mgt.mqtt.notification.listener + + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java index 362289b2ca..f56fba52c6 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java @@ -53,12 +53,11 @@ public class EventReceiverServiceImpl implements EventReceiverService { log.debug("Invoking Android device even logging."); } Message message = new Message(); - Object metaData[] = {eventBeanWrapper.getDeviceIdentifier()}; - - Object payload[] = {eventBeanWrapper.getPayload(), eventBeanWrapper.getType()}; + Object payload[] = {eventBeanWrapper.getDeviceIdentifier(), + eventBeanWrapper.getPayload(), eventBeanWrapper.getType()}; try { if (AndroidAPIUtils.getEventPublisherService().publishEvent( - EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) { + EVENT_STREAM_DEFINITION, "1.0.0", new Object[0], new Object[0], payload)) { message.setResponseCode("Event is published successfully."); return Response.status(Response.Status.CREATED).entity(message).build(); } else { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManagementService.java index fb8ef11775..5dc35ce60f 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManagementService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManagementService.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.mobile.android.impl.util.AndroidPluginConstants; @@ -120,6 +121,11 @@ public class AndroidDeviceManagementService implements DeviceManagementService { return null; } + @Override + public PullNotificationSubscriber getPullNotificationSubscriber() { + return null; + } + private String getConfigProperty(List configs, String propertyName) { for (ConfigurationEntry entry : configs) { if (propertyName.equals(entry.getName())) { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManagementService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManagementService.java index f3cc7b364b..d6b635df39 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManagementService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsDeviceManagementService.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.mobile.windows.impl; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; @@ -80,4 +81,9 @@ public class WindowsDeviceManagementService implements DeviceManagementService { return null; } + @Override + public PullNotificationSubscriber getPullNotificationSubscriber() { + return null; + } + } diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml new file mode 100644 index 0000000000..52e7817fee --- /dev/null +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml @@ -0,0 +1,61 @@ + + + + org.wso2.carbon.devicemgt-plugins + extensions-feature + 3.0.37-SNAPSHOT + ../pom.xml + + 4.0.0 + + org.wso2.carbon.device.mgt.notification.listener.feature + pom + 3.0.37-SNAPSHOT + WSO2 Carbon - Notification Listener + http://wso2.org + This feature contains the core bundles required iot core listeners + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mqtt.notification.listener + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + 4-p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.device.mgt.notification.listener + ../etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mqtt.notification.listener:${carbon.devicemgt.plugins.version} + + + + + + + + + + \ No newline at end of file diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/build.properties b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..33bb0980d3 --- /dev/null +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/build.properties @@ -0,0 +1,19 @@ +# +# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +custom = true diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/p2.inf b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..7ab37b9d7d --- /dev/null +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/extensions-feature/pom.xml b/features/extensions-feature/pom.xml index 0f2b2d9964..dd157efd03 100644 --- a/features/extensions-feature/pom.xml +++ b/features/extensions-feature/pom.xml @@ -39,6 +39,7 @@ org.wso2.carbon.device.mgt.adapter.feature org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature org.wso2.extension.siddhi.execution.json.feature - + org.wso2.carbon.device.mgt.notification.listener.feature + diff --git a/pom.xml b/pom.xml index b3d7b36fde..8bd3b46c52 100644 --- a/pom.xml +++ b/pom.xml @@ -453,7 +453,11 @@ org.wso2.carbon.device.mgt.output.adapter.websocket ${carbon.devicemgt.plugins.version} - + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mqtt.notification.listener + ${carbon.devicemgt.plugins.version} + org.wso2.carbon.devicemgt-plugins @@ -1153,7 +1157,7 @@ 1.1.1 - 2.0.58 + 2.0.69-SNAPSHOT [2.0.0, 3.0.0) From 3a7536f1f654ad09ceb0bf7a926cb3672c9ff580 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 1 Jun 2017 23:26:02 +0530 Subject: [PATCH 02/14] update version --- .../org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml | 2 +- .../pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml index ad9d9789eb..f959963920 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 3.0.37-SNAPSHOT + 3.0.38-SNAPSHOT ../../pom.xml diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml index 52e7817fee..ccfcaef415 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml @@ -5,7 +5,7 @@ org.wso2.carbon.devicemgt-plugins extensions-feature - 3.0.37-SNAPSHOT + 3.0.38-SNAPSHOT ../pom.xml 4.0.0 From 9dc836928ca94546312e084f93227adb520f8d1f Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sat, 3 Jun 2017 13:27:40 +0530 Subject: [PATCH 03/14] few changes on content transformation logic --- .../transformer/MQTTContentTransformer.java | 89 +++++++++++++++++++ .../validator/MQTTContentValidator.java | 13 ++- ...eviceTypeOperationAdapterSubscription.java | 9 +- .../listener/NotificationMessage.java | 27 ++++-- ...ullNotificationMqttContentTransformer.java | 10 +-- .../pom.xml | 2 +- pom.xml | 2 +- 7 files changed, 123 insertions(+), 29 deletions(-) create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java new file mode 100644 index 0000000000..e3a89d0180 --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java @@ -0,0 +1,89 @@ +/* +* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.device.mgt.input.adapter.extension.transformer; + +import com.jayway.jsonpath.JsonPath; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer; + +import java.util.Map; + +/** + * This holds the default implementation of ContentTransformer + */ +public class MQTTContentTransformer implements ContentTransformer { + private static final String MQTT_CONTENT_TRANSFORMER = "iot-mqtt"; + private static final String TOPIC = "topic"; + private static String JSON_ARRAY_START_CHAR = "["; + + private static final Log log = LogFactory.getLog(MQTTContentTransformer.class); + + @Override + public String getType() { + return MQTT_CONTENT_TRANSFORMER; + } + + @Override + public Object transform(Object messagePayload, Map dynamicProperties) { + String topic = (String) dynamicProperties.get(TOPIC); + String topics[] = topic.split("/"); + String deviceId = topics[2]; + String deviceType = topics[1]; + String message = (String) messagePayload; + try { + if (message.startsWith(JSON_ARRAY_START_CHAR)) { + return processMultipleEvents(message, deviceId, deviceType); + } else { + return processSingleEvent(message, deviceId, deviceType); + } + } catch (ParseException e) { + log.error("Invalid input " + message, e); + return false; + } + } + + private String processSingleEvent(String msg, String deviceIdFromTopic, String deviceIdJsonPath) + throws ParseException { + JSONParser parser = new JSONParser(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("deviceId", deviceIdFromTopic); + JSONObject eventObject = new JSONObject(); + eventObject.put("payloadData", parser.parse(msg)); + eventObject.put("metaData", jsonObject); + JSONObject event = new JSONObject(); + event.put("event", eventObject); + return event.toJSONString(); + } + + private String processMultipleEvents(String msg, String deviceIdFromTopic, String deviceIdJsonPath) + throws ParseException { + JSONParser jsonParser = new JSONParser(); + JSONArray jsonArray = (JSONArray) jsonParser.parse(msg); + JSONArray eventsArray = new JSONArray(); + for (int i = 0; i < jsonArray.size(); i++) { + eventsArray.add(i, processSingleEvent(jsonArray.get(i).toString(), deviceIdFromTopic, deviceIdJsonPath)); + } + return eventsArray.toJSONString(); + } +} diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java index 3322acb9db..f395178b5a 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java @@ -33,10 +33,10 @@ public class MQTTContentValidator implements ContentValidator { private static final String JSON_ARRAY_START_CHAR = "["; private static final Log log = LogFactory.getLog(MQTTContentValidator.class); private static final String CDMF_MQTT_CONTENT_VALIDATOR = "iot-mqtt"; - public static final String DEVICE_ID_JSON_PATH = "event.metaData.deviceId"; - public static final String DEVICE_TYPE_JSON_PATH = "event.metaData.deviceId"; - public static final String TOPIC = "topic"; - public static final int DEVICE_ID_TOPIC_HIERARCHY_INDEX = 2; + private static final String DEVICE_ID_JSON_PATH = "event.metaData.deviceId"; + private static final String DEVICE_TYPE_JSON_PATH = "event.metaData.deviceId"; + private static final String TOPIC = "topic"; + private static final int DEVICE_ID_TOPIC_HIERARCHY_INDEX = 2; @Override public String getType() { @@ -47,15 +47,14 @@ public class MQTTContentValidator implements ContentValidator { public ContentInfo validate(Object msgPayload, Map dynamicParams) { String topic = (String) dynamicParams.get(TOPIC); String topics[] = topic.split("/"); - String deviceIdJsonPath = DEVICE_ID_JSON_PATH; int deviceIdInTopicHierarchyLevelIndex = DEVICE_ID_TOPIC_HIERARCHY_INDEX; String deviceIdFromTopic = topics[deviceIdInTopicHierarchyLevelIndex]; boolean status; String message = (String) msgPayload; if (message.startsWith(JSON_ARRAY_START_CHAR)) { - status = processMultipleEvents(message, deviceIdFromTopic, deviceIdJsonPath); + status = processMultipleEvents(message, deviceIdFromTopic, DEVICE_ID_JSON_PATH); } else { - status = processSingleEvent(message, deviceIdFromTopic, deviceIdJsonPath); + status = processSingleEvent(message, deviceIdFromTopic, DEVICE_ID_JSON_PATH); } return new ContentInfo(status, msgPayload); } diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java index b2896991fc..7dcda874c5 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.mqtt.notification.listener; 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.pull.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.mqtt.notification.listener.internal.MqttNotificationDataHolder; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterSubscription; @@ -48,10 +47,10 @@ public class DeviceTypeOperationAdapterSubscription implements InputEventAdapter try { PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(PrivilegedCarbonContext. getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName()); - NotificationContext notificationContext = notificationMessage.getNotificationContext(); - deviceType = notificationContext.getDeviceId().getType(); - MqttNotificationDataHolder.getInstance().getDeviceManagementProviderService() - .executePullNotification(deviceType, notificationContext); + deviceType = notificationMessage.getDeviceIdentifier().getType(); + MqttNotificationDataHolder.getInstance().getDeviceManagementProviderService(). + updatePullNotificationOperation(notificationMessage.getDeviceIdentifier(), + notificationMessage.getOperation()); } catch (UserStoreException e) { log.error("Failed to retrieve tenant username", e); } catch (PullNotificationExecutionFailedException e) { diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java index 3fdb6e7bc1..dfd17e29da 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/NotificationMessage.java @@ -18,16 +18,19 @@ */ package org.wso2.carbon.device.mgt.mqtt.notification.listener; -import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; public class NotificationMessage { private String tenantDomain; - private NotificationContext notificationContext; + private DeviceIdentifier deviceIdentifier; + private Operation operation; - public NotificationMessage(String tenantDomain, NotificationContext notificationContext) { + public NotificationMessage(String tenantDomain, DeviceIdentifier deviceIdentifier,Operation operation) { this.tenantDomain = tenantDomain; - this.notificationContext = notificationContext; + this.operation = operation; + this.deviceIdentifier = deviceIdentifier; } public String getTenantDomain() { @@ -38,12 +41,20 @@ public class NotificationMessage { this.tenantDomain = tenantDomain; } - public NotificationContext getNotificationContext() { - return notificationContext; + public Operation getOperation() { + return operation; } public void setNotificationContext( - NotificationContext notificationContext) { - this.notificationContext = notificationContext; + Operation operation) { + this.operation = operation; + } + + public DeviceIdentifier getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; } } diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java index 18b9a331b0..1f5a2417f6 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java @@ -19,11 +19,9 @@ package org.wso2.carbon.device.mgt.mqtt.notification.listener; import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.pull.notification.NotificationContext; -import org.wso2.carbon.device.mgt.common.pull.notification.NotificationPayload; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer; import java.util.Map; @@ -50,10 +48,8 @@ public class PullNotificationMqttContentTransformer implements ContentTransforme String deviceId = topicParams[2]; Gson gson = new Gson(); try { - NotificationPayload notificationPayload = gson.fromJson((String) message, NotificationPayload.class); - NotificationContext notificationContext = new NotificationContext - (new DeviceIdentifier(deviceId, deviceType), notificationPayload); - return new NotificationMessage(tenantDomain, notificationContext); + Operation operation = gson.fromJson((String) message, Operation.class); + return new NotificationMessage(tenantDomain, new DeviceIdentifier(deviceId, deviceType),operation); } catch (Exception e) { //Avoid notification listener to fail. return new Object(); diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml index ccfcaef415..3e8c65d6b6 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml @@ -12,7 +12,7 @@ org.wso2.carbon.device.mgt.notification.listener.feature pom - 3.0.37-SNAPSHOT + 3.0.38-SNAPSHOT WSO2 Carbon - Notification Listener http://wso2.org This feature contains the core bundles required iot core listeners diff --git a/pom.xml b/pom.xml index e0f052795b..ad77c31462 100644 --- a/pom.xml +++ b/pom.xml @@ -1157,7 +1157,7 @@ 1.1.1 - 2.0.69-SNAPSHOT + 2.0.71-SNAPSHOT [2.0.0, 3.0.0) From 796de7456fa8e4d155c2f583c791e6a966130e61 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sun, 4 Jun 2017 06:52:51 +0530 Subject: [PATCH 04/14] Few changes after testing mqtt and http flow --- .../extension/internal/InputAdapterServiceComponent.java | 8 +++++--- .../extension/transformer/MQTTContentTransformer.java | 2 +- .../adapter/extension/validator/MQTTContentValidator.java | 2 +- .../mgt/input/adapter/mqtt/MQTTEventAdapterFactory.java | 2 +- .../mgt/input/adapter/mqtt/util/MQTTAdapterListener.java | 4 ++-- .../mqtt/util/MQTTBrokerConnectionConfiguration.java | 8 ++++++++ .../adapter/mqtt/util/MQTTEventAdapterConstants.java | 1 + .../listener/PullNotificationMqttContentTransformer.java | 4 +--- .../PullNotificationListenerServiceComponent.java | 2 +- .../listener/util/MqttNotificationListener.java | 3 +++ 10 files changed, 24 insertions(+), 12 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/internal/InputAdapterServiceComponent.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/internal/InputAdapterServiceComponent.java index b7370fa3aa..ee41c354dc 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/internal/InputAdapterServiceComponent.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/internal/InputAdapterServiceComponent.java @@ -25,19 +25,20 @@ import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator; import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService; import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionServiceImpl; import org.wso2.carbon.device.mgt.input.adapter.extension.transformer.DefaultContentTransformer; +import org.wso2.carbon.device.mgt.input.adapter.extension.transformer.MQTTContentTransformer; import org.wso2.carbon.device.mgt.input.adapter.extension.validator.DefaultContentValidator; import org.wso2.carbon.device.mgt.input.adapter.extension.validator.HTTPContentValidator; import org.wso2.carbon.device.mgt.input.adapter.extension.validator.MQTTContentValidator; /** * @scr.component name="input.adapter.extension.adapterService.component" immediate="true" - * @scr.reference name="InputAdapterServiceComponent.service" + * @scr.reference name="InputAdapterServiceComponent.content.validator.service" * interface="org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator" * cardinality="0..n" * policy="dynamic" * bind="setContentValidator" * unbind="unsetContentValidator" - * * @scr.reference name="InputAdapterServiceComponent.service" + * @scr.reference name="InputAdapterServiceComponent.transformer.service" * interface="org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer" * cardinality="0..n" * policy="dynamic" @@ -56,6 +57,7 @@ public class InputAdapterServiceComponent { } InputAdapterServiceDataHolder.getInstance().addContentTransformer(new DefaultContentTransformer()); + InputAdapterServiceDataHolder.getInstance().addContentTransformer(new MQTTContentTransformer()); InputAdapterServiceDataHolder.getInstance().addContentValidator(new DefaultContentValidator()); InputAdapterServiceDataHolder.getInstance().addContentValidator(new HTTPContentValidator()); InputAdapterServiceDataHolder.getInstance().addContentValidator(new MQTTContentValidator()); @@ -87,7 +89,7 @@ public class InputAdapterServiceComponent { InputAdapterServiceDataHolder.getInstance().addContentTransformer(contentTransformer); } - protected void unsetContentValidator(ContentTransformer contentTransformer) { + protected void unsetContentTransformer(ContentTransformer contentTransformer) { if (log.isDebugEnabled()) { log.debug("Un-setting ContentTransformer Service"); } diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java index e3a89d0180..fba9340096 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/MQTTContentTransformer.java @@ -33,7 +33,7 @@ import java.util.Map; * This holds the default implementation of ContentTransformer */ public class MQTTContentTransformer implements ContentTransformer { - private static final String MQTT_CONTENT_TRANSFORMER = "iot-mqtt"; + private static final String MQTT_CONTENT_TRANSFORMER = "device-meta-transformer"; private static final String TOPIC = "topic"; private static String JSON_ARRAY_START_CHAR = "["; diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java index f395178b5a..20261ab6d9 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java @@ -32,7 +32,7 @@ import java.util.Map; public class MQTTContentValidator implements ContentValidator { private static final String JSON_ARRAY_START_CHAR = "["; private static final Log log = LogFactory.getLog(MQTTContentValidator.class); - private static final String CDMF_MQTT_CONTENT_VALIDATOR = "iot-mqtt"; + private static final String CDMF_MQTT_CONTENT_VALIDATOR = "deviceid-topic-content-validator"; private static final String DEVICE_ID_JSON_PATH = "event.metaData.deviceId"; private static final String DEVICE_TYPE_JSON_PATH = "event.metaData.deviceId"; private static final String TOPIC = "topic"; 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/MQTTEventAdapterFactory.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/MQTTEventAdapterFactory.java index f5f93b17a7..54f0ec364b 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/MQTTEventAdapterFactory.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/MQTTEventAdapterFactory.java @@ -114,7 +114,7 @@ public class MQTTEventAdapterFactory extends InputEventAdapterFactory { contentTransformer.setRequired(false); contentTransformer.setHint( resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_TRANSFORMER_TYPE_HINT)); - contentTransformer.setDefaultValue(MQTTEventAdapterConstants.DEFAULT); + contentTransformer.setDefaultValue(MQTTEventAdapterConstants.EMPTY); propertyList.add(contentTransformer); // set clientId 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 4d83480569..968faa4311 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 @@ -271,8 +271,8 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { ContentInfo contentInfo; Map dynamicProperties = new HashMap<>(); dynamicProperties.put(MQTTEventAdapterConstants.TOPIC, topic); - msgText = (String) contentTransformer.transform(msgText, dynamicProperties); - contentInfo = contentValidator.validate(msgText, dynamicProperties); + Object transformedMessage = contentTransformer.transform(msgText, dynamicProperties); + contentInfo = contentValidator.validate(transformedMessage, dynamicProperties); if (contentInfo != null && contentInfo.isValidContent()) { inputEventAdapterListener.onEvent(contentInfo.getMessage()); } 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/MQTTBrokerConnectionConfiguration.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/MQTTBrokerConnectionConfiguration.java index 32669bd965..b32e7d6d93 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/MQTTBrokerConnectionConfiguration.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/MQTTBrokerConnectionConfiguration.java @@ -106,9 +106,17 @@ public class MQTTBrokerConnectionConfiguration { this.dcrUrl = PropertyUtils .replaceMqttProperty(globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_DCR_URL)); this.contentValidatorType = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE); + String contentValidatorTypeLocal = eventAdapterConfiguration.getProperties() + .get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE); if (contentValidatorType == null || contentValidatorType.isEmpty()) { this.contentValidatorType = eventAdapterConfiguration.getProperties() .get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE); + } else if (contentValidatorTypeLocal != null && !contentValidatorTypeLocal.equals(MQTTEventAdapterConstants.EMPTY)) { + this.contentValidatorType = eventAdapterConfiguration.getProperties() + .get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE); + } + if (this.contentValidatorType.equals(MQTTEventAdapterConstants.EMPTY)) { + this.contentValidatorType = MQTTEventAdapterConstants.DEFAULT; } String cleanSession = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION); if (cleanSession == null || cleanSession.isEmpty()) { 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/MQTTEventAdapterConstants.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/MQTTEventAdapterConstants.java index 0a0b09e2a7..7c80d8a1d3 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/MQTTEventAdapterConstants.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/MQTTEventAdapterConstants.java @@ -61,6 +61,7 @@ public class MQTTEventAdapterConstants { public static final String CLIENT_SECRET = "clientSecret"; public static final String CLIENT_NAME = "client_name"; public static final String DEFAULT = "default"; + public static final String EMPTY = ""; public static final String MQTT_CONTENT_VALIDATION_DEFAULT_PARAMETERS = ""; public static final String TOPIC = "topic"; public static final String PAYLOAD = "payload"; diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java index 1f5a2417f6..476b4eba0c 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/PullNotificationMqttContentTransformer.java @@ -32,7 +32,7 @@ import java.util.Map; */ public class PullNotificationMqttContentTransformer implements ContentTransformer { - public static final String MQTT_NOTIFICATION_MESSAGE_TRANSFORMER = "mqtt-notification-transformer"; + public static final String MQTT_NOTIFICATION_MESSAGE_TRANSFORMER = "mqtt-operation-transformer"; @Override public String getType() { @@ -53,8 +53,6 @@ public class PullNotificationMqttContentTransformer implements ContentTransforme } catch (Exception e) { //Avoid notification listener to fail. return new Object(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); } } diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java index df15fe2cf2..7e94759154 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java @@ -60,7 +60,7 @@ public class PullNotificationListenerServiceComponent { BundleContext bundleContext = componentContext.getBundleContext(); bundleContext.registerService(ServerStartupObserver.class.getName(), new PullNotificationStartupListener(), null); - bundleContext.registerService(ContentTransformer.class.getName(), new PullNotificationMqttContentTransformer(), null); + bundleContext.registerService(ContentTransformer.class, new PullNotificationMqttContentTransformer(), null); } catch (Throwable e) { log.error("Error occurred while initializing pull notification provider implementation bundle", e); } diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java index 3f0c4048f5..08800272d6 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/util/MqttNotificationListener.java @@ -43,6 +43,8 @@ public class MqttNotificationListener { private static final String JSON = "json"; private static final String NAME = "iot_core_server_adapter"; private static final String CONTENT_TRANSFORMER_TYPE = "contentTransformer"; + private static final String MQTT_CONTENT_VALIDATOR_TYPE = "contentValidator"; + private static final String MQTT_CONTENT_VALIDATOR = "default"; public static void setupMqttInputAdapter() { @@ -54,6 +56,7 @@ public class MqttNotificationListener { mqttAdapterProperties.put(TOPIC, SUBSCRIBED_TOPIC); mqttAdapterProperties.put(CONTENT_TRANSFORMER_TYPE, PullNotificationMqttContentTransformer.MQTT_NOTIFICATION_MESSAGE_TRANSFORMER); + mqttAdapterProperties.put(MQTT_CONTENT_VALIDATOR_TYPE, MQTT_CONTENT_VALIDATOR); inputEventAdapterConfiguration.setProperties(mqttAdapterProperties); try { PrivilegedCarbonContext.startTenantFlow(); From 6b8682f2d889fb4bbfb6a44a73fdf59646f43619 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sun, 4 Jun 2017 18:18:20 +0530 Subject: [PATCH 05/14] few fixes after testing --- .../mgt/input/adapter/mqtt/MQTTEventAdapter.java | 12 ++++++++---- .../pom.xml | 3 ++- 2 files changed, 10 insertions(+), 5 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/MQTTEventAdapter.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/MQTTEventAdapter.java index 76239163bb..21381e722b 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/MQTTEventAdapter.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/MQTTEventAdapter.java @@ -84,8 +84,10 @@ public class MQTTEventAdapter implements InputEventAdapter { .equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { return; } - if (!mqttAdapterListener.isConnectionInitialized()) { - mqttAdapterListener.createConnection(); + synchronized (this.mqttAdapterListener) { + if (!mqttAdapterListener.isConnectionInitialized()) { + mqttAdapterListener.createConnection(); + } } } @@ -102,8 +104,10 @@ public class MQTTEventAdapter implements InputEventAdapter { if (ServerStatus.getCurrentStatus().equals(ServerStatus.STATUS_SHUTTING_DOWN)) { Thread thread = new Thread(new Runnable() { public void run() { - if (mqttAdapterListener != null) { - mqttAdapterListener.stopListener(eventAdapterConfiguration.getName()); + synchronized (mqttAdapterListener) { + if (mqttAdapterListener != null) { + mqttAdapterListener.stopListener(eventAdapterConfiguration.getName()); + } } } }); diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml index 3334bfafee..bcd8f8bdb7 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml @@ -99,7 +99,8 @@ org.wso2.carbon.user.api, org.wso2.carbon.core, org.wso2.carbon.device.mgt.core.config, - org.wso2.carbon.device.mgt.core.config.pull.notification + org.wso2.carbon.device.mgt.core.config.pull.notification, + org.wso2.carbon.utils.multitenancy From bef24e75d167aedbf155e26acb16ebfbdb595342 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 6 Jun 2017 11:01:04 +0530 Subject: [PATCH 06/14] fixed few issues after testing --- .../listener/DeviceTypeOperationAdapterSubscription.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java index 7dcda874c5..f59d96415e 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java @@ -49,8 +49,8 @@ public class DeviceTypeOperationAdapterSubscription implements InputEventAdapter getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName()); deviceType = notificationMessage.getDeviceIdentifier().getType(); MqttNotificationDataHolder.getInstance().getDeviceManagementProviderService(). - updatePullNotificationOperation(notificationMessage.getDeviceIdentifier(), - notificationMessage.getOperation()); + notifyPullNotificationSubscriber(notificationMessage.getDeviceIdentifier(), + notificationMessage.getOperation()); } catch (UserStoreException e) { log.error("Failed to retrieve tenant username", e); } catch (PullNotificationExecutionFailedException e) { From b96ba00d6cd69f3de12afa36465371469f308870 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 8 Jun 2017 14:45:46 +0530 Subject: [PATCH 07/14] updated pom version --- .../org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml | 2 +- .../pom.xml | 2 +- components/extensions/pull-notification-listeners/pom.xml | 2 +- .../pom.xml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml index 85935dbf80..7c26ab25f3 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 3.0.39-SNAPSHOT + 3.0.41-SNAPSHOT ../../pom.xml diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml index bcd8f8bdb7..00f353bd6c 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins pull-notification-listeners - 3.0.39-SNAPSHOT + 3.0.41-SNAPSHOT ../pom.xml diff --git a/components/extensions/pull-notification-listeners/pom.xml b/components/extensions/pull-notification-listeners/pom.xml index b8c8bb1589..9e8ef0429f 100644 --- a/components/extensions/pull-notification-listeners/pom.xml +++ b/components/extensions/pull-notification-listeners/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 3.0.39-SNAPSHOT + 3.0.41-SNAPSHOT ../pom.xml diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml index 1ea456b52c..bbd0150f4b 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml @@ -5,14 +5,14 @@ org.wso2.carbon.devicemgt-plugins extensions-feature - 3.0.39-SNAPSHOT + 3.0.41-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.notification.listener.feature pom - 3.0.39-SNAPSHOT + 3.0.41-SNAPSHOT WSO2 Carbon - Notification Listener http://wso2.org This feature contains the core bundles required iot core listeners From b02bb795612689ca1ee9a304bf9d0ae4b9fd00d7 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 12 Jun 2017 11:40:24 +0530 Subject: [PATCH 08/14] removed unused files --- .../pom.xml | 7 --- .../src/main/resources/p2.inf | 3 +- .../main/resources/websocket-validation.xml | 50 ------------------- pom.xml | 2 +- 4 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/websocket-validation.xml diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml index 0ba2b296db..25cdd06817 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml @@ -52,10 +52,6 @@ org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.input.adapter.extension - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.input.adapter.http - org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.input.adapter.mqtt @@ -176,9 +172,6 @@ org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.input.adapter.extension:${carbon.devicemgt.plugins.version} - - org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.input.adapter.http:${carbon.devicemgt.plugins.version} - org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.input.adapter.mqtt:${carbon.devicemgt.plugins.version} diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/p2.inf b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/p2.inf index f9b3d0c5b3..e47305adad 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/p2.inf +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/p2.inf @@ -1,4 +1,3 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.adapter_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.adapter_${feature.version}/websocket-validation.xml,target:${installFolder}/../../conf/etc/websocket-validation.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.adapter_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\ \ No newline at end of file diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/websocket-validation.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/websocket-validation.xml deleted file mode 100644 index b8c789dc7d..0000000000 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/src/main/resources/websocket-validation.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - https://localhost:9443/services/OAuth2TokenValidationService - admin - admin - 2 - 100 - - - - - - - - /permission/device-mgt/user/groups/device_monitor - admin - admin - https://localhost:9443/oauth2 - - 100 - https://localhost:9443 - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 29f8d7a612..6f8ce060ec 100644 --- a/pom.xml +++ b/pom.xml @@ -1157,7 +1157,7 @@ 1.1.1 - 2.0.72-SNAPSHOT + 2.0.74-SNAPSHOT [2.0.0, 3.0.0) From e36fcfad374637f00316f74c3a02f237c9cf22bb Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 14 Jun 2017 13:23:24 +0530 Subject: [PATCH 09/14] updated version --- .../org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml | 2 +- .../pom.xml | 2 +- components/extensions/pull-notification-listeners/pom.xml | 2 +- .../pom.xml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml index b9eabf3e8f..1442eea712 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins cdmf-transport-adapters - 3.0.42-SNAPSHOT + 3.0.43-SNAPSHOT ../../pom.xml diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml index 7f1ba61422..f74b2e2b4c 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins pull-notification-listeners - 3.0.42-SNAPSHOT + 3.0.43-SNAPSHOT ../pom.xml diff --git a/components/extensions/pull-notification-listeners/pom.xml b/components/extensions/pull-notification-listeners/pom.xml index e50121c2a1..5476543c2e 100644 --- a/components/extensions/pull-notification-listeners/pom.xml +++ b/components/extensions/pull-notification-listeners/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt-plugins extensions - 3.0.42-SNAPSHOT + 3.0.43-SNAPSHOT ../pom.xml diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml index c48bf5113b..8545668232 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.notification.listener.feature/pom.xml @@ -5,14 +5,14 @@ org.wso2.carbon.devicemgt-plugins extensions-feature - 3.0.42-SNAPSHOT + 3.0.43-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.notification.listener.feature pom - 3.0.42-SNAPSHOT + 3.0.43-SNAPSHOT WSO2 Carbon - Notification Listener http://wso2.org This feature contains the core bundles required iot core listeners From b14ddd609a86df9dbb1289fcc99f1763d0096b4f Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sat, 17 Jun 2017 18:54:39 +0530 Subject: [PATCH 10/14] fixing few issues after testing --- .../device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java | 2 +- .../mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java | 2 +- .../mgt/mqtt/authorization/client/OAuthRequestInterceptor.java | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java index b3351234f6..bc07e8621d 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java @@ -84,7 +84,7 @@ public class MQTTEventAdapterFactory extends OutputEventAdapterFactory { clearSession.setDisplayName(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION)); clearSession.setRequired(false); clearSession.setOptions(new String[]{"true", "false"}); - clearSession.setDefaultValue("true"); + clearSession.setDefaultValue("false"); clearSession.setHint(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION_HINT)); // set Quality of Service 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 9d4e609d8d..7859a673f9 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 @@ -133,7 +133,7 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { return false; } catch (FeignException e) { oAuthRequestInterceptor.resetApiApplicationKey(); - if (e.getMessage().contains(GATEWAY_ERROR_CODE)) { + if (e.getMessage().contains(GATEWAY_ERROR_CODE) || e.status() == 404) { log.error("Failed to connect to the device authorization service."); } else { log.error(e.getMessage(), e); 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/client/OAuthRequestInterceptor.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/client/OAuthRequestInterceptor.java index d2917f59e8..4c098deb0c 100755 --- 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/client/OAuthRequestInterceptor.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/client/OAuthRequestInterceptor.java @@ -125,6 +125,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { public void resetApiApplicationKey() { apiApplicationKey = null; + tokenIssuerService = null; } private static Client getSSLClient() { From e708a4a7c569568258e177bdd58409fe83ee06b0 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 20 Jun 2017 19:33:12 +0530 Subject: [PATCH 11/14] few changes on analytics --- .../carbonapps/virtualfirealarm/artifacts.xml | 2 +- .../artifact.xml | 4 ++-- .../virtual_firealarm_publisher.xml} | 2 +- .../adapter/mqtt/MQTTEventAdapterFactory.java | 2 +- .../pom.xml | 22 ------------------- .../pom.xml | 22 ------------------- 6 files changed, 5 insertions(+), 49 deletions(-) rename components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/{temperature_publisher => virtual_firealarm_publisher}/artifact.xml (81%) rename components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/{temperature_publisher/temperature_publisher.xml => virtual_firealarm_publisher/virtual_firealarm_publisher.xml} (87%) diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml index 97f0428d9d..5406c20d55 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml @@ -20,7 +20,7 @@ - + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/temperature_publisher/artifact.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtual_firealarm_publisher/artifact.xml similarity index 81% rename from components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/temperature_publisher/artifact.xml rename to components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtual_firealarm_publisher/artifact.xml index 752cb8c410..096e481528 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/temperature_publisher/artifact.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtual_firealarm_publisher/artifact.xml @@ -17,6 +17,6 @@ ~ under the License. --> - - temperature_publisher.xml + + virtual_firealarm_publisher.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/temperature_publisher/temperature_publisher.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtual_firealarm_publisher/virtual_firealarm_publisher.xml similarity index 87% rename from components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/temperature_publisher/temperature_publisher.xml rename to components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtual_firealarm_publisher/virtual_firealarm_publisher.xml index d78d384073..5ecab1fd92 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/temperature_publisher/temperature_publisher.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtual_firealarm_publisher/virtual_firealarm_publisher.xml @@ -17,7 +17,7 @@ ~ under the License. --> - + diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java index bc07e8621d..b3351234f6 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/output/adapter/mqtt/MQTTEventAdapterFactory.java @@ -84,7 +84,7 @@ public class MQTTEventAdapterFactory extends OutputEventAdapterFactory { clearSession.setDisplayName(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION)); clearSession.setRequired(false); clearSession.setOptions(new String[]{"true", "false"}); - clearSession.setDefaultValue("false"); + clearSession.setDefaultValue("true"); clearSession.setHint(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION_HINT)); // set Quality of Service diff --git a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/pom.xml b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/pom.xml index 084292c00c..a43489d49e 100644 --- a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/pom.xml +++ b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/pom.xml @@ -90,28 +90,6 @@ - - unpack-analytics - package - - unpack - - - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.analytics - ${project.version} - zip - true - - ${project.build.directory}/maven-shared-archive-resources/carbonapps - - **/* - - - - diff --git a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/pom.xml b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/pom.xml index ff25b99450..d565e31ead 100644 --- a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/pom.xml +++ b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/pom.xml @@ -155,28 +155,6 @@ - - unpack-analytics - package - - unpack - - - - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.analytics - ${project.version} - zip - true - - ${project.build.directory}/maven-shared-archive-resources/carbonapps - - **/* - - - - From 276ccfc31aec38f0ba1607aa54340bc49c96eba9 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 20 Jun 2017 19:48:50 +0530 Subject: [PATCH 12/14] updated version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 55e1c870f6..261073eb70 100644 --- a/pom.xml +++ b/pom.xml @@ -1146,7 +1146,7 @@ 1.1.1 - 3.0.4-SNAPSHOT + 3.0.7-SNAPSHOT [3.0.0, 4.0.0) From 6edc54b9408fce1a45eaf1aa1ea4080fbb90b005 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 22 Jun 2017 06:50:28 +0530 Subject: [PATCH 13/14] updated version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 19ec72a394..c3e8887eb0 100644 --- a/pom.xml +++ b/pom.xml @@ -1153,7 +1153,7 @@ 1.2.25 - 4.0.4 + 4.0.5-SNAPSHOT 4.4.8 From 15bfa09a84f7d4d21ba08c46242a16ff03087062 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 22 Jun 2017 20:37:19 +0530 Subject: [PATCH 14/14] fixed commit issues --- .../internal/PullNotificationListenerServiceComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java index 7e94759154..78e918ec73 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/internal/PullNotificationListenerServiceComponent.java @@ -54,7 +54,7 @@ public class PullNotificationListenerServiceComponent { try { //Do nothing if (log.isDebugEnabled()) { - log.debug("pull notification provider implementation bundle has been successfully " + + log.debug("Pull notification provider implementation bundle has been successfully " + "initialized"); } BundleContext bundleContext = componentContext.getBundleContext();