Sending push notifications not possible in native mode
andlinger opened this issue · comments
It's not possible to send push notifications with FirebaseMessaging if extension is running in native mode.
Following code works in JAR but not in native:
var messaging = FirebaseMessaging.getInstance(firebaseApp);
var notification = Notification.builder()
.setTitle("Title")
.setBody("Body")
.build();
var message = MulticastMessage.builder()
.setNotification(notification)
.addAllTokens(List.of("DEVICE_TOKEN"))
.build();
try {
var response = messaging.sendMulticast(message);
} catch (FirebaseMessagingException e) {
throw new RuntimeException(e);
}
The request runs properly, but if you look at the response, you can see that for each device token the following error occurs:
com.google.firebase.messaging.FirebaseMessagingException: Recipient of the message is not set.
at com.google.firebase.messaging.FirebaseMessagingClientImpl$MessagingBatchCallback.onFailure(FirebaseMessagingClientImpl.java:259)
at com.google.firebase.messaging.FirebaseMessagingClientImpl$MessagingBatchCallback.onFailure(FirebaseMessagingClientImpl.java:243)
at com.google.api.client.googleapis.batch.BatchUnparsedResponse.parseAndCallback(BatchUnparsedResponse.java:209)
at com.google.api.client.googleapis.batch.BatchUnparsedResponse.parseNextResponse(BatchUnparsedResponse.java:149)
at com.google.api.client.googleapis.batch.BatchRequest.execute(BatchRequest.java:269)
at com.google.firebase.messaging.FirebaseMessagingClientImpl.sendBatchRequest(FirebaseMessagingClientImpl.java:138)
at com.google.firebase.messaging.FirebaseMessagingClientImpl.sendAll(FirebaseMessagingClientImpl.java:118)
at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:295)
at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:292)
at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
at java.base@17.0.6/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base@17.0.6/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base@17.0.6/java.lang.Thread.run(Thread.java:833)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)
Got it to work with following reflection-config.json file:
[
{
"name" : "com.google.firebase.messaging.Message",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.google.firebase.messaging.internal.MessagingServiceResponse",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}
]
Firebase messaging is not supported for the moment.
If you have GraalVM native image reflection configuration for it, the best is to open an issue upstream (should b https://github.com/firebase/firebase-admin-java) as Google Cloud library authors now include GraalVM native image support directly inside their libraries.