A Web Push library for Java 7. Supports payloads and VAPID.
For Gradle, add the following dependency to build.gradle:
compile group: 'nl.martijndwars', name: 'web-push', version: '3.0.0'
For Maven, add the following dependency to pom.xml:
<dependency>
<groupId>nl.martijndwars</groupId>
<artifactId>web-push</artifactId>
<version>3.0.0</version>
</dependency>
First, create an instance of the push service:
pushService = new PushService(...);
Then, create a notification based on the user's subscription:
Notification notification = new Notification(...);
To send a push notification:
pushService.send(notification);
Use sendAsync instead of send to get a Future<HttpResponse>:
pushService.sendAsync(notification);
See doc/UsageExample.md for detailed usage instructions. If you plan on using VAPID, read doc/VAPID.md.
Our integration tests use Web Push Testing Service (WPTS) to automate browser interaction. To install WPTS:
npm install web-push-testing-service -g
Then, to start WPTS:
web-push-testing-service start wpts
Finally, to run all tests:
./gradlew test
To give credit where credit is due, the PushService is mostly a Java port of marco-c/web-push. The HttpEce class is mostly a Java port of martinthomson/encrypted-content-encoding.
- For PHP, see Minishlink/web-push
- For NodeJS, see marco-c/web-push and GoogleChrome/push-encryption-node
- For Python, see mozilla-services/pywebpush