web-push-libs / webpush-java

Web Push library for Java
MIT License
318 stars 112 forks source link

pushService.send(notification); => java.security.GeneralSecurityException,java.io.IOException,org.jose4j.lang.JoseException,java.util.concurrent.ExecutionException,java.lang.InterruptedException #145

Closed kopax closed 4 years ago

kopax commented 4 years ago

I have used this example to integrate my application, I am able to subscribe, unsubscribe but not to send web push.

It does not throw any error, this is the log:

2020-08-17 18:52:11,962 DEBUG org.springframework.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/public/web-push/notify-all]
2020-08-17 18:52:11,963 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping : Looking up handler method for path /public/web-push/notify-all
2020-08-17 18:52:11,963 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping : Returning handler method [public com.kopaxgroup.api.userManagement.domain.WebPushMessage com.kopaxgroup.api.userManagement.controller.PublicWebPushController.notifyAll(com.kopaxgroup.api.userManagement.domain.WebPushMessage) throws java.security.GeneralSecurityException,java.io.IOException,org.jose4j.lang.JoseException,java.util.concurrent.ExecutionException,java.lang.InterruptedException]
2020-08-17 18:52:11,966 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor : Read [class com.kopaxgroup.api.userManagement.domain.WebPushMessage] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@1c5d3a37]
2020-08-17 18:52:11,967 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : Total subscriptions where sending: 1
2020-08-17 18:52:11,967 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : getNotificationEndPoint :https://fcm.googleapis.com/fcm/send/dHw3jOtGvcc:APA91bFp2h6mWj1vFZNYXhmwMFgaAIa7IXiqa18JBP7HgK2a03evcxDy1F6a1XpgFTPQX-DljGvYG-ehzGquPyInvUFuFZo-29wHNXFwlWIOs0rqFFMmVExGtlLek7yvzQlRAqobufMS
2020-08-17 18:52:11,968 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : getPublicKey :BGikCeYw8PiHG0qf18YR9ooe7dVCo9dNx0j+h6eYJLB9eO8nDw4gxyMejMRSnpaOJdtqbZJKjFZUqxsF0v6AAuI=
2020-08-17 18:52:11,968 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : getAuth :5......bN.............==
2020-08-17 18:52:11,971 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : sending start

2020-08-17 18:52:13,100 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : sending done
2020-08-17 18:52:13,100 DEBUG com.kopaxgroup.api.userManagement.controller.PublicWebPushController : ===> Sending notification is over, payload was: [123, 34, 116, 105, 116, 108, 101, 34, 58, 34, 116, 101, 115, 116, 105, 110, 103, 34, 44, 34, 99, 108, 105, 99, 107, 84, 97, 114, 103, 101, 116, 34, 58, 34, 104, 116, 116, 112, 115, 58, 47, 47, 115, 116, 97, 103, 105, 110, 103, 45, 119, 119, 119, 46, 105, 99, 105, 109, 97, 116, 105, 110, 46, 99, 111, 109, 47, 63, 111, 107, 61, 116, 114, 117, 101, 34, 44, 34, 109, 101, 115, 115, 97, 103, 101, 34, 58, 34, 104, 101, 108, 108, 111, 32, 119, 101, 108, 99, 111, 109, 101, 34, 125]
2020-08-17 18:52:13,104 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor : Written [WebPushMessage(title=testing, clickTarget=https://staging-www.icimatin.com/?ok=true, message=hello welcome)] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@1c5d3a37]
2020-08-17 18:52:13,104 DEBUG org.springframework.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2020-08-17 18:52:13,104 DEBUG org.springframework.web.servlet.DispatcherServlet : Successfully completed request

This is my controller that is in charge of sending the push notification:


    @PostMapping(value = "/notify-all", produces = MediaType.APPLICATION_JSON_VALUE)
    public WebPushMessage notifyAll(@RequestBody WebPushMessage message) throws GeneralSecurityException, IOException, JoseException, ExecutionException, InterruptedException {
        WebPushMessage msg = null != message && message.getMessage() == null ? new WebPushMessage("test", "https://staging-www.icimatin.com/?clickTarget=me", "test message") : message;
        log.debug("Total subscriptions where sending: " + subscriptions.size());
        for (WebPushSubscription subscription: subscriptions.values()) {
            log.debug("getNotificationEndPoint :" + subscription.getNotificationEndPoint());
            log.debug("getPublicKey :" + subscription.getPublicKey());
            log.debug("getAuth :" + subscription.getAuth());

            Notification notification = new Notification(
                    subscription.getNotificationEndPoint(),
                    subscription.getPublicKey(),
                    subscription.getAuth(),
                    objectMapper.writeValueAsBytes(msg));
            try {
                log.debug("sending start");
                pushService.send(notification);
                log.debug("sending done");
            } catch (Exception e) {
                log.debug("sending produced exception :" + e.getMessage());
                log.debug("sending produced stacktrace :" + Arrays.toString(e.getStackTrace()));
            }
            log.debug("===> Sending notification is over, payload was: " + Arrays.toString(notification.getPayload()));
        }

        return message;
    }

So no error, It seems to work fine, it does no error, but pushService.send(notification) produce nothing.

It is hard to debug since I can't test this in development due to https://github.com/expo/expo-cli/issues/2063

Any idea how I can get web push to work ?