Отправка PUSH-уведомлений на устройства Apple: java.lang.IllegalStateException: Channel closed before HTTP/2 preface completed

181
28 июня 2018, 07:50

Пытаюсь отправить push-уведомления на устройства Apple. Использую библиотеку:

compile "com.turo:pushy:0.11.3"

Логика отправки следующая:

@Override
public BasePushMessageDto send(BasePushMessageDto dto, Locale locale) {
    List<PushNotificationResponse<SimpleApnsPushNotification>> responses = new ArrayList<>();
    ApnsClient client = createClient();
    String payloadBody = GSON.toJson(createMessage());
    Arrays.asList(dto.getPushIds()).forEach(token -> {
        try {
            SimpleApnsPushNotification notification
                    = new SimpleApnsPushNotification(TokenUtil.sanitizeTokenString(token), PUSH_TOPIC, payloadBody);
            Future<PushNotificationResponse<SimpleApnsPushNotification>> pushNotificationResponseFuture = client.sendNotification(notification);
            PushNotificationResponse<SimpleApnsPushNotification> response = pushNotificationResponseFuture.get();
            responses.add(response);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    });
    return responses;
}
private ApnsClient createClient() {
    try {
        ApnsClient build = new ApnsClientBuilder()
                .setClientCredentials(new File(properties.getApnKeyName()), properties.getApnKeyPass())
                .setApnsServer(properties.getApnHost())
                .build();
        return build;
    } catch (IOException e) {
        throw new ConfigException(e);
    }
}
//тестовое сообщение
private Map<String, Object> createMessage() {
    return Stream.<Map.Entry<String, Object>>of(
            CollectionUtils.entry("aps", Stream.<Map.Entry<String, Object>>of(
                    CollectionUtils.entry("alert", Stream.<Map.Entry<String, Object>>of(
                            CollectionUtils.entry("title", "Test title"),
                            CollectionUtils.entry("body", "Test Body")
                    ).collect(CollectionUtils.entriesToMap())),
                    CollectionUtils.entry("badge", "0")
            ).collect(CollectionUtils.entriesToMap()))
    ).collect(CollectionUtils.entriesToMap());
}

Настройки следующие:

apn.host=api.push.apple.com
apn.key.name=./src/main/resources/data/prod.p12
apn.key.pass=***

При попытке исполнить код валится со следующим стектрейсом:

Caused by: java.lang.IllegalStateException: Channel closed before HTTP/2 preface completed.
    at com.turo.pushy.apns.ApnsChannelFactory$3$2.operationComplete(ApnsChannelFactory.java:198)
    at com.turo.pushy.apns.ApnsChannelFactory$3$2.operationComplete(ApnsChannelFactory.java:192)
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:485)
    at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
    at io.netty.util.concurrent.DefaultPromise.addListener(DefaultPromise.java:162)
    at io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:95)
    at io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:30)
    at com.turo.pushy.apns.ApnsChannelFactory$3.run(ApnsChannelFactory.java:192)
    at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:125)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:465)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:748)
READ ALSO
Свой Behavior для View внутри Toolbar в CoordinatorLayout

Свой Behavior для View внутри Toolbar в CoordinatorLayout

Недавно начал изучать CoordinatorLayout и решил написать свой Behavior

174
Как указать главный класс при сборки jar GRADLE

Как указать главный класс при сборки jar GRADLE

Мне нужно указать в buildgradle чтобы он считал главный класс - с методом main был допустим hello

204
Jsoup разбор таблицы

Jsoup разбор таблицы

Есть таблица со строкой

213