Merge branch 'sameeragunarathne-master'

merge-requests/7/head
Harshan Liyanage 8 years ago
commit 4272bd1a7a

@ -27,10 +27,10 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId> <artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm</artifactId>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<name>WSO2 Carbon - GCM Based Push Notification Provider Implementation</name> <name>WSO2 Carbon - FCM Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - GCM Based Push Notification Provider Implementation</description> <description>WSO2 Carbon - FCM Based Push Notification Provider Implementation</description>
<url>http://wso2.org</url> <url>http://wso2.org</url>
<dependencies> <dependencies>
@ -128,10 +128,10 @@
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name> <Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version> <Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
<Bundle-Description>GCM Based Push Notification Provider Bundle</Bundle-Description> <Bundle-Description>FCM Based Push Notification Provider Bundle</Bundle-Description>
<Export-Package> <Export-Package>
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal, !org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal,
org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.* org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.*
</Export-Package> </Export-Package>
<Import-Package> <Import-Package>
com.google.gson, com.google.gson,

@ -16,24 +16,24 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm; package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; 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.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
public class GCMBasedPushNotificationProvider implements PushNotificationProvider { public class FCMBasedPushNotificationProvider implements PushNotificationProvider {
private static final String PS_PROVIDER_GCM = "GCM"; private static final String PS_PROVIDER_FCM = "FCM";
@Override @Override
public String getType() { public String getType() {
return PS_PROVIDER_GCM; return PS_PROVIDER_FCM;
} }
@Override @Override
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) { public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
return new GCMNotificationStrategy(config); return new FCMNotificationStrategy(config);
} }
} }

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm; package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -27,7 +27,7 @@ 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.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMDataHolder; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal.FCMDataHolder;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -35,16 +35,16 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
public class GCMNotificationStrategy implements NotificationStrategy { public class FCMNotificationStrategy implements NotificationStrategy {
private static final String GCM_TOKEN = "GCM_TOKEN"; private static final String FCM_TOKEN = "FCM_TOKEN";
private static final String GCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send"; private static final String FCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send";
private static final String GCM_API_KEY = "gcmAPIKey"; private static final String FCM_API_KEY = "fcmAPIKey";
private static final int TIME_TO_LIVE = 60; private static final int TIME_TO_LIVE = 60;
private static final int HTTP_STATUS_CODE_OK = 200; private static final int HTTP_STATUS_CODE_OK = 200;
private PushNotificationConfig config; private PushNotificationConfig config;
public GCMNotificationStrategy(PushNotificationConfig config) { public FCMNotificationStrategy(PushNotificationConfig config) {
this.config = config; this.config = config;
} }
@ -57,7 +57,7 @@ public class GCMNotificationStrategy implements NotificationStrategy {
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
try { try {
Device device = Device device =
GCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId()); FCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId());
this.sendWakeUpCall(ctx.getOperation().getCode(), device); this.sendWakeUpCall(ctx.getOperation().getCode(), device);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e); throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);
@ -79,13 +79,13 @@ public class GCMNotificationStrategy implements NotificationStrategy {
private void sendWakeUpCall(String message, private void sendWakeUpCall(String message,
Device device) throws IOException, PushNotificationExecutionFailedException { Device device) throws IOException, PushNotificationExecutionFailedException {
OutputStream os = null; OutputStream os = null;
byte[] bytes = getGCMRequest(message, getGCMToken(device.getProperties())).getBytes(); byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes();
HttpURLConnection conn = null; HttpURLConnection conn = null;
try { try {
conn = (HttpURLConnection) new URL(GCM_ENDPOINT).openConnection(); conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection();
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key=" + config.getProperty(GCM_API_KEY)); conn.setRequestProperty("Authorization", "key=" + config.getProperty(FCM_API_KEY));
conn.setRequestMethod("POST"); conn.setRequestMethod("POST");
conn.setDoOutput(true); conn.setDoOutput(true);
os = conn.getOutputStream(); os = conn.getOutputStream();
@ -102,35 +102,35 @@ public class GCMNotificationStrategy implements NotificationStrategy {
} }
} }
private static String getGCMRequest(String message, String registrationId) { private static String getFCMRequest(String message, String registrationId) {
JsonObject gcmRequest = new JsonObject(); JsonObject fcmRequest = new JsonObject();
gcmRequest.addProperty("delay_while_idle", false); fcmRequest.addProperty("delay_while_idle", false);
gcmRequest.addProperty("time_to_live", TIME_TO_LIVE); fcmRequest.addProperty("time_to_live", TIME_TO_LIVE);
//Add message to GCM request //Add message to FCM request
JsonObject data = new JsonObject(); JsonObject data = new JsonObject();
if (message != null && !message.isEmpty()) { if (message != null && !message.isEmpty()) {
data.addProperty("data", message); data.addProperty("data", message);
gcmRequest.add("data", data); fcmRequest.add("data", data);
} }
//Set device reg-id //Set device reg-id
JsonArray regIds = new JsonArray(); JsonArray regIds = new JsonArray();
regIds.add(new JsonPrimitive(registrationId)); regIds.add(new JsonPrimitive(registrationId));
gcmRequest.add("registration_ids", regIds); fcmRequest.add("registration_ids", regIds);
return gcmRequest.toString(); return fcmRequest.toString();
} }
private static String getGCMToken(List<Device.Property> properties) { private static String getFCMToken(List<Device.Property> properties) {
String gcmToken = null; String fcmToken = null;
for (Device.Property property : properties) { for (Device.Property property : properties) {
if (GCM_TOKEN.equals(property.getName())) { if (FCM_TOKEN.equals(property.getName())) {
gcmToken = property.getValue(); fcmToken = property.getValue();
break; break;
} }
} }
return gcmToken; return fcmToken;
} }
} }

@ -16,16 +16,16 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal; package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
public class GCMDataHolder { public class FCMDataHolder {
private DeviceManagementProviderService deviceManagementProviderService; private DeviceManagementProviderService deviceManagementProviderService;
private static GCMDataHolder thisInstance = new GCMDataHolder(); private static FCMDataHolder thisInstance = new FCMDataHolder();
public static GCMDataHolder getInstance() { public static FCMDataHolder getInstance() {
return thisInstance; return thisInstance;
} }

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal; package org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -24,7 +24,7 @@ import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
/** /**
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMPushNotificationServiceComponent" immediate="true" * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal.FCMPushNotificationServiceComponent" immediate="true"
* @scr.reference name="carbon.device.mgt.provider" * @scr.reference name="carbon.device.mgt.provider"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1" * cardinality="1..1"
@ -32,23 +32,23 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
* bind="setDeviceManagementProviderService" * bind="setDeviceManagementProviderService"
* unbind="unsetDeviceManagementProviderService" * unbind="unsetDeviceManagementProviderService"
*/ */
public class GCMPushNotificationServiceComponent { public class FCMPushNotificationServiceComponent {
private static final Log log = LogFactory.getLog(GCMPushNotificationServiceComponent.class); private static final Log log = LogFactory.getLog(FCMPushNotificationServiceComponent.class);
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing GCM based push notification provider implementation bundle"); log.debug("Initializing FCM based push notification provider implementation bundle");
} }
//Do nothing //Do nothing
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("GCM based push notification provider implementation bundle has been successfully " + log.debug("FCM based push notification provider implementation bundle has been successfully " +
"initialized"); "initialized");
} }
} catch (Throwable e) { } catch (Throwable e) {
log.error("Error occurred while initializing GCM based push notification provider " + log.error("Error occurred while initializing FCM based push notification provider " +
"implementation bundle", e); "implementation bundle", e);
} }
} }
@ -59,12 +59,12 @@ public class GCMPushNotificationServiceComponent {
protected void setDeviceManagementProviderService( protected void setDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) { DeviceManagementProviderService deviceManagementProviderService) {
GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); FCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
} }
protected void unsetDeviceManagementProviderService( protected void unsetDeviceManagementProviderService(
DeviceManagementProviderService deviceManagementProviderService) { DeviceManagementProviderService deviceManagementProviderService) {
GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); FCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
} }
} }

