получить java .lang.IllegalStateException при отправке уведомления apple pu sh? - PullRequest
0 голосов
/ 27 января 2020

Я получаю сообщение об ошибке ниже при отправке уведомления pu sh с помощью библиотеки pushy.

java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Client has been closed and can no longer send push notifications. whole stack trace is Failed to send push notification.
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Client has been closed and can no longer send push notifications.
        at io.netty.util.concurrent.AbstractFuture.get(AbstractFuture.java:41)
        at com.inslab.notificationservice.push.service.impl.NormalPushNotificationServiceImpl.sendAPNSPushNotification(NormalPushNotificationServiceImpl.java:160)
        at com.inslab.notificationservice.push.service.impl.NormalPushNotificationServiceImpl.sendNormalPushNotification(NormalPushNotificationServiceImpl.java:105)
        at com.inslab.notificationservice.push.core.PushProcessorThread.run(PushProcessorThread.java:48)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Client has been closed and can no longer send push notifications.
        at com.turo.pushy.apns.ApnsClient.<clinit>(ApnsClient.java:96)
        at com.turo.pushy.apns.ApnsClientBuilder.build(ApnsClientBuilder.java:546)
        at com.inslab.notificationservice.push.service.impl.NormalPushNotificationServiceImpl.<init>(NormalPushNotificationServiceImpl.java:72)
        at com.inslab.notificationservice.push.core.PushProcessorThread.<init>(PushProcessorThread.java:19)
        at com.inslab.notificationservice.push.core.PushNotificationProcessor.init(PushNotificationProcessor.java:27)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Код:

ApnsClient apnsClient = new ApnsClientBuilder()
    .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST)
    .setClientCredentials(cerLocationLoc, "XXXXXXXX")
    .build();

SimpleApnsPushNotification pushNotification;
ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder();
payloadBuilder.setAlertBody("Example!");

payload = APNSPayloadBuilder.buildAPNSPayloadFromNotificationDTO(pushNotificationDTO);
LOGGER.info("payload   " + payload);

token = pushNotificationDTO.getNotificationTargetIdentifier();
pushToken = TokenUtil.sanitizeTokenString(token);
LOGGER.info("Token for APNS push is **********" + pushToken);

pushNotification = new SimpleApnsPushNotification(pushToken, "", payload);

PushNotificationFuture < SimpleApnsPushNotification, PushNotificationResponse < SimpleApnsPushNotification >> sendNotificationFuture = apnsClient.sendNotification(pushNotification);

try {
    PushNotificationResponse < SimpleApnsPushNotification > pushNotificationResponse =
        sendNotificationFuture.get();

    if (pushNotificationResponse.isAccepted()) {
        LOGGER.info("Push notification accepted by APNs gateway.");
    } else {
        LOGGER.info("Notification rejected by the APNs gateway: " +
            pushNotificationResponse.getRejectionReason());

        if (pushNotificationResponse.getTokenInvalidationTimestamp() != null) {
            LOGGER.info("\t…and the token is invalid as of " +
                pushNotificationResponse.getTokenInvalidationTimestamp());
        }
    }

} catch (ExecutionException e) {
    System.err.println("Failed to send push notification.");
    e.printStackTrace();
}
...