Unable to send firebase notification via server.
Sufiyan-Salman opened this issue · comments
Environment
- Operating System version: Linux
- Firebase SDK version: 9.2.0
- Library version: same
- Firebase Product: cloud messaging api
The problem
I have a springboot project and added firebase dependency and all related things. When I run the project locally, everything works fine. I then deploy on the remote server, I get the exception which I will share below. I am using firebase admin sdk to send notifications.
The code for sending is:
try {
messagingService.send(message);
logger.info("Firebase notification sent to user: "+user.getUsername());
saveLog(true, "Notification Sent", pushNotificationLog);
return true;
}catch (FirebaseMessagingException e) {
logger.info("Firebase did not send notification to user: "+user.getUsername()+ " Error Message: "+e.getMessage());
saveLog(false, e.getMessage(), pushNotificationLog);
return false;
}
Steps to reproduce:
I don't know what we can do to reproduce as it is happening with my server, I guess.
As soon as I do the same on my remote server after deploying my code, I get the exception while sending the notification, this is what it says:
Error Message: Unknown error while making a remote service call: Error getting access token for service account: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext), iss: firebase-adminsdk-b12345@abc1-c1235.ibm.gserviceaccount.com
I have go daddy certificate.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Now to narrow down this issue even more, I got a lead, which is:
I wrote the following line in my docker file and faced the issue because this.
ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","-Djavax.net.ssl.keyStore=/opt/java/openjdk/lib/security/cacerts","-Djavax.net.ssl.keyStorePassword=cheit","-Djdk.tls.client.protocols=TLSv1.2", "/app.jar"]
When I changed the above line to the one below, it worked.
ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","-Djdk.tls.client.protocols=TLSv1.2", "/app.jar"]
This shows that cacerts file has some issue, but it only appears when I use firebase.
What can I do to resolve this?
The path which was leading to cacerts file was wrong as there was no such path in my container, I changed it as per mine and it worked.
How I reached to the error?
"-Djavax.net.debug=all", I added this in entrypoint which gave me logs for reqs and in that I saw the error of file not found.