Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
Menu
How to integrate Push Notifications in Vaadin Web App

2024 Firebase Push Notifications in Vaadin Web [Fail⚠️] App [Mobile✅]

Posted on September 5, 2024September 5, 2024 by Toma Velev

Most recently I’ve tried to Integrate Firebase Push Notifications into a Vaadin Web App and I ended up – getting it – working – on Mobile. Here’s an overview of the steps I’ve done.

Using Vaadin’s built-in support for @Push Notifications

Vaadin provides ability to “Push” content onto the browser from your server. If you are running your app inside Spring Boot

  • annotate the Application class with @Push
  • Cache UI intance on rendering – in the view that will need update from server
  • On Some update from the Server – Push your changes with ui.access((){ /* ui Update */ })

This is the way I’ve accomplished incremental response from the GPT Chat in https://programtom.com/dev/product/own-your-chat-with-llm-gpt/

Using Vaadin’s official documentation for Push Notifications

I tried following the official example https://vaadin.com/blog/step-by-step-guide-to-sending-web-push-notifications-from-vaadin-flow. It seems to use deprecated Google Firebase Messaging API. It didn’t work on my machine – using Windows & Chrome.

The Registration token from the old way looks like an URL like: http://fcm.googleapis.com/fcm/send/{some long hash unique for the user/browser/installation/etc}. The way a push was working in the old way is – posting a request to that url with the VAPID – configured for your project.

I may get it working at some moment at the future, but for now – I’ll move on the the way it worked. More about it below.

On the Server

Step 1: Add dependencies

In your pom.xml file, add the following dependencies:

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>9.3.0</version>
</dependency>

Step 2: Configure Firebase on the Server

Install GCloud: https://cloud.google.com/sdk/docs/install. Authenticate and bind – your local Java Project – with a Firebase Project from your console.

Step 3: Create a Firebase instance

Create a Java class that will handle the FCM integration:

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;

@Configuration
public class FirebaseConfig {

    @Bean
    public FirebaseApp firebaseApp() {
return FirebaseApp.initializeApp(FirebaseOptions.builder()
        .setCredentials(GoogleCredentials
                .getApplicationDefault())
        .setProjectId("your project id")
        .setStorageBucket("storage-bucket")
///....etc //better to be part of application.properties
        .build());
} 
}

Step 4: Send FCM notifications

Create a Java class that will send FCM notifications:

import com.google.firebase.messaging.FirebaseMessaging;

@Service
public class FcmService {

    @Autowired
    private FirebaseApp firebaseApp;

    public void sendNotification(String token, String message) {
Message message = Message.builder()
        .putData("score", "850")
        .putData("time", "2:45")
        .setToken(token)  
.build();

String response = FirebaseMessaging.getInstance().send(message);
} 
}

I’ve failed to get working receiving Push Notifications on Web

  • on active page
  • nor – on the background.

I’ve even went and

  • created a clean web app – with no Vaadin, no Spring, no – nothing and just follow the instructions on their page.
  • I’ve tried with very minimal react app

One of the great obsticles of Integrations are – to try to plug-in multiple technologies at once.

I’ve learned that – the the “plain” JavaScript has evolved with a lot of items that I’ve previously have  seen only in Angular or React and TypeScript – where code is trans-complied to be “runnable” by the browsers.

Trying Alternatives

I’ve tried some of the alternatives of Firebase

  • One Signal Sign Up fails. I cannot pass through the Welcome – with some not “Unavailable. Please try again later”.
  • I’ve started with Amazon SNS – but I saw that it is intended for Mobile Push.
  • I’ve attempted several others, but they seem to have worse documentation and integrations.

From Vaadin Web App to Mobile Апп Push Message

What I did make functional push is on Mobile Device using Flutter.

  1. I’ve created a clean new project
  2. installed and configured the firebase_cli tools
  3. Made the appropiate configuration and changes in dart and android: https://firebase.google.com/docs/cloud-messaging/flutter/client
  4. Started the app on device that has Google Play Services.

For Every other device – without these services – I will need to do another integration – that – I’ve tried to escape – by – implementing it on the Web. Better luck next time. Until Then – I’ll get to more meaningful business logic.

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (87)
    • Flutter Apps (26)
    • GPT (4)
    • Java (39)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (36)
    • Utils (15)
    • Vaadin 24+ (28)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Post Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)