@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
/** /**
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.XMPPPushNotificationServiceComponent" immediate="true" * @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.internal.XMPPPushNotificationServiceComponent" immediate="true"
* @scr.reference name="carbon.device.mgt.provider" * @scr.reference name="carbon.device.mgt.provider"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1" * cardinality="1..1"

@ -34,7 +34,7 @@
<url>http://wso2.org</url> <url>http://wso2.org</url>
<modules> <modules>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</module> <module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</module> <module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</module> <module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</module>
<module>org.wso2.carbon.device.mgt.extensions.device.type.deployer</module> <module>org.wso2.carbon.device.mgt.extensions.device.type.deployer</module>

@ -27,17 +27,17 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature</artifactId> <artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>2.0.24-SNAPSHOT</version> <version>2.0.24-SNAPSHOT</version>
<name>WSO2 Carbon - GCM Based Push Notification Provider Feature</name> <name>WSO2 Carbon - FCM Based Push Notification Provider Feature</name>
<url>http://wso2.org</url> <url>http://wso2.org</url>
<description>WSO2 Carbon - MQTT Based Push Notification Provider Feature</description> <description>WSO2 Carbon - MQTT Based Push Notification Provider Feature</description>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId> <artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
@ -80,7 +80,7 @@
<goal>p2-feature-gen</goal> <goal>p2-feature-gen</goal>
</goals> </goals>
<configuration> <configuration>
<id>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</id> <id>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile> <propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile> <adviceFile>
<properties> <properties>
@ -90,7 +90,7 @@
</adviceFile> </adviceFile>
<bundles> <bundles>
<bundleDef> <bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm:${carbon.device.mgt.version} org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm:${carbon.device.mgt.version}
</bundleDef> </bundleDef>
</bundles> </bundles>
<importFeatures> <importFeatures>

@ -34,7 +34,7 @@
<modules> <modules>
<module>org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature</module> <module>org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature</module> <module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature</module> <module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature</module>
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature</module> <module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature</module>
</modules> </modules>

@ -26,7 +26,7 @@
</DataSourceConfiguration> </DataSourceConfiguration>
</ManagementRepository> </ManagementRepository>
<PushNotificationProviders> <PushNotificationProviders>
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.GCMBasedPushNotificationProvider</Provider> <Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider</Provider>
<!--<Provider>org.wso2.carbon.device.mgt.mobile.impl.ios.apns.APNSBasedPushNotificationProvider</Provider>--> <!--<Provider>org.wso2.carbon.device.mgt.mobile.impl.ios.apns.APNSBasedPushNotificationProvider</Provider>-->
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider</Provider> <Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider</Provider>
<Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider</Provider> <Provider>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider</Provider>

@ -1403,7 +1403,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId> <artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm</artifactId>
<version>${carbon.device.mgt.version}</version> <version>${carbon.device.mgt.version}</version>
</dependency> </dependency>
<dependency> <dependency>

Loading…
Cancel
Save