diff --git a/NotificationHubs/src/com/windowsazure/messaging/BaseInstallationDeserializer.java b/NotificationHubs/src/com/windowsazure/messaging/BaseInstallationDeserializer.java index 99cb654..9ed7f6b 100644 --- a/NotificationHubs/src/com/windowsazure/messaging/BaseInstallationDeserializer.java +++ b/NotificationHubs/src/com/windowsazure/messaging/BaseInstallationDeserializer.java @@ -27,6 +27,8 @@ private static Class getClass(String platformString) { return AppleInstallation.class; case "baidu": return BaiduInstallation.class; + case "browser": + return BrowserInstallation.class; case "fcm": return FcmInstallation.class; case "mpns": diff --git a/NotificationHubs/src/com/windowsazure/messaging/BrowserCredential.java b/NotificationHubs/src/com/windowsazure/messaging/BrowserCredential.java new file mode 100644 index 0000000..4d99b7d --- /dev/null +++ b/NotificationHubs/src/com/windowsazure/messaging/BrowserCredential.java @@ -0,0 +1,86 @@ +//---------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +//---------------------------------------------------------------- + +package com.windowsazure.messaging; + +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; + +/** + * This class represents Browser Push PNS credentials for Azure Notification Hubs. + */ +public final class BrowserCredential extends PnsCredential { + private String subject; + private String vapidPublicKey; + private String vapidPrivateKey; + + /** + * Creates a new BrowserCredential with default values. + */ + public BrowserCredential() { + } + + /** + * Creates a BrowserCredential with subject, VAPID public key and private key. + * @param subject The subject in mailto: or http:// form. + * @param vapidPublicKey The VAPID public key. + * @param vapidPrivateKey The VAPID private key. + */ + public BrowserCredential(String subject, String vapidPublicKey, String vapidPrivateKey) { + this.subject = subject; + this.vapidPublicKey = vapidPublicKey; + this.vapidPrivateKey = vapidPrivateKey; + } + + /** + * Gets the browser credential subject. + * @return The browser credential subject. + */ + public String getSubject() { return subject; } + + /** + * Sets the browser credential subject. + * @param value The new browser credential subject to set. + */ + public void setSubject(String value) { subject = value; } + + /** + * Gets the browser credential VAPID public key. + * @return The browser credential VAPID public key. + */ + public String getVapidPublicKey() { return vapidPublicKey; } + + /** + * Sets the browser credential VAPID public key. + * @param value The browser credential VAPID public key to set. + */ + public void setVapidPublicKey(String value) { vapidPublicKey = value; } + + /** + * Gets the browser credential VAPID private key. + * @return The browser credential VAPID private key. + */ + public String getVapidPrivateKey() { return vapidPrivateKey; } + + /** + * Sets the browser credential VAPID private key. + * @param value The browser credential VAPID private key to set. + */ + public void setVapidPrivateKey(String value) { vapidPrivateKey = value; } + + @Override + public List> getProperties() { + ArrayList> result = new ArrayList<>(); + result.add(new AbstractMap.SimpleEntry<>("Subject", subject)); + result.add(new AbstractMap.SimpleEntry<>("VapidPublicKey", vapidPublicKey)); + result.add(new AbstractMap.SimpleEntry<>("VapidPrivateKey", vapidPrivateKey)); + return result; + } + + @Override + public String getRootTagName() { + return "BrowserCredential"; + } +} diff --git a/NotificationHubs/src/com/windowsazure/messaging/BrowserInstallation.java b/NotificationHubs/src/com/windowsazure/messaging/BrowserInstallation.java new file mode 100644 index 0000000..64a5bbd --- /dev/null +++ b/NotificationHubs/src/com/windowsazure/messaging/BrowserInstallation.java @@ -0,0 +1,61 @@ +package com.windowsazure.messaging; + +/** + * This class represents an installation for browser push. + */ +public class BrowserInstallation extends BaseInstallation { + private BrowserPushChannel pushChannel; + + /** + * Creates a new instance of the BrowserInstallation class. + * + * @param installationId The ID for the installation. + */ + public BrowserInstallation(String installationId) { + this(installationId, (String[]) null); + } + + /** + * Creates a new instance of the BrowserInstallation class. + * + * @param installationId The ID for the installation. + * @param tags The tags for the installation. + */ + public BrowserInstallation(String installationId, String... tags) { + this(installationId, null, tags); + } + + /** + * Creates a new instance of the Installation class. + * + * @param installationId The ID for the installation. + */ + public BrowserInstallation(String installationId, BrowserPushChannel pushChannel) { + this(installationId, pushChannel, (String[]) null); + } + + /** + * Creates a new instance of the Installation class. + * @param installationId The ID for the installation. + * @param pushChannel The device specific push channel for the installation. + * @param tags The tags for the installation. + */ + public BrowserInstallation(String installationId, BrowserPushChannel pushChannel, String... tags) { + super(installationId, NotificationPlatform.Browser, tags); + this.pushChannel = pushChannel; + } + + /** + * Gets the PNS specific push channel for the installation. + * + * @return The PNS specific push channel for the installation. + */ + public BrowserPushChannel getPushChannel() { return pushChannel; } + + /** + * Sets the PNS specific push channel for the installation. + * + * @param value The PNS specific push channel for the installation + */ + public void setPushChannel(BrowserPushChannel value) { pushChannel = value; } +} diff --git a/NotificationHubs/src/com/windowsazure/messaging/BrowserNotification.java b/NotificationHubs/src/com/windowsazure/messaging/BrowserNotification.java new file mode 100644 index 0000000..410a810 --- /dev/null +++ b/NotificationHubs/src/com/windowsazure/messaging/BrowserNotification.java @@ -0,0 +1,4 @@ +package com.windowsazure.messaging; + +public class BrowserNotification extends Notification { +} diff --git a/NotificationHubs/src/com/windowsazure/messaging/BrowserPushChannel.java b/NotificationHubs/src/com/windowsazure/messaging/BrowserPushChannel.java new file mode 100644 index 0000000..77b09cd --- /dev/null +++ b/NotificationHubs/src/com/windowsazure/messaging/BrowserPushChannel.java @@ -0,0 +1,84 @@ +package com.windowsazure.messaging; + +import java.util.Objects; + +/** + * This class represents + */ +public class BrowserPushChannel { + private String endpoint; + private String p256dh; + private String auth; + + /** + * Creates a new instance of the BrowserPushChannel class. + */ + public BrowserPushChannel() { + + } + + /** + * Creates a new instance of the BrowserPushChannel class. + * @param endpoint The browser PNS endpoint URL. + * @param p256dh The P256DH key from the browser registration. + * @param auth The auth secret from the browser registration. + */ + public BrowserPushChannel( + String endpoint, + String p256dh, + String auth + ) { + this.endpoint = endpoint; + this.p256dh = p256dh; + this.auth = auth; + } + + /** + * Gets the browser PNS endpoint URL. + * @return The browser PNS endpoint URL. + */ + public String getEndpoint() { return endpoint; } + + /** + * Sets the browser PNS endpoint URL. + * @param value The browser PNS endpoint URL. + */ + public void setEndpoint(String value) { endpoint = value; } + + /** + * Gets the browser subscription p256dh key. + * @return The browser subscription p256dh key. + */ + public String getP256dh() { return p256dh; } + + /** + * Sets the browser subscription p256dh key. + * @param value The browser subscription p256dh key. + */ + public void setP256dh(String value) { p256dh = value; } + + /** + * Gets the browser subscription auth secret. + * @return The browser subscription auth secret. + */ + public String getAuth() { return auth; } + + /** + * Sets the browser subscription auth secret. + * @param value The browser subscription auth secret. + */ + public void setAuth(String value) { auth = value; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BrowserPushChannel that = (BrowserPushChannel) o; + return Objects.equals(getEndpoint(), that.getEndpoint()) && Objects.equals(getP256dh(), that.getP256dh()) && Objects.equals(getAuth(), that.getAuth()); + } + + @Override + public int hashCode() { + return Objects.hash(getEndpoint(), getP256dh(), getAuth()); + } +} diff --git a/NotificationHubs/src/com/windowsazure/messaging/BrowserRegistration.java b/NotificationHubs/src/com/windowsazure/messaging/BrowserRegistration.java new file mode 100644 index 0000000..3b04f70 --- /dev/null +++ b/NotificationHubs/src/com/windowsazure/messaging/BrowserRegistration.java @@ -0,0 +1,126 @@ +//---------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +//---------------------------------------------------------------- + +package com.windowsazure.messaging; + +import java.util.Objects; + +/** + * This class represents a Browser Push device registration. + */ +public class BrowserRegistration extends Registration { + private static final String BROWSER_NATIVE_REGISTRATION1 = ""; + private static final String BROWSER_NATIVE_REGISTRATION2 = ""; + private static final String BROWSER_NATIVE_REGISTRATION3 = ""; + private static final String BROWSER_NATIVE_REGISTRATION4 = ""; + private static final String BROWSER_NATIVE_REGISTRATION5 = ""; + + protected String endpoint; + protected String p256dh; + protected String auth; + + /** + * Creates a new instance of the BrowserRegistration class. + */ + public BrowserRegistration() { + super(); + } + + /** + * Creates a new instance of the BrowserRegistration class with endpoint, p256dh and auth secret. + * @param endpoint The browser PNS endpoint URL. + * @param p256dh The P256DH key from the browser registration. + * @param auth The auth secret from the browser registration. + */ + public BrowserRegistration(String endpoint, String p256dh, String auth) { + super(); + this.endpoint = endpoint; + this.p256dh = p256dh; + this.auth = auth; + } + + /** + * Creates a new instance of the BrowserRegistration class with endpoint, p256dh and auth secret. + * @param registrationId The Azure Notification Hubs registration ID. + * @param endpoint The browser PNS endpoint URL. + * @param p256dh The P256DH key from the browser registration. + * @param auth The auth secret from the browser registration. + */ + public BrowserRegistration(String registrationId, String endpoint, String p256dh, String auth) { + super(registrationId); + this.endpoint = endpoint; + this.p256dh = p256dh; + this.auth = auth; + } + + /** + * Gets the browser PNS endpoint URL. + * @return The browser PNS endpoint URL. + */ + public String getEndpoint() { return endpoint; } + + /** + * Sets the browser PNS endpoint URL. + * @param value The browser PNS endpoint URL. + */ + public void setEndpoint(String value) { endpoint = value; } + + /** + * Gets the browser subscription p256dh key. + * @return The browser subscription p256dh key. + */ + public String getP256dh() { return p256dh; } + + /** + * Sets the browser subscription p256dh key. + * @param value The browser subscription p256dh key. + */ + public void setP256dh(String value) { p256dh = value; } + + /** + * Gets the browser subscription auth secret. + * @return The browser subscription auth secret. + */ + public String getAuth() { return auth; } + + /** + * Sets the browser subscription auth secret. + * @param value The browser subscription auth secret. + */ + public void setAuth(String value) { auth = value; } + + /** + * Gets the PNS handle for getting devices by channel. + * @return The PNS handle for getting devices by channel. + */ + @Override + public String getPnsHandle() { return endpoint; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + BrowserRegistration that = (BrowserRegistration) o; + return Objects.equals(getEndpoint(), that.getEndpoint()) && Objects.equals(getP256dh(), that.getP256dh()) && Objects.equals(getAuth(), that.getAuth()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getEndpoint(), getP256dh(), getAuth()); + } + + @Override + public String getXml() { + return BROWSER_NATIVE_REGISTRATION1 + + getTagsXml() + + BROWSER_NATIVE_REGISTRATION2 + + endpoint + + BROWSER_NATIVE_REGISTRATION3 + + p256dh + + BROWSER_NATIVE_REGISTRATION4 + + auth + + BROWSER_NATIVE_REGISTRATION5; + } +} diff --git a/NotificationHubs/src/com/windowsazure/messaging/BrowserTemplateRegistration.java b/NotificationHubs/src/com/windowsazure/messaging/BrowserTemplateRegistration.java new file mode 100644 index 0000000..bd7ba35 --- /dev/null +++ b/NotificationHubs/src/com/windowsazure/messaging/BrowserTemplateRegistration.java @@ -0,0 +1,87 @@ +package com.windowsazure.messaging; + +/** + * This class represents a Browser Push device template registration. + */ +public class BrowserTemplateRegistration extends BrowserRegistration implements TemplateRegistration { + private static final String BROWSER_TEMPLATE_REGISTRATION1 = ""; + private static final String BROWSER_TEMPLATE_REGISTRATION2 = ""; + private static final String BROWSER_TEMPLATE_REGISTRATION3 = ""; + private static final String BROWSER_TEMPLATE_REGISTRATION4 = ""; + private static final String BROWSER_TEMPLATE_REGISTRATION5 = ""; + + private String bodyTemplate; + + /** + * Creates a new instance of the BrowserTemplateRegistration class. + */ + public BrowserTemplateRegistration() { + super(); + } + + /** + * Creates a new instance of the BrowserTemplateRegistration class. + * @param registrationId The Azure Notification Hubs registration ID. + * @param endpoint The browser push registration endpoint URL. + * @param p256dh The browser push registration P256DH. + * @param auth The browser push registration auth secret. + * @param bodyTemplate The browser push registration template body. + */ + public BrowserTemplateRegistration( + String registrationId, + String endpoint, + String p256dh, + String auth, + String bodyTemplate + ) { + super(registrationId, endpoint, p256dh, auth); + this.bodyTemplate = bodyTemplate; + } + + /** + * Creates a new instance of the BrowserTemplateRegistration class. + * @param endpoint The browser push registration endpoint URL. + * @param p256dh The browser push registration P256DH. + * @param auth The browser push registration auth secret. + * @param bodyTemplate The browser push registration template body. + */ + public BrowserTemplateRegistration( + String endpoint, + String p256dh, + String auth, + String bodyTemplate + ) { + super(endpoint, p256dh, auth); + this.bodyTemplate = bodyTemplate; + } + + /** + * Gets the registration template body. + * @return The registration template body. + */ + @Override + public String getBodyTemplate() { return bodyTemplate; } + + /** + * Sets the registration template body. + * @param value The registration template body to set. + */ + @Override + public void setBodyTemplate(String value) { this.bodyTemplate = value; } + + @Override + public String getXml() { + return BROWSER_TEMPLATE_REGISTRATION1 + + getTagsXml() + + BROWSER_TEMPLATE_REGISTRATION2 + + endpoint + + BROWSER_TEMPLATE_REGISTRATION3 + + p256dh + + BROWSER_TEMPLATE_REGISTRATION4 + + auth + + BROWSER_TEMPLATE_REGISTRATION5 + + bodyTemplate + + BROWSER_TEMPLATE_REGISTRATION6; + } +} diff --git a/NotificationHubs/src/com/windowsazure/messaging/NotificationHub.java b/NotificationHubs/src/com/windowsazure/messaging/NotificationHub.java index 32b7396..f4d7016 100644 --- a/NotificationHubs/src/com/windowsazure/messaging/NotificationHub.java +++ b/NotificationHubs/src/com/windowsazure/messaging/NotificationHub.java @@ -1099,6 +1099,21 @@ public NotificationOutcome sendDirectNotification(Notification notification, Str return callback.getResult(); } + /** + * Sends a direct notification to a given browser push channel. + * + * @param notification The notification to send directly to the browser push channel. + * @param pushChannel The browser push channel to target for the notification. + * @return A notification outcome with the tracking ID and notification ID. + * @throws NotificationHubsException Thrown if there is a client error. + */ + @Override + public NotificationOutcome sendDirectNotification(BrowserNotification notification, BrowserPushChannel pushChannel) throws NotificationHubsException { + SyncCallback callback = new SyncCallback<>(); + sendDirectNotificationAsync(notification, pushChannel, callback); + return callback.getResult(); + } + /** * Sends a direct notification to the given device handles. Note that this is not available on the free SKU. * @@ -1188,6 +1203,81 @@ public void cancelled() { } } + /** + * Sends a direct notification to a given browser push channel. + * + * @param notification The notification to send directly to the push channel. + * @param pushChannel The browser push channel to send directly to. + * @param callback A callback, when invoked, returns a notification outcome + */ + @Override + public void sendDirectNotificationAsync( + BrowserNotification notification, + BrowserPushChannel pushChannel, + FutureCallback callback + ) { + try { + URI uri = new URI(endpoint + hubPath + "/messages" + API_VERSION + "&direct"); + final HttpPost post = new HttpPost(uri); + final String trackingId = java.util.UUID.randomUUID().toString(); + post.setHeader("ServiceBusNotification-DeviceHandle", pushChannel.getEndpoint()); + post.setHeader("P256DH", pushChannel.getP256dh()); + post.setHeader("Auth", pushChannel.getAuth()); + post.setHeader("Authorization", tokenProvider.generateSasToken(uri)); + post.setHeader(TRACKING_ID_HEADER, trackingId); + post.setHeader("User-Agent", getUserAgent()); + + for (String header : notification.getHeaders().keySet()) { + post.setHeader(header, notification.getHeaders().get(header)); + } + + post.setEntity(new StringEntity(notification.getBody(), notification.getContentType())); + + HttpClientManager.getHttpAsyncClient().execute(post, new FutureCallback() { + public void completed(final HttpResponse response) { + try { + int httpStatusCode = response.getStatusLine().getStatusCode(); + if (httpStatusCode != 201) { + String msg = ""; + if (response.getEntity() != null && response.getEntity().getContent() != null) { + msg = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + } + msg = "Error: " + response.getStatusLine() + " body: " + msg; + callback.failed(NotificationHubsExceptionFactory.createNotificationHubException(response, httpStatusCode, msg)); + return; + } + + String notificationId = null; + Header locationHeader = response.getFirstHeader(CONTENT_LOCATION_HEADER); + if (locationHeader != null) { + URI location = new URI(locationHeader.getValue()); + String[] segments = location.getPath().split("/"); + notificationId = segments[segments.length - 1]; + } + + callback.completed(new NotificationOutcome(trackingId, notificationId)); + } catch (Exception e) { + callback.failed(e); + } finally { + post.releaseConnection(); + } + } + + public void failed(final Exception ex) { + post.releaseConnection(); + callback.failed(ex); + } + + public void cancelled() { + post.releaseConnection(); + callback.cancelled(); + } + }); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + /** * Sends a direct notification to the given device handles. Note that this is not available on the free SKU. * diff --git a/NotificationHubs/src/com/windowsazure/messaging/NotificationHubClient.java b/NotificationHubs/src/com/windowsazure/messaging/NotificationHubClient.java index 9165d68..87d47da 100644 --- a/NotificationHubs/src/com/windowsazure/messaging/NotificationHubClient.java +++ b/NotificationHubs/src/com/windowsazure/messaging/NotificationHubClient.java @@ -635,6 +635,19 @@ void scheduleNotificationAsync( NotificationOutcome sendDirectNotification(Notification notification, String deviceHandle) throws NotificationHubsException; + /** + * Sends a direct notification to a given browser push channel. + * + * @param notification The notification to send directly to the browser push channel. + * @param pushChannel The browser push channel to target for the notification. + * @return A notification outcome with the tracking ID and notification ID. + * @throws NotificationHubsException Thrown if there is a client error. + */ + NotificationOutcome sendDirectNotification( + BrowserNotification notification, + BrowserPushChannel pushChannel + ) throws NotificationHubsException; + /** * Sends a direct notification to a given device handle. * @@ -649,6 +662,20 @@ void sendDirectNotificationAsync( FutureCallback callback ); + /** + * Sends a direct notification to a given browser push channel. + * + * @param notification The notification to send directly to the push channel. + * @param pushChannel The browser push channel to send directly to. + * @param callback A callback, when invoked, returns a notification outcome + * with the tracking ID and notification ID. + */ + void sendDirectNotificationAsync( + BrowserNotification notification, + BrowserPushChannel pushChannel, + FutureCallback callback + ); + /** * Sends a direct notification to the given device handles. * diff --git a/NotificationHubs/src/com/windowsazure/messaging/NotificationPlatform.java b/NotificationHubs/src/com/windowsazure/messaging/NotificationPlatform.java index 5e6b69f..2187f8b 100644 --- a/NotificationHubs/src/com/windowsazure/messaging/NotificationPlatform.java +++ b/NotificationHubs/src/com/windowsazure/messaging/NotificationPlatform.java @@ -40,6 +40,12 @@ public enum NotificationPlatform { */ @SerializedName("adm") Adm, + /** + * The Browser Push platform. + */ + @SerializedName("browser") + Browser, + /** * The Baidu Push Platform. */ diff --git a/NotificationHubs/src/com/windowsazure/messaging/NotificationTelemetry.java b/NotificationHubs/src/com/windowsazure/messaging/NotificationTelemetry.java index 30ee3b2..189665f 100644 --- a/NotificationHubs/src/com/windowsazure/messaging/NotificationTelemetry.java +++ b/NotificationHubs/src/com/windowsazure/messaging/NotificationTelemetry.java @@ -13,6 +13,9 @@ import org.apache.commons.digester3.Digester; import org.xml.sax.SAXException; +/** + * This class represents notification telemetry counts. + */ public class NotificationTelemetry { private String notificationId; @@ -30,6 +33,7 @@ public class NotificationTelemetry { private Map fcmOutcomeCounts; private Map admOutcomeCounts; private Map baiduOutcomeCounts; + private Map browserOutcomeCounts; private String pnsErrorDetailsUri; private static final ThreadLocal parser; @@ -46,6 +50,10 @@ public static NotificationTelemetry parseOne(InputStream content) throws IOExcep return parser.get().parse(content); } + /** + * Gets the notification ID. + * @return The notification ID. + */ public String getNotificationId() { return notificationId; } @@ -182,6 +190,14 @@ public void setAdmOutcomeCounts(Map admOutcomeCounts) { this.admOutcomeCounts = admOutcomeCounts; } + public Map getBrowserOutcomeCounts() { + return browserOutcomeCounts; + } + + public void setBrowserOutcomeCounts(Map browserOutcomeCounts) { + this.browserOutcomeCounts = browserOutcomeCounts; + } + public String getPnsErrorDetailsUri() { return pnsErrorDetailsUri; } @@ -252,5 +268,11 @@ private static void setupParser(Digester digester) { digester.addCallParam("*/Name", 0); digester.addCallParam("*/Count", 1); digester.addSetNext("*/BaiduOutcomeCounts", "setBaiduOutcomeCounts", Map.class.getName()); + + digester.addObjectCreate("*/BrowserOutcomeCounts", HashMap.class); + digester.addCallMethod("*/Outcome", "put", 2, new Class[]{String.class, Integer.class}); + digester.addCallParam("*/Name", 0); + digester.addCallParam("*/Count", 1); + digester.addSetNext("*/BrowserOutcomeCounts", "setBrowserOutcomeCounts", Map.class.getName()); } } diff --git a/NotificationHubs/src/com/windowsazure/messaging/Registration.java b/NotificationHubs/src/com/windowsazure/messaging/Registration.java index cd34604..d7a2d38 100644 --- a/NotificationHubs/src/com/windowsazure/messaging/Registration.java +++ b/NotificationHubs/src/com/windowsazure/messaging/Registration.java @@ -219,6 +219,10 @@ private static void addRegistrationRules(Digester digester) { BaiduRegistration.class); digester.addObjectCreate("*/BaiduTemplateRegistrationDescription", BaiduTemplateRegistration.class); + digester.addObjectCreate("*/BrowserRegistrationDescription", + BrowserRegistration.class); + digester.addObjectCreate("*/BrowserTemplateRegistrationDescription", + BrowserTemplateRegistration.class); digester.addCallMethod("*/RegistrationId", "setRegistrationId", 1); digester.addCallParam("*/RegistrationId", 0); digester.addCallMethod("*/ETag", "setEtag", 1); @@ -251,6 +255,12 @@ private static void addRegistrationRules(Digester digester) { digester.addCallParam("*/BaiduUserId", 0); digester.addCallMethod("*/BaiduChannelId", "setBaiduChannelId", 1); digester.addCallParam("*/BaiduChannelId", 0); + digester.addCallMethod("*/Endpoint", "setEndpoint", 1); + digester.addCallParam("*/Endpoint", 0); + digester.addCallMethod("*/P256DH", "setP256dh", 1); + digester.addCallParam("*/P256DH", 0); + digester.addCallMethod("*/Auth", "setAuth", 1); + digester.addCallParam("*/Auth", 0); } public static CollectionResult parseRegistrations(InputStream content) diff --git a/NotificationHubs/test/com/windowsazure/messaging/InstallationBrowserMinimal b/NotificationHubs/test/com/windowsazure/messaging/InstallationBrowserMinimal new file mode 100644 index 0000000..dce8c02 --- /dev/null +++ b/NotificationHubs/test/com/windowsazure/messaging/InstallationBrowserMinimal @@ -0,0 +1,9 @@ +{ + "pushChannel":{ + "endpoint":"https://some.url", + "p256dh":"p256-value", + "auth":"auth-value" + }, + "installationId":"123", + "platform":"browser" +} diff --git a/NotificationHubs/test/com/windowsazure/messaging/InstallationParseTest.java b/NotificationHubs/test/com/windowsazure/messaging/InstallationParseTest.java index 113be8b..19fce1b 100644 --- a/NotificationHubs/test/com/windowsazure/messaging/InstallationParseTest.java +++ b/NotificationHubs/test/com/windowsazure/messaging/InstallationParseTest.java @@ -20,6 +20,21 @@ public class InstallationParseTest { + @Test + public void InstallationBrowser() throws IOException { + BrowserPushChannel pushChannel = new BrowserPushChannel( + "https://some.url", + "p256-value", + "auth-value"); + + InputStream inputJson = this.getClass().getResourceAsStream("InstallationBrowserMinimal"); + BrowserInstallation installation = BaseInstallation.fromJson(inputJson); + assertNotNull(installation); + assertEquals("123", installation.getInstallationId()); + assertEquals(NotificationPlatform.Browser, installation.getPlatform()); + assertEquals(pushChannel, installation.getPushChannel()); + } + @Test public void InstallationMinimal() throws IOException { InputStream inputJson = this.getClass().getResourceAsStream("InstallationMinimal");