Sending notifications via Apple’s new HTTP/2 API

classic Classic list List threaded Threaded
1 message Options
- -
Reply | Threaded
Open this post in threaded view

Sending notifications via Apple’s new HTTP/2 API

- -


i try to send a push notification via apns to a smart phone (apple).

The response status code indicates that the message was sent successfully and i also get a push notification. The problem is i always get two (!) push notifications to the phone for every single request I send!

I can't see the problem and hope somebody can help :).

I use jetty's libraries.

I orientated on this code:

To gradle dependencies I included

compile 'org.eclipse.jetty.http2:http2-client:9.4.10.v20180503'
compile 'org.eclipse.jetty:jetty-http:9.4.10.v20180503'
compile 'org.eclipse.jetty.http2:http2-http-client-transport:9.4.10.v20180503'

I could not handle to add the ALPN library to my boot classpath :/, so I included to my code


and it works i.e. I did not get the error anymore. Maybe this is the problem?

Here's the code:

private ContentResponse sendMessage(String jsonMessage, String token, byte[] apnsCertificate, char[] apnCertificatePassword)  {

HTTP2Client http2Client = new HTTP2Client();
HttpClientTransportOverHTTP2 transport = new HttpClientTransportOverHTTP2(http2Client);
ContentResponse response = null;

try {

KeyStore keyStore = KeyStore.getInstance(KEY_STORE_TYPE);
keyStore.load(new ByteArrayInputStream(apnsCertificate), apnCertificatePassword);

KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, apnCertificatePassword);

SslContextFactory ssl = new SslContextFactory(true); //todo

HttpClient httpClient = new HttpClient(transport, ssl);

Request req = httpClient.newRequest(“”)
.path(“/3/device/”+ token)
.content(new StringContentProvider("{ \"aps\" : { \"alert\" : \"Hello\" } }"));

response = req.send();
} catch (Exception e) {
LOG.error(“Message could not be sent: ” + e.toString());
return response;




jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit