();
- private static final String DEVICEMGT_JAGGERY_APP_PATH = CarbonUtils.getCarbonRepository() + File.separator
- + "jaggeryapps" + File.separator + "devicemgt" + File.separator + "app" + File.separator + "units"
- + File.separator;
-
- private static final String UNIT_PREFIX = "cdmf.unit.device.type";
-
- @Override
- public void init(ConfigurationContext configurationContext) {
- }
-
- @Override
- public void setDirectory(String s) {
-
- }
-
- @Override
- public void setExtension(String s) {
-
- }
-
- @Override
- public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
- if (!deploymentFileData.getFile().isDirectory()) {
- return;
- }
- String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
- if (tenantDomain != null && !tenantDomain.isEmpty()) {
- File jaggeryAppPath = new File(
- DEVICEMGT_JAGGERY_APP_PATH + tenantDomain + "." + deploymentFileData.getName());
- try {
- if (!jaggeryAppPath.exists()) {
- FileUtils.forceMkdir(jaggeryAppPath);
- FileUtils.copyDirectory(deploymentFileData.getFile(), jaggeryAppPath);
- File[] listOfFiles = jaggeryAppPath.listFiles();
-
- for (int i = 0; i < listOfFiles.length; i++) {
- if (listOfFiles[i].isFile()) {
- String content = FileUtils.readFileToString(listOfFiles[i]);
- FileUtils.writeStringToFile(listOfFiles[i], content.replaceAll(UNIT_PREFIX
- , tenantDomain + "." + UNIT_PREFIX));
- }
- }
- } else {
- log.debug("units already exists " + deploymentFileData.getName());
- }
- this.deviceTypeDeployedUIMap.put(deploymentFileData.getAbsolutePath(),
- jaggeryAppPath.getAbsolutePath());
- } catch (IOException e) {
- if (jaggeryAppPath.exists()) {
- try {
- FileUtils.deleteDirectory(jaggeryAppPath);
- } catch (IOException e1) {
- log.error("Failed to delete directory " + jaggeryAppPath.getAbsolutePath());
- }
- }
- log.error("Cannot deploy deviceType ui : " + deploymentFileData.getName(), e);
- throw new DeploymentException(
- "Device type ui file " + deploymentFileData.getName() + " is not deployed ", e);
- }
-
- } else {
- log.error("Cannot deploy deviceType ui: " + deploymentFileData.getName());
- }
-
-
- }
-
- @Override
- public void undeploy(String filePath) throws DeploymentException {
- try {
- String jaggeryUnitPath = this.deviceTypeDeployedUIMap.remove(filePath);
- FileUtils.deleteDirectory(new File(jaggeryUnitPath));
- log.info("Device Type units un deployed successfully.");
- } catch (IOException e) {
- throw new DeploymentException("Failed to remove the units: " + filePath);
- }
- }
-
-}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java
deleted file mode 100644
index be089a9ccc..0000000000
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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.extensions.device.type.deployer.config;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.annotation.XmlElementDecl;
-import javax.xml.bind.annotation.XmlRegistry;
-import javax.xml.namespace.QName;
-
-
-/**
- * This object contains factory methods for each
- * Java content interface and Java element interface
- * generated in the org.wso2.carbon package.
- * An ObjectFactory allows you to programatically
- * construct new instances of the Java representation
- * for XML content. The Java representation of XML
- * content can consist of schema derived interfaces
- * and classes representing the binding of schema
- * type definitions, element declarations and model
- * groups. Factory methods for each of these are
- * provided in this class.
- *
- */
-@XmlRegistry
-public class ObjectFactory {
-
- private final static QName _DeviceTypeConfiguration_QNAME = new QName("", "DeviceTypeConfiguration");
-
- /**
- * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.wso2.carbon
- *
- */
- public ObjectFactory() {
- }
-
- /**
- * Create an instance of {@link DeviceTypeConfiguration }
- *
- */
- public DeviceTypeConfiguration createDeviceTypeConfiguration() {
- return new DeviceTypeConfiguration();
- }
-
- /**
- * Create an instance of {@link Operation }
- *
- */
- public Operation createOperation() {
- return new Operation();
- }
-
- /**
- * Create an instance of {@link Attributes }
- *
- */
- public Attributes createAttributes() {
- return new Attributes();
- }
-
- /**
- * Create an instance of {@link ProvisioningConfig }
- *
- */
- public ProvisioningConfig createProvisioningConfig() {
- return new ProvisioningConfig();
- }
-
- /**
- * Create an instance of {@link TableConfig }
- *
- */
- public TableConfig createTableConfig() {
- return new TableConfig();
- }
-
- /**
- * Create an instance of {@link Table }
- *
- */
- public Table createTable() {
- return new Table();
- }
-
- /**
- * Create an instance of {@link Property }
- *
- */
- public Property createProperty() {
- return new Property();
- }
-
- /**
- * Create an instance of {@link JndiConfig }
- *
- */
- public JndiConfig createJndiConfig() {
- return new JndiConfig();
- }
-
- /**
- * Create an instance of {@link FormParameters }
- *
- */
- public FormParameters createFormParameters() {
- return new FormParameters();
- }
-
- /**
- * Create an instance of {@link Features }
- *
- */
- public Features createFeatures() {
- return new Features();
- }
-
- /**
- * Create an instance of {@link Feature }
- *
- */
- public Feature createFeature() {
- return new Feature();
- }
-
- /**
- * Create an instance of {@link PushNotificationProvider }
- *
- */
- public PushNotificationProvider createPushNotificationProvider() {
- return new PushNotificationProvider();
- }
-
- /**
- * Create an instance of {@link DataSource }
- *
- */
- public DataSource createDataSource() {
- return new DataSource();
- }
-
- /**
- * Create an instance of {@link ConfigProperties }
- *
- */
- public ConfigProperties createConfigProperties() {
- return new ConfigProperties();
- }
-
- /**
- * Create an instance of {@link License }
- *
- */
- public License createLicense() {
- return new License();
- }
-
- /**
- * Create an instance of {@link DeviceDetails }
- *
- */
- public DeviceDetails createDeviceDetails() {
- return new DeviceDetails();
- }
-
- /**
- * Create an instance of {@link QueryParameters }
- *
- */
- public QueryParameters createQueryParameters() {
- return new QueryParameters();
- }
-
- /**
- * Create an instance of {@link JAXBElement }{@code <}{@link DeviceTypeConfiguration }{@code >}}
- *
- */
- @XmlElementDecl(namespace = "", name = "DeviceTypeConfiguration")
- public JAXBElement createDeviceTypeConfiguration(DeviceTypeConfiguration value) {
- return new JAXBElement(_DeviceTypeConfiguration_QNAME, DeviceTypeConfiguration.class, null, value);
- }
-
-}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java
index 9c7d771c11..88761df2e1 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java
@@ -28,7 +28,7 @@ import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.utils.ConfigurationContextService;
/**
- * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeManagementServiceComponent"
+ * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeExtensionServiceComponent"
* immediate="true"
* @scr.reference name="config.context.service"
* interface="org.wso2.carbon.utils.ConfigurationContextService"
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java
index 495a72b48d..4611deb8f3 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java
@@ -19,7 +19,7 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
import org.w3c.dom.Document;
-import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java
index 290fe93b7b..8b8ad98cf2 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java
@@ -22,9 +22,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
* This holds the constants used for this bundle.
*/
public class DeviceTypePluginConstants {
- public static final String MEDIA_TYPE_XML = "application/xml";
- public static final String CHARSET_UTF8 = "UTF8";
- public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
public static final String CDMF_UI_TYPE = "devicetype/ui";
public static final String CDMF_UI_TYPE_DIR = "devicetypes-ui";
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml
deleted file mode 100644
index 414bcaa8dd..0000000000
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml
+++ /dev/null
@@ -1,128 +0,0 @@
-
-
-
-
-
-
-
-
-
- abc
- this is a feature
-
-
- deviceId
-
-
- test
-
-
-
-
-
-
-
-
-
- temperature sensor fitted
- org.wso2.temperature.stream
- this is a sensor
-
- celcius
- atmeggga11234
-
-
-
- temperature sensor fitted
- org.wso2.temperature.stream
- this is a sensor
-
- celcius
-
-
-
-
-
-
-
-
- false
-
-
-
- true
-
-
-
- true
-
-
- sample.mqtt.adapter
- tcp://localhost:1883
- admin
- admin
- 0
-
- true
-
-
-
-
-
-
- en_US
- 1.0.0
- This is license text
-
-
-
- true
- 600000
-
-
- DEVICE_INFO
- 1
-
-
- APPLICATION_LIST
- 5
-
-
- DEVICE_LOCATION
- 1
-
-
-
-
-
-
- jdbc/SampleDM_DB
-
-
-
- SAMPLE_DEVICE_ID
-
- column1
- column2
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
new file mode 100644
index 0000000000..05c100dbd4
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 3.0.46-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.pull.notification
+ bundle
+ WSO2 Carbon - Pull Notification Provider Implementation
+ WSO2 Carbon - Pull Notification Provider 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.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.policy.mgt.core
+
+
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ Pull Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.pull.notification.internal,
+ org.wso2.carbon.device.mgt.extensions.pull.notification.*
+
+
+ org.osgi.framework,
+ org.osgi.service.component,
+ org.apache.commons.logging,
+ org.wso2.carbon.device.mgt.common.*,
+ org.wso2.carbon.device.mgt.core.service
+ org.wso2.carbon.policy.mgt.core.*,
+ org.wso2.carbon.policy.mgt.core,
+ com.google.gson,
+ org.wso2.carbon.device.mgt.core.service.*
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/PullNotificationSubscriberImpl.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/PullNotificationSubscriberImpl.java
new file mode 100644
index 0000000000..bcf8dece8a
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/PullNotificationSubscriberImpl.java
@@ -0,0 +1,102 @@
+/*
+ * 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.extensions.pull.notification;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
+import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
+import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
+import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
+import org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationDataHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class PullNotificationSubscriberImpl implements PullNotificationSubscriber {
+
+ public final class OperationCodes {
+ private OperationCodes() {
+ throw new AssertionError();
+ }
+ public static final String POLICY_MONITOR = "POLICY_MONITOR";
+ }
+
+
+ private static final Log log = LogFactory.getLog(PullNotificationSubscriberImpl.class);
+
+ public void init(Map properties) {
+
+ }
+
+ @Override
+ public void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException {
+ try {
+ if (!Operation.Status.ERROR.equals(operation.getStatus()) && operation.getCode() != null &&
+ OperationCodes.POLICY_MONITOR.equals(operation.getCode())) {
+ if (log.isDebugEnabled()) {
+ log.info("Received compliance status from POLICY_MONITOR operation ID: " + operation.getId());
+ }
+ List features = getComplianceFeatures(operation.getPayLoad());
+ PullNotificationDataHolder.getInstance().getPolicyManagerService()
+ .checkCompliance(deviceIdentifier, features);
+
+ } else {
+ PullNotificationDataHolder.getInstance().getDeviceManagementProviderService().updateOperation(
+ deviceIdentifier, operation);
+ }
+ } catch (OperationManagementException e) {
+ throw new PullNotificationExecutionFailedException(e);
+ } catch (PolicyComplianceException e) {
+ throw new PullNotificationExecutionFailedException("Invalid payload format compliant feature", e);
+ }
+ }
+
+ public void clean() {
+
+ }
+
+ private static List getComplianceFeatures(Object compliancePayload) throws
+ PolicyComplianceException {
+ String compliancePayloadString = new Gson().toJson(compliancePayload);
+ if (compliancePayload == null) {
+ return null;
+ }
+ // Parsing json string to get compliance features.
+ JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
+ JsonArray jsonArray = jsonElement.getAsJsonArray();
+ Gson gson = new Gson();
+ ComplianceFeature complianceFeature;
+ List complianceFeatures = new ArrayList(jsonArray.size());
+
+ for (JsonElement element : jsonArray) {
+ complianceFeature = gson.fromJson(element, ComplianceFeature.class);
+ complianceFeatures.add(complianceFeature);
+ }
+ return complianceFeatures;
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationDataHolder.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationDataHolder.java
new file mode 100644
index 0000000000..a9f7888c43
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationDataHolder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.extensions.pull.notification.internal;
+
+import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
+import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
+
+public class PullNotificationDataHolder {
+
+ private DeviceManagementProviderService deviceManagementProviderService;
+ private PolicyManagerService policyManagerService;
+
+ private static PullNotificationDataHolder thisInstance = new PullNotificationDataHolder();
+
+ public static PullNotificationDataHolder getInstance() {
+ return thisInstance;
+ }
+
+ public DeviceManagementProviderService getDeviceManagementProviderService() {
+ return deviceManagementProviderService;
+ }
+
+ public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ this.deviceManagementProviderService = deviceManagementProviderService;
+ }
+
+ public PolicyManagerService getPolicyManagerService() {
+ return policyManagerService;
+ }
+
+ public void setPolicyManagerService(PolicyManagerService policyManagerService) {
+ this.policyManagerService = policyManagerService;
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationServiceComponent.java
new file mode 100644
index 0000000000..351e514706
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/src/main/java/org/wso2/carbon/device/mgt/extensions/pull/notification/internal/PullNotificationServiceComponent.java
@@ -0,0 +1,80 @@
+/*
+ * 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.extensions.pull.notification.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
+import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
+
+/**
+ * @scr.component name="org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationServiceComponent" 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="org.wso2.carbon.policy.mgt.core"
+ * interface="org.wso2.carbon.policy.mgt.core.PolicyManagerService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setPolicyManagerService"
+ * unbind="unsetPolicyManagerService"
+ */
+public class PullNotificationServiceComponent {
+
+ private static final Log log = LogFactory.getLog(PullNotificationServiceComponent.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");
+ }
+ } 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) {
+ PullNotificationDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
+ }
+
+ protected void unsetDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
+ PullNotificationDataHolder.getInstance().setDeviceManagementProviderService(null);
+ }
+
+ protected void setPolicyManagerService(PolicyManagerService policyManagerService) {
+ PullNotificationDataHolder.getInstance().setPolicyManagerService(policyManagerService);
+ }
+
+ protected void unsetPolicyManagerService(PolicyManagerService policyManagerService) {
+ PullNotificationDataHolder.getInstance().setPolicyManagerService(null);
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
index 7c8b6fc6f0..ecfd3e1276 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
index da488c5435..7085f1244b 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
@@ -57,7 +57,7 @@ public class FCMNotificationStrategy implements NotificationStrategy {
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
try {
Device device =
- FCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId());
+ FCMDataHolder.getInstance().getDeviceManagementProviderService().getDeviceWithTypeProperties(ctx.getDeviceId());
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
} catch (DeviceManagementException e) {
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);
diff --git a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
similarity index 57%
rename from components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml
rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
index a75583c06c..7cc0b1213d 100644
--- a/components/identity-extensions/dynamic-client-registration/org.wso2.carbon.dynamic.client.web.app.registration/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
@@ -1,114 +1,78 @@
+
- dynamic-client-registration
+ device-mgt-extensions
org.wso2.carbon.devicemgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../pom.xml
4.0.0
- org.wso2.carbon.dynamic.client.web.app.registration
- 2.0.63-SNAPSHOT
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
bundle
- WSO2 Carbon - Dynamic client web app registration
- WSO2 Carbon - Dynamic Client Web-app Registration Service
+ WSO2 Carbon - HTTP Based Push Notification Provider Implementation
+ WSO2 Carbon - HTTP Based Push Notification Provider Implementation
http://wso2.org
-
-
-
- org.apache.felix
- maven-scr-plugin
-
-
- org.apache.felix
- maven-bundle-plugin
- 1.4.0
- true
-
-
- ${project.artifactId}
- ${project.artifactId}
- ${carbon.device.mgt.version}
- Dynamic Client Web App Registration Bundle
- org.wso2.carbon.dynamic.client.web.app.registration.internal
-
- !org.wso2.carbon.dynamic.client.web.app.registration.internal,
- org.wso2.carbon.dynamic.client.web.app.registration.*
-
-
- javax.xml.bind.*,
- com.google.*,
- javax.net.ssl,
- javax.servlet,
- org.apache.axis2.context,
- org.apache.catalina,
- org.apache.catalina.core,
- org.apache.commons.*,
- org.apache.http,
- org.apache.http.*,
- org.osgi.framework,
- org.osgi.service.component,
- org.wso2.carbon.context,
- org.wso2.carbon.core,
- org.wso2.carbon.core.security,
- org.wso2.carbon.dynamic.client.*,
- org.wso2.carbon.registry.*,
- org.wso2.carbon.user.*,
- org.wso2.carbon.utils
-
-
-
-
-
-
- org.eclipse.osgi
- org.eclipse.osgi
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.api
- org.eclipse.osgi
- org.eclipse.osgi.services
+ org.wso2.carbon
+ org.wso2.carbon.registry.api
+
+
+ org.wso2.carbon
+ org.wso2.carbon.registry.core
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
- org.testng
- testng
+ org.apache.ws.commons.axiom.wso2
+ axiom
org.wso2.carbon
org.wso2.carbon.utils
- org.wso2.carbon.identity.framework
- org.wso2.carbon.identity.application.mgt
+ org.wso2.orbit.org.scannotation
+ scannotation
- org.wso2.carbon.identity.inbound.auth.oauth2
- org.wso2.carbon.identity.oauth
+ org.eclipse.osgi
+ org.eclipse.osgi
- org.wso2.carbon.identity.framework
- org.wso2.carbon.identity.core
+ org.eclipse.osgi
+ org.eclipse.osgi.services
org.wso2.tomcat
@@ -119,28 +83,65 @@
tomcat-servlet-api
- org.wso2.carbon
- org.wso2.carbon.logging
-
-
- org.wso2.carbon
- org.wso2.carbon.user.core
-
-
- org.wso2.carbon
- org.wso2.carbon.registry.core
+ javax.ws.rs
+ jsr311-api
- org.wso2.carbon.devicemgt
- org.wso2.carbon.dynamic.client.registration
+ org.apache.axis2.wso2
+ axis2
- org.apache.httpcomponents
- httpclient
+ commons-lang.wso2
+ commons-lang
com.google.code.gson
gson
+
+ org.json.wso2
+ json
+
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ MQTT Based Push Notification Provider Bundle
+
+ !org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal,
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.*
+
+
+ org.apache.commons.logging,
+ org.osgi.service.component,
+ org.wso2.carbon.context,
+ org.wso2.carbon.device.mgt.common.operation.mgt,
+ org.wso2.carbon.device.mgt.common.push.notification,
+ org.wso2.carbon.device.mgt.common,
+ org.wso2.carbon.device.mgt.core.service,
+ org.osgi.framework,
+ org.wso2.carbon.device.mgt.core.operation.mgt,
+ org.wso2.carbon.core,
+ com.google.gson,
+ org.apache.commons.httpclient.*
+
+
+
+
+
+
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.java
similarity index 50%
rename from components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java
rename to components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.java
index 10a9b018b3..5f083400b1 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.java
@@ -16,24 +16,22 @@
* under the License.
*
*/
+package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
-package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
-public class DeviceTypePluginDAOManager {
+public class HTTPBasedPushNotificationProvider implements PushNotificationProvider {
- private DeviceTypePluginDAO deviceTypePluginDAO;
- private DeviceTypeDAOHandler deviceTypeDAOHandler;
-
- public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
- deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName);
- deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, deviceTypeDAOHandler);
+ @Override
+ public String getType() {
+ return "HTTP";
}
- public DeviceTypePluginDAO getDeviceDAO() {
- return deviceTypePluginDAO;
+ @Override
+ public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
+ return new HTTPNotificationStrategy(config);
}
- public DeviceTypeDAOHandler getDeviceTypeDAOHandler() {
- return deviceTypeDAOHandler;
- }
-}
\ No newline at end of file
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java
new file mode 100644
index 0000000000..d833856883
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPMessageExecutor.java
@@ -0,0 +1,94 @@
+package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
+
+import com.google.gson.Gson;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
+
+import java.net.UnknownHostException;
+
+public class HTTPMessageExecutor implements Runnable {
+
+ private String url;
+ private String authorizationHeader;
+ private String payload;
+ private HostConfiguration hostConfiguration;
+ private HttpClient httpClient;
+ private static final String APPLIATION_JSON = "application/json";
+ private static final String AUTHORIZATION_HEADER = "Authorization";
+ private static final Log log = LogFactory.getLog(HTTPMessageExecutor.class);
+
+ public HTTPMessageExecutor(NotificationContext notificationContext, String authorizationHeader, String url
+ , HostConfiguration hostConfiguration, HttpClient httpClient) {
+ this.url = url;
+ this.authorizationHeader = authorizationHeader;
+ Gson gson = new Gson();
+ this.payload = gson.toJson(notificationContext);
+ this.hostConfiguration = hostConfiguration;
+ this.httpClient = httpClient;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getAuthorizationHeader() {
+ return authorizationHeader;
+ }
+
+ public void setAuthorizationHeader(String authorizationHeader) {
+ this.authorizationHeader = authorizationHeader;
+ }
+
+ public String getPayload() {
+ return payload;
+ }
+
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
+ @Override
+ public void run() {
+ EntityEnclosingMethod method = null;
+
+ try {
+ method = new PostMethod(this.getUrl());
+ method.setRequestEntity(new StringRequestEntity(this.getPayload(), APPLIATION_JSON, "UTF-8"));
+ if (authorizationHeader != null && authorizationHeader.isEmpty()) {
+ method.setRequestHeader(AUTHORIZATION_HEADER, authorizationHeader);
+ }
+
+ this.getHttpClient().executeMethod(hostConfiguration, method);
+
+ } catch (UnknownHostException e) {
+ log.error("Push Notification message dropped " + url, e);
+ throw new InvalidConfigurationException("invalid host: url", e);
+ } catch (Throwable e) {
+ log.error("Push Notification message dropped ", e);
+ throw new InvalidConfigurationException("Push Notification message dropped, " + e.getMessage(), e);
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java
new file mode 100644
index 0000000000..2e4e237c69
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPNotificationStrategy.java
@@ -0,0 +1,103 @@
+/*
+ * 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.extensions.push.notification.provider.http;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
+import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
+import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
+
+public class HTTPNotificationStrategy implements NotificationStrategy {
+
+ private static final Log log = LogFactory.getLog(HTTPNotificationStrategy.class);
+ private final PushNotificationConfig config;
+ private static final String URL_PROPERTY = "url";
+ private static final String AUTHORIZATION_HEADER_PROPERTY = "authorization";
+ private String endpoint;
+ private static ExecutorService executorService;
+ private HttpClient httpClient = null;
+ private HostConfiguration hostConfiguration;
+ private String authorizationHeaderValue;
+ private String uri;
+
+ public HTTPNotificationStrategy(PushNotificationConfig config) {
+ this.config = config;
+ if (this.config == null) {
+ throw new InvalidConfigurationException("Properties Cannot be found");
+ }
+ endpoint = config.getProperties().get(URL_PROPERTY);
+ if (endpoint == null || endpoint.isEmpty()) {
+ throw new InvalidConfigurationException("Property - 'url' cannot be found");
+ }
+ try {
+ this.uri = endpoint;
+ URL url = new URL(endpoint);
+ hostConfiguration = new HostConfiguration();
+ hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
+ this.authorizationHeaderValue = config.getProperties().get(AUTHORIZATION_HEADER_PROPERTY);
+ executorService = Executors.newFixedThreadPool(1);
+ httpClient = new HttpClient();
+ } catch (MalformedURLException e) {
+ throw new InvalidConfigurationException("Property - 'url' is malformed.", e);
+ }
+ }
+
+ @Override
+ public void init() {
+
+ }
+
+ @Override
+ public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
+ try {
+ executorService.submit(new HTTPMessageExecutor(ctx, authorizationHeaderValue, uri, hostConfiguration
+ , httpClient));
+ } catch (RejectedExecutionException e) {
+ log.error("Failed to publish to external endpoint url: " + endpoint, e);
+ }
+ }
+
+ @Override
+ public NotificationContext buildContext() {
+ return null;
+ }
+
+ @Override
+ public void undeploy() {
+ executorService.shutdown();
+ }
+
+ @Override
+ public PushNotificationConfig getConfig() {
+ return config;
+ }
+
+}
+
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/internal/HTTPPushNotificationServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/internal/HTTPPushNotificationServiceComponent.java
new file mode 100644
index 0000000000..b16e1728d9
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/internal/HTTPPushNotificationServiceComponent.java
@@ -0,0 +1,49 @@
+/*
+ * 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.extensions.push.notification.provider.http.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal.HTTPPushNotificationServiceComponent" immediate="true"
+ */
+public class HTTPPushNotificationServiceComponent {
+
+ private static final Log log = LogFactory.getLog(HTTPPushNotificationServiceComponent.class);
+
+ @SuppressWarnings("unused")
+ protected void activate(ComponentContext componentContext) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing HTTP based push notification provider implementation bundle");
+ }
+ //Do nothing
+ if (log.isDebugEnabled()) {
+ log.debug("HTTP based push notification provider implementation bundle has been successfully " +
+ "initialized");
+ }
+ } catch (Throwable e) {
+ log.error("Error occurred while initializing HTTP based push notification provider " +
+ "implementation bundle", e);
+ }
+ }
+
+}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
index e954b928ce..4e8aa8ee60 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
index 8af53af6b2..59653e7831 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java
@@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
-import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@@ -46,36 +46,52 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
private String mqttAdapterName;
private static final Log log = LogFactory.getLog(MQTTNotificationStrategy.class);
private final PushNotificationConfig config;
+ private final String providerTenantDomain;
+ private static final Object lockObj = new Object();
public MQTTNotificationStrategy(PushNotificationConfig config) {
this.config = config;
OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration();
adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE);
- mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME);
- adapterConfig.setName(mqttAdapterName);
adapterConfig.setMessageFormat(MessageType.TEXT);
Map configProperties = new HashMap();
- String brokerUrl = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL);
- if (brokerUrl != null && !brokerUrl.isEmpty()) {
- configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl);
+ if (config.getProperties() != null && config.getProperties().size() > 0) {
+ String brokerUrl = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL);
+ if (brokerUrl != null && !brokerUrl.isEmpty()) {
+ configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl);
+ }
+ mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME);
+ configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
+ config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
+ configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD,
+ config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD));
+ configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
+ config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
+ configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
+ config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES));
+ configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS,
+ config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS));
+ } else {
+ mqttAdapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
+ .toLowerCase();
}
- configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
- config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
- configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD,
- config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD));
- configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
- config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
- configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
- config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES));
- configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS,
- config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS));
+ adapterConfig.setName(mqttAdapterName);
adapterConfig.setStaticProperties(configProperties);
try {
- MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
+ synchronized (lockObj) {
+ try {
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().isPolled(mqttAdapterName);
+ } catch (OutputEventAdapterException e) {
+ //event adapter not created
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
+ }
+ }
} catch (OutputEventAdapterException e) {
throw new InvalidConfigurationException("Error occurred while initializing MQTT output event adapter", e);
}
+ providerTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
+ .toLowerCase();
}
@Override
@@ -85,42 +101,73 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
@Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
+ String adapterName = mqttAdapterName;
+ String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
+ if (!providerTenantDomain.equals(tenantDomain)) {
+ //this is to handle the device type shared with all tenant mode.
+
+ adapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
+ .toLowerCase();
+ try {
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().isPolled(adapterName);
+ } catch (OutputEventAdapterException e) {
+ //event adapter not created
+ synchronized (lockObj) {
+ OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration();
+ adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE);
+ adapterConfig.setMessageFormat(MessageType.TEXT);
+ adapterConfig.setName(adapterName);
+ Map configProperties = new HashMap();
+ adapterConfig.setStaticProperties(configProperties);
+ try {
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
+ } catch (OutputEventAdapterException e1) {
+ throw new PushNotificationExecutionFailedException
+ ("Error occurred while initializing MQTT output event adapter for shared tenant: "
+ + tenantDomain, e);
+ }
+ }
+ }
+
+ }
Operation operation = ctx.getOperation();
Properties properties = operation.getProperties();
if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) {
Map dynamicProperties = new HashMap<>();
dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC));
- MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
operation.getPayLoad());
} else {
if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) {
PolicyOperation policyOperation = (PolicyOperation) operation;
List profileOperations = policyOperation.getProfileOperations();
- String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
String deviceType = ctx.getDeviceId().getType();
String deviceId = ctx.getDeviceId().getId();
for (ProfileOperation profileOperation : profileOperations) {
Map dynamicProperties = new HashMap<>();
String topic = tenantDomain + "/"
- + deviceType + "/" + deviceId + "/" + profileOperation.getType()
+ + deviceType + "/" + deviceId + "/operation/" + profileOperation.getType()
.toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase();
dynamicProperties.put("topic", topic);
- MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
profileOperation.getPayLoad());
}
} else {
Map dynamicProperties = new HashMap<>();
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
- + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType()
- .toString().toLowerCase() + "/" + operation.getCode();
+ + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/operation/"
+ + operation.getType().toString().toLowerCase() + "/" + operation.getCode() + "/" + operation.getId();
dynamicProperties.put("topic", topic);
- if (operation.getPayLoad() == null) {
- operation.setPayLoad("");
+ Object payload;
+ if ("command".equals(operation.getType().toString().toLowerCase())) {
+ payload = operation.getCode();
+ } else {
+ payload = operation.getPayLoad();
}
- MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
- operation.getPayLoad());
+ MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
+ payload);
}
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
index b767cb933e..451a1d6515 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
org.wso2.carbon.devicemgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
index af3a1c6c4b..d091ecfd9d 100644
--- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java
@@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml
index febe8a00f7..34a7bec6a1 100644
--- a/components/device-mgt-extensions/pom.xml
+++ b/components/device-mgt-extensions/pom.xml
@@ -22,7 +22,7 @@
carbon-devicemgt
org.wso2.carbon.devicemgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../../pom.xml
@@ -34,10 +34,12 @@
http://wso2.org
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp
org.wso2.carbon.device.mgt.extensions.device.type.deployer
+ org.wso2.carbon.device.mgt.extensions.pull.notification
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
index 04bee77b9a..64d2f9dfbc 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml
@@ -3,7 +3,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
index 679b7264c5..f4657a1210 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.devicemgt
device-mgt
- 2.0.63-SNAPSHOT
+ 3.0.46-SNAPSHOT
../pom.xml
@@ -66,10 +66,6 @@
org.wso2.carbon
org.wso2.carbon.utils
-
- org.wso2.carbon.devicemgt
- org.wso2.carbon.device.mgt.core
-
org.wso2.carbon.analytics-common
org.wso2.carbon.databridge.agent
@@ -118,6 +114,7 @@
org.osgi.framework,
org.osgi.service.component,
org.apache.commons.logging.*,
+ org.wso2.carbon.utils.multitenancy,
org.wso2.carbon.context;version="${carbon.kernel.version.range}",
org.wso2.carbon.utils;version="${carbon.kernel.version.range}",
org.wso2.carbon.databridge.*;version="${carbon.analytics.common.version.range}",
@@ -126,14 +123,15 @@
org.wso2.carbon.registry.indexing.*; version="${carbon.registry.imp.pkg.version.range}",
org.json;version="${commons-json.version}",
javax.xml.*,
- javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
+ javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
org.w3c.dom,
- org.wso2.carbon.base
+ org.wso2.carbon.base,
+ org.wso2.carbon.utils.multitenancy