Skip to content

st-user/zerodep-web-push-java-example

Repository files navigation

zerodep-web-push-java-example

A zerodep-web-push-java example using Spring Boot.

This is the example for v2. The example for v1 is here.

Requirements

  • JDK17+
  • A library for generating ECDSA key pairs(e.g. OpenSSL)
  • A browser supporting Push API such as Google Chrome, Microsoft Edge and Firefox

Usage

  1. Set up and run the application.

    git clone https://github.com/st-user/zerodep-web-push-java-example.git
    cd zerodep-web-push-java-example
    mkdir .keys
    cd .keys
    openssl ecparam -genkey -name prime256v1 -noout -out my-private.pem
    openssl pkcs8 -in my-private.pem -topk8 -nocrypt -out my-private_pkcs8.pem
    openssl ec -in my-private.pem -pubout -conv_form uncompressed -out my-pub.pem
    cd ../
    

    Linux/mac OS

    ./mvnw clean
    ./mvnw spring-boot:run
    

    Windows

    ./mvnw.cmd clean
    ./mvnw.cmd spring-boot:run
    
  2. Open your browser and access http://localhost:8080;

  3. Click the subscribe button.

  4. Enter an arbitrary message and click the send button.

  5. You should see a push notification!

  6. (Optional) Since push notifications are handled in the background, we can get them even if we close the browser.

    • Close the browser and open a terminal instead.
    • Make the application send a push notification by using a command like the following:
    curl -X POST http://localhost:8080/sendMessage \
    -H 'Content-Type: application/json' \
    -d '{ "message": "Message sent with curl." }'
    

video: Web Push With Java; How to use the example application for ‘zerodep-web-push-java’(mac OS/LInux)

NOTE

private key

In general, storing private keys in plain text on a file system is not recommended (In the above example, we do that for simplicity).

However, such a method is still useful depending on architectures.

For example:

Further reading

See also

About

A zerodep-web-push-java example using Spring Boot.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published