Re: [pushy] They just don't arrive.

203 views
Skip to first unread message

Jon Chambers

unread,
Mar 6, 2015, 11:18:25 AM3/6/15
to El Xar, pushy...@googlegroups.com
It looks like you're shutting down your push manager before the notification is sent. I think you'd find that, if you looked at your push manager's queue after shutting down, your notification would still be there. See https://github.com/relayrides/pushy/wiki/Frequently-asked-questions#i-started-a-push-manager-added-a-notification-to-the-queue-and-shut-down-the-push-manager-my-push-notification-never-got-sent-why-not for additional information.

If you're building an application where you expect to create a push manager, send a bunch of notifications, and then shut down immediately, I'd recommend using a SynchronousQueue (http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/SynchronousQueue.html) as your blocking queue implementation; the SynchronousQueue will block until the push manager has woken up, opened connections, and actually attempted to send your notification.

Hope that helps!

-Jon

On Fri, Mar 6, 2015 at 10:39 AM, El Xar <xare...@googlemail.com> wrote:
I'm out of ideas. Whatever I try, I can't get pushy to push a message to my device. It's just silently sending it out to Apple (I think), but it never arrives.
First of all, I downloaded an APNS testing utility from the mac app store and that app is consistently able to send a test push with the same certificate and token, so I know the credentials are valid.

I made a simple testing class and it throws no errors, RejectedNotificationListener and FailedConnectionListener are not called, the test finishes and nothing happens.
My second problem is that I am unable to enable trace logging. I use a huge library which uses maven and sl4j is in there somewhere, but I am apparently unable to figure out how to find or create the properties file  - I spend a few hours on stackoverflow trying to enable logging alone. Is there a programmatic way to tell pushy to just log everything?

I updated pushy to 0.4.3, for netty I have to use 4.1.0-beta4 because of a maven dependency. This has been updated together with the 4.0.26 release, so I think it has the same changes.

My test class is pasted below. Logging works for warn and error levels. As I said, it runs through fine and gives no indication that something is wrong. What am I missing? Where could I go from here?
Thank you for listening.

public class PushTest {

    public static void main(String[] args) throws Exception {

        final org.slf4j.Logger log = LoggerFactory.getLogger(PushTest.class);

        log.trace("trace");
        log.debug("debug");
        log.info("info");
        log.warn("warning");
        log.error("error");


        PushTest pushTest = new PushTest();

    }

    public PushTest() throws Exception {
        String pushCertificatePath = "CertAndKey20150306.p12";

        System.out.println("Certificate path: " + pushCertificatePath);

        final PushManager<SimpleApnsPushNotification> pushManager =
                new PushManager<SimpleApnsPushNotification>(
                        ApnsEnvironment.getProductionEnvironment(),
                        SSLContextUtil.createDefaultSSLContext(pushCertificatePath, "password"),
                        null, // Optional: custom event loop group
                        null, // Optional: custom ExecutorService for calling listeners
                        null, // Optional: custom BlockingQueue implementation
                        new PushManagerConfiguration(),
                        "ExamplePushManager");
        pushManager.registerRejectedNotificationListener(new MyRejectedNotificationListener());
        pushManager.registerFailedConnectionListener(new MyFailedConnectionListener());

        pushManager.start();
       
        System.out.println("Testpush start...");
        final byte[] token = TokenUtil.tokenStringToByteArray("38541569d205f99d9db7c75ef4d67462c7b3b98941cdaf69593d24a27d0d29bc");
        //final byte[] token = TokenUtil.tokenStringToByteArray("<38541569 d205f99d 9db7c75e f4d67462 c7b3b989 41cdaf69 593d24a2 7d0d29bc>");
        final ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder();

        payloadBuilder.setAlertBody("Ring ring, Neo.");
        payloadBuilder.setSoundFileName("ring-ring.aiff");

        final String payload = payloadBuilder.buildWithDefaultMaximumLength();
        SimpleApnsPushNotification sapn = new SimpleApnsPushNotification(token, payload);
        System.out.println("notification: " + sapn.toString())  ;
        pushManager.getQueue().put(sapn);
        System.out.println("Testpush finished, shutting down...");
        pushManager.shutdown();
        System.out.println("Shutdown complete.");

    }

    class MyRejectedNotificationListener implements RejectedNotificationListener<SimpleApnsPushNotification> {

        @Override
        public void handleRejectedNotification(
                final PushManager<? extends SimpleApnsPushNotification> pushManager,
                final SimpleApnsPushNotification notification,
                final RejectedNotificationReason reason) {

            System.out.format("%s was rejected with rejection reason %s\n", notification, reason);
        }
    }

    class MyFailedConnectionListener implements FailedConnectionListener<SimpleApnsPushNotification> {

        @Override
        public void handleFailedConnection(
                final PushManager<? extends SimpleApnsPushNotification> pushManager,
                final Throwable cause) {
            System.out.format("handshake failed!");

            if (cause instanceof SSLHandshakeException) {
                // This is probably a permanent failure, and we should shut down
                // the PushManager.

            }
        }
    }

}


--
Pushy is an open-source Java library for sending APNs (iOS and OS X) push notifications. Pushy is brought to you by the engineers at RelayRides.
---
You received this message because you are subscribed to the Google Groups "pushy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pushy-apns+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

El Xar

unread,
Mar 6, 2015, 2:09:26 PM3/6/15
to pushy...@googlegroups.com, xare...@googlemail.com
Hi Jon,

yes, this is exactly what was wrong. I read some other posts and realized that shutdown() will not send out notifications in the queue. When I waited for a minute before shutting down, the pushes went out.
I noticed a delay of a few seconds when calling shutdown(), so I assumed it's because PushManager is trying to send out the remaining notifications. I should have read the documentation first.
I deleted my post because I thought it's been answered already, but you were faster :) Thanks for your help.
Reply all
Reply to author
Forward
0 new messages