Пытаюсь отправить 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)
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Недавно начал изучать CoordinatorLayout и решил написать свой Behavior
Мне нужно указать в buildgradle чтобы он считал главный класс - с методом main был допустим hello
при тестировании в chrome требуется использовать плагин, а тк