add wns changes

Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/24e7cda7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/24e7cda7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/24e7cda7

Branch: refs/heads/USERGRID-593
Commit: 24e7cda7b15c028b00de3285466c8abd9840be87
Parents: 381d8c5
Author: Shawn Feldman <sfeld...@apache.org>
Authored: Thu Apr 23 09:31:16 2015 -0600
Committer: Shawn Feldman <sfeld...@apache.org>
Committed: Thu Apr 23 09:31:16 2015 -0600

----------------------------------------------------------------------
 .../Client/IUsergridClient.cs                   |  2 +-
 .../Usergrid.Notifications/Client/PushClient.cs |  2 +-
 .../Usergrid.Notifications/MainPage.xaml.cs     |  6 +-
 .../services/notifications/wns/WNSAdapter.java  | 60 +++++++-------------
 4 files changed, 26 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24e7cda7/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
----------------------------------------------------------------------
diff --git 
a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
 
b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
index 5279e32..5efbb9b 100644
--- 
a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
+++ 
b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
@@ -108,7 +108,7 @@ namespace Usergrid.Notifications.Client
         /// <param name="message"></param>
         /// <returns></returns>
         Task<bool> SendToast(string message);
-        Task<bool> SendRaw(JObject message);
+        Task<bool> SendRaw(string message);
         /// <summary>
         /// Send a badge update
         /// </summary>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24e7cda7/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
----------------------------------------------------------------------
diff --git 
a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs 
b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
index 54d7b00..7ccb391 100644
--- 
a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
+++ 
b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
@@ -86,7 +86,7 @@ namespace Usergrid.Notifications.Client
         }
 
 
-        public async Task<bool> SendRaw(JObject message)
+        public async Task<bool> SendRaw(string message)
         {
             if (DeviceId == null)
             {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24e7cda7/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
----------------------------------------------------------------------
diff --git 
a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs 
b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
index 80b6dd8..2625289 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
@@ -45,7 +45,7 @@ namespace Usergrid.Notifications
         {
             this.InitializeComponent();
             //TODO: change me to your server
-            serverUrl = "http://yoururl/";;
+            serverUrl = "http://10.0.1.20:8080/";;
             //TODO: change me to your org
             org = "test-organization";
             //TODO: change me to your app
@@ -55,7 +55,7 @@ namespace Usergrid.Notifications
             //TODO: change me to your user
             user = "mobileuser";
             //TODO: change me to your password
-            password = "password";
+            password = "P@ssw0rd1";
             this.NavigationCacheMode = NavigationCacheMode.Required;
             usergrid = new Client.Usergrid(serverUrl, org, app, user, 
password, notifier);
 
@@ -130,7 +130,7 @@ namespace Usergrid.Notifications
 
             JObject obj = new JObject();
             obj.Add("message", message);
-            if (await usergrid.Push.SendRaw(obj))
+            if (await usergrid.Push.SendRaw(message))
             {
                 Result.Text = "It did! :)";
             }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24e7cda7/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
----------------------------------------------------------------------
diff --git 
a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
 
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
index 34ae63f..1fe8f72 100644
--- 
a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
+++ 
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
@@ -21,10 +21,9 @@
 package org.apache.usergrid.services.notifications.wns;
 
 import ar.com.fernandospr.wns.WnsService;
-import ar.com.fernandospr.wns.model.WnsBadge;
-import ar.com.fernandospr.wns.model.WnsRaw;
-import ar.com.fernandospr.wns.model.WnsToast;
+import ar.com.fernandospr.wns.model.*;
 import ar.com.fernandospr.wns.model.builders.WnsBadgeBuilder;
+import ar.com.fernandospr.wns.model.builders.WnsRawBuilder;
 import ar.com.fernandospr.wns.model.builders.WnsToastBuilder;
 import com.sun.jersey.api.client.ClientHandlerException;
 import org.apache.usergrid.persistence.EntityManager;
@@ -64,9 +63,9 @@ public class WNSAdapter implements ProviderAdapter {
         WnsToast toast = new 
WnsToastBuilder().bindingTemplateToastText01("test").build();
         try{
             //this fails every time due to jax error which is ok
-            
service.pushToast("s-1-15-2-2411381248-444863693-3819932088-4077691928-1194867744-112853457-373132695",toast);
+            
service.pushToast("s-1-15-2-2411381248-444863693-3819932088-4077691928-1194867744-112853457-373132695",
 toast);
         }catch (ClientHandlerException e){
-            LOG.info("Windows Phone notifier added: "+e.toString());
+            LOG.info("Windows Phone notifier added: " + e.toString());
         }
     }
 
@@ -89,12 +88,23 @@ public class WNSAdapter implements ProviderAdapter {
                         }
                         service.pushBadge(providerId, badge);
                         break;
-                    case "raw" :
-                        WnsRaw raw = new WnsRaw();
-                        raw.stream = toBytes( 
translatedNotification.getMessage() ) ;
-                        service.pushRaw(providerId, raw);
+                    case "raw":
+                        Object message = translatedNotification.getMessage();
+                        if(message instanceof String) {
+                            WnsRaw raw = new WnsRawBuilder().stream(((String) 
message).getBytes()).build();
+                            WnsNotificationRequestOptional opt = new 
WnsNotificationRequestOptional();
+                            opt.cachePolicy = "cache";
+                            opt.requestForStatus = "true";
+                            WnsNotificationResponse response = 
service.pushRaw(providerId, opt, raw);
+                            if 
(!response.notificationStatus.equals("received")) { // 
https://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#pncodes_x_wns_notification
+                                throw new 
Exception(String.format("Notification failed status:%s, devicesStatus:%s, 
description:%s, debug flag:%s", response.notificationStatus, 
response.deviceConnectionStatus, response.errorDescription, 
response.debugTrace));
+                            }
+                        }else{
+                            throw new IllegalArgumentException("You must send 
a string in the raw body. instead got this: " + message.getClass().getName());
+                        }
                         break;
-                    default : throw new 
IllegalArgumentException(translatedNotification.getType()+" does not match a 
valid notification type (toast,badge).");
+                    default:
+                        throw new 
IllegalArgumentException(translatedNotification.getType() + " does not match a 
valid notification type (toast,badge).");
                 }
             }
             tracker.completed();
@@ -104,35 +114,7 @@ public class WNSAdapter implements ProviderAdapter {
         }
     }
 
-    private byte[] toBytes(Object message) {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        ObjectOutput out = null;
-        try {
-            if(message instanceof Serializable) {
-                out = new ObjectOutputStream(bos);
-                out.writeObject(message);
-                byte[] yourBytes = bos.toByteArray();
-                return yourBytes;
-            }else{
-                throw new RuntimeException("message is not serializable");
-            }
-        }catch (IOException e){
-            throw new RuntimeException(e);
-        } finally {
-            try {
-                if (out != null) {
-                    out.close();
-                }
-            } catch (IOException ex) {
-                // ignore close exception
-            }
-            try {
-                bos.close();
-            } catch (IOException ex) {
-                // ignore close exception
-            }
-        }
-    }
+
     @Override
     public void doneSendingNotifications() throws Exception {
 

Reply via email to