Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to subscribe multiple device token for FCM HTTP v1 API using coldfusion

New Here ,
Sep 19, 2024 Sep 19, 2024

In ColdFusion, we generated an OAuth token to send notifications. However, due to the limitations of FCM HTTP v1, we cannot send notifications to multiple devices at once. To overcome this, we found a solution: using a TOPIC to subscribe device tokens. We attempted to subscribe multiple tokens using the FCM SDK.

We included all the necessary dependent JAR files for subscribing, but it throws an error.

We are using ColdFusion 2023.

 

Here’s a simplified version of what we’re trying:

<cfset FirebaseAdmin = createObject("java", "com.google.firebase.FirebaseApp") /> <cfset FirebaseMessaging = createObject("java", "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin) />

<cfset registrationTokens = ["token1", "token2", "token3"] />

<cfset response = FirebaseMessaging.subscribeToTopic(registrationTokens, topic) />

However, we’re getting an error when trying to subscribe the tokens.

Could anyone please provide a solution?

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2024 Sep 19, 2024

Can you share all the details of the error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2024 Sep 19, 2024

Getting below error

com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor

We searched for this soltuion. It is something related to guava jar file. But we tried with almost all the version guava jar file. But still shows the error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2024 Sep 19, 2024

The error is not related to ColdFusion. I agree with you that it is an error coming from Google's Guava library.

 

What is the name/version of the Guava Jar files you are using?  You could download and copy the latest versions of the Jar files to ColdFusion's lib directory, and see if that helps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2024 Sep 19, 2024

I have used guava-33.3.0-jre.jar library. It's a latest version. Also tried with older version.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2024 Sep 19, 2024

As an example, I have just done the following test:

  1.  Download firebase-admin-9.3.0.jar from maven.org (its release date is 2024-05-21 18:18).
  2.  Copy the file to ColdFusion 2023's lib directory.
  3.  Restart ColdFusion.
  4.  Launch the following code (which I borrowed from you) as a CFM file.
    <cfset FirebaseAdmin = createObject("java", "com.google.firebase.FirebaseApp")> 
    
    <cfdump var="#FirebaseAdmin#">​

    The code runs as expected. The result is:
    BKBK_0-1726754166467.png

     

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2024 Sep 19, 2024

<cfset FirebaseAdmin = createObject("java", "com.google.firebase.FirebaseApp") />
<cfset FirebaseMessaging = createObject("java", "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin) />

<cfset registrationTokens = ["token1", "token2", "token3"] />


<cfset response = FirebaseMessaging.subscribeToTopic(registrationTokens, topic) />

We know that it's working and creating the object for this <cfset FirebaseMessaging = createObject("java", "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin) />  when we are caliing FirebaseMessaging.subscribeToTopic(registrationTokens, topic) method in response we are getting HTTP 500 :: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor

We want soltuion for this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024
quote "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin) />  when we are caliing FirebaseMessaging.subscribeToTopic(registrationTokens, topic) method in response we are getting HTTP 500 :: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor


By @Piyush32537068gy36

 

As I said before, given that your question is about Firebase Messaging, you would probably be better off asking it in a Google Firebase forum.

 

In any case, shouldn't that line be "com.google.firebase.messaging.FirebaseMessaging").getInstance()" instead of "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin)"? I ask because I can see the following in https://firebase.google.com/docs/cloud-messaging/cpp/topic-messaging :

BKBK_0-1726834450667.png

 

Your code passes the variable topic as an argument to subscribeToTopic. Question: is the value of topic a string?

 

  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 20, 2024 Sep 20, 2024

Thanks for the reply. I will check it in detail and let you know

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024

Test:

What do you get when you modify the code as follows?

<cfset FirebaseAdmin = createObject("java", "com.google.firebase.FirebaseApp") />
<cfset FirebaseMessaging = createObject("java", "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin) />

<cfset registrationTokens = ["token1", "token2", "token3"] />

<!--- Temporary test code --->
<cfdump var="#FirebaseMessaging#" label="FirebaseMessaging" abort="true">

<cfset response = FirebaseMessaging.subscribeToTopic(registrationTokens, topic) />

If a variable is dumped, please share a printscreen of it.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2024 Sep 20, 2024

Piyush32537068gy36_0-1726836467807.png

Plese refer the attach screenshot

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024

The screenshot suggests that the HTTP 500 error is caused by the line

<cfset FirebaseMessaging = createObject("java", "com.google.firebase.messaging.FirebaseMessaging").getInstance(FirebaseAdmin) />

So, what happens when you run the following test?

 

<cfset FirebaseAdmin = createObject("java", "com.google.firebase.FirebaseApp") />
<cfset FirebaseMessaging = createObject("java", "com.google.firebase.messaging.FirebaseMessaging").getInstance() />

<cfset registrationTokens = ["token1", "token2", "token3"] />

<!--- Temporary test code --->
<cfdump var="#FirebaseMessaging#" label="FirebaseMessaging" abort="true">

<cfset response = FirebaseMessaging.subscribeToTopic(registrationTokens, topic) />

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 19, 2024 Sep 19, 2024

Will it work on Coldfusion 2021? When we execute the code below 

 

<cfset FirebaseAdmin = createObject("java", "com.google.firebase.FirebaseApp")>
<cfobject action="create" type="java" class="com.google.firebase.FirebaseApp" name="obj">
<cfdump var="#obj#" label="obj">
 

we got the error "Object instantiation exception.".  please advise

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2024 Sep 19, 2024

Yes, it work in Coldfusion 2021.

But you wana download this firebase-admin-9.3.0 jar file and paste into coldfusion\lib folder

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 21, 2024 Sep 21, 2024

Thanks. I downloaded the above  firebase-admin-9.3.0 jar file and got the below error

jibinanto40792294_0-1726936967593.png

Then I got a fix to add dependency jar files so i added below jar files

jibinanto40792294_1-1726937175258.png

Then i got the response as 

jibinanto40792294_2-1726937224342.png

 

Thanks @BKBK. It helps me a lot.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2024 Sep 21, 2024
LATEST

Hi @jibinanto40792294 , thanks for the update.

 Piyush's problem is different from yours. As a result, it is confusing to have two separate discussions here. Could you therefore continue your discussion in your own thread?

That will help anyone who comes here to look for answers to a question similar to yours.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources