When I run my code in the main class it works correctly, but in the backend this code does not work.
There are no exceptions, it shows no error.
I put impressions to see what happened, but it never shows the impression 3. java version: 1.8 server: glassfish 5
The code runs in the main class but not in the backend, I thought this happened because it was on my local machine (localhost), but I uploaded the code to the server and the same thing happens, the code does not run and shows no errors
Maven's Unit
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.4.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
Aggregate
import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.firebase.messaging.AndroidConfig; import com.google.firebase.messaging.AndroidNotification; import com.google.firebase.messaging.ApnsConfig; import com.google.firebase.messaging.Aps; import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.Notification; import com.google.firebase.messaging.TopicManagementResponse; import com.google.firebase.messaging.WebpushConfig;
Code that works in the main
try {
System.out.println("1");
FileInputStream serviceAccount= new FileInputStream("/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setServiceAccountId("projectId")
.setProjectId("projectId")
.build();
FirebaseApp.initializeApp(options);
System.out.println("2");
com.google.firebase.messaging.Message message =
com.google.firebase.messaging.Message.builder()
.putData("tipo", "cargueTareasFinalizado")
.putData("nombreAmigo", "DARIOOO")
.putData("pagina", "DARIOOO")
.setToken(token)
.setNotification(new Notification(
"Dario up 1.43% on the day",
"$GOOG gained 11.80 points to close at 835.67, up
1.43% on the day."))
.setAndroidConfig(AndroidConfig.builder()
.setTtl(3600 * 1000)
.setNotification(AndroidNotification.builder()
.setTitle("titulo android")
.setBody("body android")
.setIcon("icon_color")
.setColor("#247c2e")
.build())
.build())
.setApnsConfig(ApnsConfig.builder()
.setAps(Aps.builder()
.setBadge(0)
.build())
.putCustomData("titulo", "tiiiiiiii")
.putCustomData("body", "bodddd")
.putCustomData("tipo", "cargueTareasFinalizado")
.build())
.setWebpushConfig(WebpushConfig.builder()
.putData("titulo", "Tiiiiii")
.putData("body", "bodddy")
.putData("icon", "\"images/favicon.png\"")
.build())
.build();
System.out.println("3");
String response = FirebaseMessaging.getInstance().send(message);
} catch (Exception e) {
e.printStackTrace();
}