Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NotificationHubs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.windowsazure</groupId>
<artifactId>Notification-Hubs-java-sdk</artifactId>
<version>0.4.0</version>
<version>0.5.0</version>
<name>Windows Azure Notification Hubs Java SDK</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
49 changes: 34 additions & 15 deletions NotificationHubs/src/com/windowsazure/messaging/AdmCredential.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,60 @@
import java.util.ArrayList;
import java.util.List;

/**
* This class represents Amazon PNS credentials.
*/
public final class AdmCredential extends PnsCredential {
private String clientId;
private String clientSecret;

/**
* Creates a new instance of the AdmCredential class.
*/
public AdmCredential() {
this(null, null);
super();
}

/**
* Creates a new instance of the AdmCredential class.
* @param clientId The Amazon client ID.
* @param clientSecret The Amazon client secret.
*/
public AdmCredential(String clientId, String clientSecret) {
super();
this.setClientId(clientId);
this.setClientSecret(clientSecret);
}

public String getClientId() {
return clientId;
}
/**
* Gets the Amazon client ID.
* @return The Amazon client ID.
*/
public String getClientId() { return clientId; }

public void setClientId(String clientId) {
this.clientId = clientId;
}
/**
* Gets the Amazon client ID.
* @param value THe Amazon client ID to set.
*/
public void setClientId(String value) { clientId = value; }

public String getClientSecret() {
return clientSecret;
}
/**
* Gets the Amazon client secret.
* @return The Amazon client secret.
*/
public String getClientSecret() { return clientSecret; }

public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
/**
* Sets the Amazon client secret.
* @param value The Amazon client secret to set.
*/
public void setClientSecret(String value) { clientSecret = value; }

@Override
public List<SimpleEntry<String, String>> getProperties() {
ArrayList<SimpleEntry<String, String>> result = new ArrayList<>();
result.add(new SimpleEntry<>("ClientId", getClientId()));
result.add(new SimpleEntry<>("ClientSecret", getClientSecret()));
result.add(new SimpleEntry<>("ClientId", clientId));
result.add(new SimpleEntry<>("ClientSecret", clientSecret));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.windowsazure.messaging;

import org.apache.http.entity.ContentType;

/**
* This class represents a notification to the Amazon PNS.
*/
public class AdmNotification extends Notification {

/**
* Creates a new instance of the AdmNotification class.
* @param body The JSON body for the Amazon PNS.
*/
public AdmNotification(String body) {
this.body = body;
this.contentType = ContentType.APPLICATION_JSON;

this.headers.put("ServiceBusNotification-Format", "adm");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,72 @@

package com.windowsazure.messaging;

import java.util.Objects;

/**
* This class represents an Amazon device registration.
*/
public class AdmRegistration extends Registration {
private static final String ADM_NATIVE_REGISTRATION1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><content type=\"application/xml\"><AdmRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">";
private static final String ADM_NATIVE_REGISTRATION2 = "<AdmRegistrationId>";
private static final String ADM_NATIVE_REGISTRATION3 = "</AdmRegistrationId></AdmRegistrationDescription></content></entry>";

protected String admRegistrationId;

/**
* Creates a new instance of the AdmRegistration class.
*/
public AdmRegistration() {
super();
}

/**
* Creates a new instance of the AdmRegistration class.
* @param registrationId The Azure Notification Hubs registration ID for the device.
* @param admRegistrationId The Amazon device registration ID.
*/
public AdmRegistration(String registrationId, String admRegistrationId) {
super(registrationId);
this.admRegistrationId = admRegistrationId;
}

/**
* Creates a new instance of the AdmRegistration class.
* @param admRegistrationId The Amazon device registration ID.
*/
public AdmRegistration(String admRegistrationId) {
super();
this.admRegistrationId = admRegistrationId;
}

/**
* Gets the Amazon registration ID for the device.
* @return The Amazon registration ID for the device.
*/
public String getAdmRegistrationId() {
return admRegistrationId;
}

public void setAdmRegistrationId(String admRegistrationId) {
this.admRegistrationId = admRegistrationId;
/**
* Sets the Amazon registration ID for the device.
* @param value The Amazon registration ID for the device to set.
*/
public void setAdmRegistrationId(String value) {
admRegistrationId = value;
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime
* result
+ ((admRegistrationId == null) ? 0 : admRegistrationId
.hashCode());
return result;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
AdmRegistration that = (AdmRegistration) o;
return Objects.equals(getAdmRegistrationId(), that.getAdmRegistrationId());
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AdmRegistration other = (AdmRegistration) obj;
if (admRegistrationId == null) {
if (other.admRegistrationId != null)
return false;
} else if (!admRegistrationId.equals(other.admRegistrationId))
return false;
return true;
public int hashCode() {
return Objects.hash(super.hashCode(), getAdmRegistrationId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,62 @@

package com.windowsazure.messaging;

public class AdmTemplateRegistration extends AdmRegistration {
/**
* This class represents an Amazon device template registration.
*/
public class AdmTemplateRegistration extends AdmRegistration implements TemplateRegistration {
private static final String ADM_TEMPLATE_REGISTRATION1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><content type=\"application/xml\"><AdmTemplateRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">";
private static final String ADM_TEMPLATE_REGISTRATION2 = "<AdmRegistrationId>";
private static final String ADM_TEMPLATE_REGISTRATION3 = "</AdmRegistrationId><BodyTemplate><![CDATA[";
private static final String ADM_TEMPLATE_REGISTRATION4 = "]]></BodyTemplate></AdmTemplateRegistrationDescription></content></entry>";

private String bodyTemplate;

/**
* Creates a new instance of the AdmTemplateRegistration class.
*/
public AdmTemplateRegistration() {
super();
}

public AdmTemplateRegistration(String registrationId,
String admRegistrationId, String bodyTemplate) {
/**
* Creates a new instance of the AdmTemplateRegistration class.
* @param registrationId The Azure Notification Hubs registration ID.
* @param admRegistrationId The Amazon device registration ID.
* @param bodyTemplate The template body.
*/
public AdmTemplateRegistration(
String registrationId,
String admRegistrationId,
String bodyTemplate
) {
super(registrationId, admRegistrationId);
this.bodyTemplate = bodyTemplate;
}

/**
* Creates a new instance of the AdmTemplateRegistration class.
* @param admRegistrationId The Amazon device registration ID.
* @param bodyTemplate The template body.
*/
public AdmTemplateRegistration(String admRegistrationId, String bodyTemplate) {
super(admRegistrationId);
this.bodyTemplate = bodyTemplate;
}

public String getBodyTemplate() {
return bodyTemplate;
}
/**
* Gets the registration template body.
* @return The registration template body.
*/
@Override
public String getBodyTemplate() { return bodyTemplate; }

public void setBodyTemplate(String bodyTemplate) {
this.bodyTemplate = 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 int hashCode() {
Expand Down Expand Up @@ -66,7 +92,7 @@ public String getXml() {
return ADM_TEMPLATE_REGISTRATION1 +
getTagsXml() +
ADM_TEMPLATE_REGISTRATION2 +
admRegistrationId +
getAdmRegistrationId() +
ADM_TEMPLATE_REGISTRATION3 +
bodyTemplate +
ADM_TEMPLATE_REGISTRATION4;
Expand Down
Loading