Search in sources :

Example 1 with EnhancedApnsNotification

use of com.notnoop.apns.EnhancedApnsNotification in project camel by apache.

the class ApnsProducerTest method testProducer.

@Test(timeout = 5000)
public void testProducer() throws Exception {
    String message = "Hello World";
    String messagePayload = APNS.newPayload().alertBody(message).build();
    EnhancedApnsNotification apnsNotification = new EnhancedApnsNotification(1, EnhancedApnsNotification.MAXIMUM_EXPIRY, FAKE_TOKEN, messagePayload);
    server.stopAt(apnsNotification.length());
    template.sendBody("direct:test", message);
    server.getMessages().acquire();
    assertArrayEquals(apnsNotification.marshall(), server.getReceived().toByteArray());
}
Also used : EnhancedApnsNotification(com.notnoop.apns.EnhancedApnsNotification) Test(org.junit.Test)

Example 2 with EnhancedApnsNotification

use of com.notnoop.apns.EnhancedApnsNotification in project camel by apache.

the class ApnsProducerTest method testProducerWithApnsNotification.

@Test(timeout = 5000)
public void testProducerWithApnsNotification() throws InterruptedException {
    String message = "Hello World";
    String messagePayload = APNS.newPayload().alertBody(message).build();
    final EnhancedApnsNotification apnsNotification = new EnhancedApnsNotification(14, EnhancedApnsNotification.MAXIMUM_EXPIRY, FAKE_TOKEN, messagePayload);
    server.stopAt(apnsNotification.length());
    template.sendBody("direct:testWithApnsNotification", apnsNotification);
    server.getMessages().acquire();
    assertArrayEquals(apnsNotification.marshall(), server.getReceived().toByteArray());
}
Also used : EnhancedApnsNotification(com.notnoop.apns.EnhancedApnsNotification) Test(org.junit.Test)

Example 3 with EnhancedApnsNotification

use of com.notnoop.apns.EnhancedApnsNotification in project java-apns by notnoop.

the class AbstractApnsService method push.

public EnhancedApnsNotification push(String deviceToken, String payload, Date expiry) throws NetworkIOException {
    EnhancedApnsNotification notification = new EnhancedApnsNotification(c.incrementAndGet(), (int) (expiry.getTime() / 1000), deviceToken, payload);
    push(notification);
    return notification;
}
Also used : EnhancedApnsNotification(com.notnoop.apns.EnhancedApnsNotification)

Example 4 with EnhancedApnsNotification

use of com.notnoop.apns.EnhancedApnsNotification in project java-apns by notnoop.

the class AbstractApnsService method push.

public Collection<EnhancedApnsNotification> push(Collection<String> deviceTokens, String payload, Date expiry) throws NetworkIOException {
    byte[] messageBytes = Utilities.toUTF8Bytes(payload);
    List<EnhancedApnsNotification> notifications = new ArrayList<EnhancedApnsNotification>(deviceTokens.size());
    for (String deviceToken : deviceTokens) {
        byte[] dtBytes = Utilities.decodeHex(deviceToken);
        EnhancedApnsNotification notification = new EnhancedApnsNotification(c.incrementAndGet(), (int) (expiry.getTime() / 1000), dtBytes, messageBytes);
        notifications.add(notification);
        push(notification);
    }
    return notifications;
}
Also used : EnhancedApnsNotification(com.notnoop.apns.EnhancedApnsNotification) ArrayList(java.util.ArrayList)

Example 5 with EnhancedApnsNotification

use of com.notnoop.apns.EnhancedApnsNotification in project java-apns by notnoop.

the class AbstractApnsService method push.

public Collection<EnhancedApnsNotification> push(Collection<byte[]> deviceTokens, byte[] payload, int expiry) throws NetworkIOException {
    List<EnhancedApnsNotification> notifications = new ArrayList<EnhancedApnsNotification>(deviceTokens.size());
    for (byte[] deviceToken : deviceTokens) {
        EnhancedApnsNotification notification = new EnhancedApnsNotification(c.incrementAndGet(), expiry, deviceToken, payload);
        notifications.add(notification);
        push(notification);
    }
    return notifications;
}
Also used : EnhancedApnsNotification(com.notnoop.apns.EnhancedApnsNotification) ArrayList(java.util.ArrayList)

Aggregations

EnhancedApnsNotification (com.notnoop.apns.EnhancedApnsNotification)12 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 ApnsNotification (com.notnoop.apns.ApnsNotification)1