title: APNS accepts push messages, but they are never come to target
body: <p>I'm trying, to add apple push notifications for my backend server services, but i faced an issue, that i cant understand.<br>
  I'm using Pushy library <a href="https://github.com/relayrides/pushy" rel="nofollow">(com.relayriders.pushy)</a>.<br>
  My code is just like their github page recommends.<br>
  Code is works, there is no exceptions, push looks like formed properly. Push sends to APNS, but never comes to device.<br>
  Device token and certificate are correct to, my friend sent push to target device through his test program.<br>
  I also tested <a href="https://github.com/notnoop/java-apns" rel="nofollow">com.notnoop.apns</a>  library with the same result - no exceptions and still no push on device<br>
  Here is my sender class:<br></p>
  
  <pre><code>package ua.asprelis.communicator.push;
  
  import com.relayrides.pushy.apns.ApnsEnvironment;
  import com.relayrides.pushy.apns.FailedConnectionListener;
  import com.relayrides.pushy.apns.PushManager;
  import com.relayrides.pushy.apns.PushManagerConfiguration;
  import com.relayrides.pushy.apns.RejectedNotificationListener;
  import com.relayrides.pushy.apns.RejectedNotificationReason;
  import com.relayrides.pushy.apns.util.ApnsPayloadBuilder;
  import com.relayrides.pushy.apns.util.MalformedTokenStringException;
  import com.relayrides.pushy.apns.util.SSLContextUtil;
  import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
  import com.relayrides.pushy.apns.util.TokenUtil;
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLDecoder;
  import java.security.KeyManagementException;
  import java.security.KeyStoreException;
  import java.security.NoSuchAlgorithmException;
  import java.security.UnrecoverableKeyException;
  import java.security.cert.CertificateException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.net.ssl.SSLHandshakeException;
  
  
  public class ApplePushNotifier
  {
      private final PushManager&lt;SimpleApnsPushNotification&gt; pushManager;
  
      private final ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder();
  
      public ApplePushNotifier() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException, IOException {
          URL url = getClass().getResource("/certpath/cert.p12");
          this.pushManager = new PushManager&lt;&gt;(
              ApnsEnvironment.getSandboxEnvironment(),
              SSLContextUtil.createDefaultSSLContext(URLDecoder.decode(url.getPath(), "UTF-8"), "password"),
              null, // Optional: custom event loop group
              null, // Optional: custom ExecutorService for calling listeners
              null, // Optional: custom BlockingQueue implementation
              new PushManagerConfiguration(),
              "ExamplePushManager");
          pushManager.start();
          pushManager.registerRejectedNotificationListener(new MyRejectedNotificationListener());
          pushManager.registerFailedConnectionListener(new MyFailedConnectionListener());
      }
  
      public void sendpush(String message, byte[] token) throws InterruptedException {
          String payload = payloadBuilder.setAlertBody(message).setSoundFileName("ring-ring.aiff").buildWithDefaultMaximumLength();
          pushManager.getQueue().put(new SimpleApnsPushNotification(token, payload));
      }
  
      public void sendpush(String message, String stoken) throws InterruptedException, MalformedTokenStringException {
          byte[]token = TokenUtil.tokenStringToByteArray(stoken);
          String payload = payloadBuilder.setAlertBody(message).setSoundFileName("ring-ring.aiff").buildWithDefaultMaximumLength();
          SimpleApnsPushNotification notification = new SimpleApnsPushNotification(token, payload);
          pushManager.getQueue().put(notification);
          System.out.println("Queued: "+notification);
      }
  
      public void closeSender() {
          if(pushManager!=null) {
              try {
                  pushManager.shutdown();
              } catch (InterruptedException ex) {
                  Logger.getLogger(ApplePushNotifier.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }
  
      private class MyRejectedNotificationListener implements RejectedNotificationListener&lt;SimpleApnsPushNotification&gt; {
          @Override
          public void handleRejectedNotification(
              final PushManager&lt;? extends SimpleApnsPushNotification&gt; pushManager,
              final SimpleApnsPushNotification notification,
              final RejectedNotificationReason reason) {
              System.out.format("%s was rejected with rejection reason %s\n", notification, reason);
          }
      }
  
      private class MyFailedConnectionListener implements FailedConnectionListener&lt;SimpleApnsPushNotification&gt; {
          @Override
          public void handleFailedConnection(
              final PushManager&lt;? extends SimpleApnsPushNotification&gt; pushManager,
              final Throwable cause) {
              if (cause instanceof SSLHandshakeException)
                  // This is probably a permanent failure, and we should shut down the PushManager.
              else
                  System.out.println(cause);
          }
      }
  }
  </code></pre>
  
  <p>And test class for running push:<br></p>
  
  <pre><code>@Test
  public void testPushMessage() {
      Random random = new Random();
      String testMessage = "Hello Test! "+random.nextInt(1000);
      String testToken = "e6878d3993abfaec48220b9d4d3ea0b576c22351c7fbbb5faeb5449bf7f24452";
                        //e6878d39 93abfaec 48220b9d 4d3ea0b5 76c22351 c7fbbb5f aeb5449b f7f24452
  
      ApplePushNotifier notifier=null;
      try {
          notifier = new ApplePushNotifier();
          notifier.sendpush(testMessage, testToken);
      } catch(Exception ex) {
          Logger.getLogger(applePushNotifierTest.class.getName()).log(Level.SEVERE, null, ex);
      } finally {
          if (notifier!=null)
              notifier.closeSender();
      }
  }
  </code></pre>
  
  <p>And my output:</p>
  
  <pre><code>[main] INFO com.relayrides.pushy.apns.PushManager - ExamplePushManager starting.
      Queued: SimpleApnsPushNotification [token=[-26, -121, -115, 57, -109, -85, -6, -20, 72, 34, 11, -99, 77, 62, -96, -75, 118, -62, 35, 81, -57, -5, -69, 95, -82, -75, 68, -101, -9, -14, 68, 82], payload={"aps":{"alert":"Hello Test! 955","sound":"ring-ring.aiff"}}, invalidationTime=null, priority=IMMEDIATE]
      [main] INFO com.relayrides.pushy.apns.PushManager - ExamplePushManager shutting down.
  </code></pre>
  
  <p>I feel that problem is in some tiny piece, that i cant see. It would be strange if both tested libraries dont work</p>