@Override public void operationComplete(io.netty.util.concurrent.Future<PushNotificationResponse<SimpleApnsPushNotification>> result) { try { PushNotificationResponse<SimpleApnsPushNotification> response = result.get(); if (response.isAccepted()) { future.set(new ApnResult(ApnResult.Status.SUCCESS, null)); } else if ("Unregistered".equals(response.getRejectionReason())) { future.set(new ApnResult(ApnResult.Status.NO_SUCH_USER, response.getRejectionReason())); } else { logger.warn("Got APN failure: " + response.getRejectionReason()); future.set(new ApnResult(ApnResult.Status.GENERIC_FAILURE, response.getRejectionReason())); } } catch (InterruptedException e) { future.setException(e); } catch (ExecutionException e) { if (e.getCause() instanceof ClientNotConnectedException) setDisconnected(e.getCause()); else future.setException(e.getCause()); } }
private String getResponse(SimpleApnsPushNotification pushNotification) throws InterruptedException, ExecutionException { final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = apnsClient.sendNotification(pushNotification).get(); if (pushNotificationResponse.isAccepted()) { LOG.debug("Push notification accepted by APNs gateway."); return "Push notification accepted by APNs gateway."; } LOG.error("Notification rejected by the APNs gateway: {}", pushNotificationResponse.getRejectionReason()); String result = String.format("Notification rejected by the APNs gateway: %s", pushNotificationResponse.getRejectionReason()); if (pushNotificationResponse.getTokenInvalidationTimestamp() != null) { LOG.error("\t…and the token is invalid as of {}", pushNotificationResponse.getTokenInvalidationTimestamp()); result += String.format("\t…and the token is invalid as of {}", pushNotificationResponse.getTokenInvalidationTimestamp()); } return result; }
protected void handlePushNotificationResponse(final PushNotificationResponse<ApnsPushNotification> response) { log.debug("Received response from APNs gateway: {}", response); // This will always be called from inside the channel's event loop, so we don't have to worry about // synchronization. final Promise<PushNotificationResponse<ApnsPushNotification>> responsePromise = this.responsePromises.remove(response.getPushNotification()); if (EXPIRED_AUTH_TOKEN_REASON.equals(response.getRejectionReason())) { this.sendNotification(response.getPushNotification(), responsePromise); } else { responsePromise.setSuccess(response); } }