diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
new file mode 100644
index 0000000000..dda338e82d
--- /dev/null
+++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+
+ device-mgt-extensions
+ org.wso2.carbon.devicemgt
+ 2.0.72-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
+ bundle
+ WSO2 Carbon - HTTP Based Push Notification Provider Implementation
+ WSO2 Carbon - HTTP Based Push Notification Provider Implementation
+ http://wso2.org
+
+
+
+ org.wso2.carbon.governance
+ org.wso2.carbon.governance.api
+
+
+ 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.apache.ws.commons.axiom.wso2
+ axiom
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ org.wso2.orbit.org.scannotation
+ scannotation
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+ org.wso2.tomcat
+ tomcat
+
+
+ org.wso2.tomcat
+ tomcat-servlet-api
+
+
+ javax.ws.rs
+ jsr311-api
+
+
+ org.apache.axis2.wso2
+ axis2
+
+
+ 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.push.notification.provider.http/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/http/HTTPBasedPushNotificationProvider.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
new file mode 100644
index 0000000000..5f083400b1
--- /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/HTTPBasedPushNotificationProvider.java
@@ -0,0 +1,37 @@
+/*
+ * 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.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 HTTPBasedPushNotificationProvider implements PushNotificationProvider {
+
+ @Override
+ public String getType() {
+ return "HTTP";
+ }
+
+ @Override
+ public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
+ return new HTTPNotificationStrategy(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/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..3858421e5a
--- /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,91 @@
+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.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);
+ } catch (Throwable e) {
+ log.error("Push Notification message dropped ", 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..d543062a57
--- /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,98 @@
+/*
+ * 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.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;
+ }
+
+ @Override
+ public void init() {
+ 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 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/InvalidConfigurationException.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/InvalidConfigurationException.java
new file mode 100644
index 0000000000..17f2b1b29c
--- /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/InvalidConfigurationException.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * This exception is thrown whether the http configured with invalid configuration.
+ */
+public class InvalidConfigurationException extends RuntimeException {
+
+ public InvalidConfigurationException(String msg, Exception nestedEx) {
+ super(msg, nestedEx);
+ }
+
+ public InvalidConfigurationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidConfigurationException(String msg) {
+ super(msg);
+ }
+
+ public InvalidConfigurationException() {
+ super();
+ }
+
+ public InvalidConfigurationException(Throwable cause) {
+ super(cause);
+ }
+
+}
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/pom.xml b/components/device-mgt-extensions/pom.xml
index 081983603c..5b236e779d 100644
--- a/components/device-mgt-extensions/pom.xml
+++ b/components/device-mgt-extensions/pom.xml
@@ -34,6 +34,7 @@
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
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java
index 51520e4ddd..1f7dc7f9ff 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java
@@ -21,16 +21,15 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
-import org.wso2.carbon.device.mgt.extensions.device.type.template.HTTPDeviceTypeManagerService;
-import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@@ -69,8 +68,8 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
String msg = "Device type already available, " + deviceType.getName();
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
- HTTPDeviceTypeManagerService httpDeviceTypeManagerService = new HTTPDeviceTypeManagerService
- (deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
+ DeviceManagementService httpDeviceTypeManagerService = DeviceMgtAPIUtils.getDeviceTypeGeneratorService()
+ .populateDeviceManagementService(deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
return Response.status(Response.Status.OK).build();
} catch (DeviceManagementException e) {
@@ -92,8 +91,8 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
String msg = "Device type does not exist, " + deviceType.getName();
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
- HTTPDeviceTypeManagerService httpDeviceTypeManagerService = new HTTPDeviceTypeManagerService
- (deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
+ DeviceManagementService httpDeviceTypeManagerService = DeviceMgtAPIUtils.getDeviceTypeGeneratorService()
+ .populateDeviceManagementService(deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
return Response.status(Response.Status.OK).build();
} catch (DeviceManagementException e) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
index 90814865da..3a70391228 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java
@@ -44,6 +44,7 @@ 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.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
@@ -193,6 +194,18 @@ public class DeviceMgtAPIUtils {
return deviceManagementProviderService;
}
+ public static DeviceTypeGeneratorService getDeviceTypeGeneratorService() {
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ DeviceTypeGeneratorService deviceTypeGeneratorService =
+ (DeviceTypeGeneratorService) ctx.getOSGiService(DeviceTypeGeneratorService.class, null);
+ if (deviceTypeGeneratorService == null) {
+ String msg = "DeviceTypeGeneratorService service has not initialized.";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ return deviceTypeGeneratorService;
+ }
+
public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
Device device = getDeviceManagementService().getDevice(deviceIdentifier);
if (device == null || device.getDeviceIdentifier() == null ||
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeGeneratorService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeGeneratorService.java
new file mode 100644
index 0000000000..f9c98e0f3a
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeGeneratorService.java
@@ -0,0 +1,13 @@
+package org.wso2.carbon.device.mgt.common.spi;
+
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+
+/**
+ * This implementation populates device management service.
+ */
+public interface DeviceTypeGeneratorService {
+
+ DeviceManagementService populateDeviceManagementService(String deviceTypeName
+ , DeviceTypeMetaDefinition deviceTypeMetaDefinition);
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
index de8588da8f..6f4578a4bd 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
@@ -133,10 +133,6 @@
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.common
-
- org.wso2.carbon.devicemgt
- org.wso2.carbon.device.mgt.extensions
-
org.wso2.carbon
org.wso2.carbon.logging
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java
index bc685415bf..7a3b487121 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java
@@ -50,7 +50,6 @@ import org.wso2.carbon.device.mgt.core.status.task.impl.DeviceStatusTaskManagerS
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
-import org.wso2.carbon.device.mgt.extensions.device.type.template.HTTPDeviceTypeManagerService;
import java.util.Collections;
import java.util.HashMap;
@@ -179,8 +178,12 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
}
DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
if (deviceTypeMetaDefinition != null) {
- HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService
- (type, deviceTypeMetaDefinition);
+ DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder.getInstance()
+ .getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
+ if (deviceTypeManagerService == null) {
+ log.error("Failing to retrieve the device type service for " + type);
+ return null;
+ }
addDeviceManagementProvider(deviceTypeManagerService);
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId);
provider = providers.get(deviceTypeIdentifier);
@@ -210,8 +213,12 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
if (!cachedDefinition.equals(dbStoredDefinition)) {
- HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService
- (type, deviceTypeMetaDefinition);
+ DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder.getInstance()
+ .getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
+ if (deviceTypeManagerService == null) {
+ log.error("Failing to retrieve the device type service for " + type);
+ return null;
+ }
addDeviceManagementProvider(deviceTypeManagerService);
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId);
provider = providers.get(deviceTypeIdentifier);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
index 6e61a2ceb3..f6a3a3fc83 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java
@@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
@@ -65,6 +66,7 @@ public class DeviceManagementDataHolder {
private PushNotificationProviderRepository pushNotificationProviderRepository;
private DeviceTaskManagerService deviceTaskManagerService;
private DeviceStatusTaskManagerService deviceStatusTaskManagerService;
+ private DeviceTypeGeneratorService deviceTypeGeneratorService;
private Map deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
new HashMap());
@@ -255,4 +257,13 @@ public class DeviceManagementDataHolder {
public void removeDeviceStatusTaskPluginConfig(DeviceType deviceType) {
this.deviceStatusTaskPluginConfigs.remove(deviceType);
}
+
+ public DeviceTypeGeneratorService getDeviceTypeGeneratorService() {
+ return deviceTypeGeneratorService;
+ }
+
+ public void setDeviceTypeGeneratorService(
+ DeviceTypeGeneratorService deviceTypeGeneratorService) {
+ this.deviceTypeGeneratorService = deviceTypeGeneratorService;
+ }
}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
index 0c1a62471d..04da5ac6e3 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java
@@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl;
@@ -105,6 +106,12 @@ import java.util.concurrent.TimeUnit;
* policy="dynamic"
* bind="setEmailSenderService"
* unbind="unsetEmailSenderService"
+ * @scr.reference name="device.type.generator.service"
+ * interface="org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService"
+ * cardinality="0..1"
+ * policy="dynamic"
+ * bind="setDeviceTypeGeneratorService"
+ * unbind="unsetDeviceTypeGeneratorService"
*/
public class DeviceManagementServiceComponent {
@@ -304,7 +311,7 @@ public class DeviceManagementServiceComponent {
try {
if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service Provider: '" +
- deviceManagementService.getType() + "'");
+ deviceManagementService.getType() + "'");
}
synchronized (LOCK) {
deviceManagers.add(deviceManagementService);
@@ -435,6 +442,30 @@ public class DeviceManagementServiceComponent {
}
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
}
+
+ /**
+ * sets DeviceTypeGeneratorService.
+ *
+ * @param deviceTypeGeneratorService An Instance of DeviceTypeGeneratorService
+ */
+ protected void setDeviceTypeGeneratorService(DeviceTypeGeneratorService deviceTypeGeneratorService) {
+ if (log.isDebugEnabled()) {
+ log.debug("Un setting Device DeviceTypeGeneratorService");
+ }
+ DeviceManagementDataHolder.getInstance().setDeviceTypeGeneratorService(deviceTypeGeneratorService);
+ }
+
+ /**
+ * sets DeviceTypeGeneratorService.
+ *
+ * @param deviceTypeGeneratorService An Instance of DeviceTypeGeneratorService
+ */
+ protected void unsetDeviceTypeGeneratorService(DeviceTypeGeneratorService deviceTypeGeneratorService) {
+ if (log.isDebugEnabled()) {
+ log.debug("Un setting Device DeviceTypeGeneratorService");
+ }
+ DeviceManagementDataHolder.getInstance().setDeviceTypeGeneratorService(null);
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
index 8e549d89d9..645d4d0a0a 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
@@ -110,6 +110,7 @@
org.wso2.carbon.registry.core.service,
org.wso2.carbon.utils.dbcreator,
org.wso2.carbon.utils.multitenancy,
+ org.osgi.framework
org.wso2.carbon.device.mgt.extensions.pull.notification,
org.wso2.carbon.device.mgt.extensions.pull.notification.*
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeGeneratorServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeGeneratorServiceImpl.java
new file mode 100644
index 0000000000..01bc313095
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeGeneratorServiceImpl.java
@@ -0,0 +1,14 @@
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
+
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
+import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
+
+public class DeviceTypeGeneratorServiceImpl implements DeviceTypeGeneratorService {
+
+ @Override
+ public DeviceManagementService populateDeviceManagementService(String deviceTypeName
+ , DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
+ return new HTTPDeviceTypeManagerService(deviceTypeName, deviceTypeMetaDefinition);
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
index 3bc00675dc..180e9717e3 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java
@@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.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.common.spi.DeviceTypeGeneratorService;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeGeneratorServiceImpl;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService;
@@ -45,6 +47,8 @@ public class DeviceTypeExtensionServiceComponent {
if (log.isDebugEnabled()) {
log.debug("Activating DeviceType Deployer Service Component");
}
+ ctx.getBundleContext().registerService(DeviceTypeGeneratorService.class, new DeviceTypeGeneratorServiceImpl()
+ , null);
}
protected void deactivate(ComponentContext ctx) {
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml
new file mode 100644
index 0000000000..b8c527d5ca
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ device-mgt-extensions-feature
+ 2.0.72-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature
+ pom
+ 2.0.72-SNAPSHOT
+ WSO2 Carbon - MQTT Based Push Notification Provider Feature
+ http://wso2.org
+ WSO2 Carbon - MQTT Based Push Notification Provider Feature
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+ ${carbon.p2.plugin.version}
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
+ ../../../features/etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+ org.eclipse.equinox.p2.type.group:false
+
+
+
+
+ org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.http:${carbon.device.mgt.version}
+
+
+
+ org.wso2.carbon.core.server:${carbon.kernel.version}
+ org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
+
+
+
+
+
+
+
+
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/src/main/resources/build.properties b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..9c86577d76
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/src/main/resources/build.properties
@@ -0,0 +1 @@
+custom = true
diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/src/main/resources/p2.inf b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..7ab37b9d7d
--- /dev/null
+++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/src/main/resources/p2.inf
@@ -0,0 +1 @@
+instructions.configure = \
\ No newline at end of file
diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml
index 9f4ff818f4..b0f59e3c0c 100644
--- a/features/device-mgt-extensions/pom.xml
+++ b/features/device-mgt-extensions/pom.xml
@@ -37,6 +37,7 @@
org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature
diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml
index a05dff9256..4343859a98 100644
--- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml
+++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml
@@ -34,6 +34,7 @@
org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider
diff --git a/pom.xml b/pom.xml
index 5b60aa868f..19d69acaea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1446,6 +1446,11 @@
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt
${carbon.device.mgt.version}
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.extensions.push.notification.provider.http
+ ${carbon.device.mgt.version}
+
org.wso2.carbon.devicemgt
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp