CleverTap / apns-http2

A Java library for sending notifications via APNS using Apple's HTTP/2 API.
https://clevertap.com
BSD 3-Clause "New" or "Revised" License
216 stars 109 forks source link

Getting Exception while running with OKhttp3 + No notification #4

Closed shubham-m closed 8 years ago

shubham-m commented 8 years ago
Exception in thread "main" java.io.IOException: unexpected end of stream on okhttp3.Address@5106fe42
    at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:199)
    at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:125)
    at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:723)
    at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:81)
    at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:708)
    at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563)
    at okhttp3.RealCall.getResponse(RealCall.java:241)
    at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
    at okhttp3.RealCall.execute(RealCall.java:57)
    at com.clevertap.jetty.apns.http2.clients.SyncOkHttpApnsClient.main(SyncOkHttpApnsClient.java:229)
Caused by: java.io.EOFException: \n not found: size=176 content=0000180400000000000001000010000003000001c4000500004000000600001f...
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)
    at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:184)
    ... 10 more

We tried it with builder pattern you had provided, also we tried to use directly the constructor itself and then client private from SyncOkHttpApnsClient.java. But both produced same results.

final ApnsClient apnsClient = new ApnsClientBuilder()
        .withProductionGateway()
        .inSynchronousMode()
        .withCertificate(cert)
        .withPassword("pass")
        .withOkHttp3()
        .build();
Notification notification = new  Notification.Builder(token).alertBody("Example!015").sound("default").build();
NotificationResponse response = apnsClient.push(notification);

We also had same exception when we tried to use OkHttp. Any kind of help will be much appreciated.

Request request = new Request.Builder()
              .url("https://api.push.apple.com:443/3/device/{token}")
              .post(body).header("apns-priority","10")
              .build();
          Response response = apnsClient.client.newCall(request).execute();
          System.out.println(response);
judepereira commented 8 years ago

Can you reproduce this every time? I've noticed that the Apple gateways are down are at random times.

labelnolongerexists commented 8 years ago

I got this exception every time. The exceptions are exactly same with the issue described above.

judepereira commented 8 years ago

I'm not certain about how to reproduce this issue here. Perhaps you could create a new issue on the okHttp project?

jbaizer commented 8 years ago

I am also able to replicate this issue 100% of the time, while testing using cURL+nghttp2 works (so it isn't that the server is down).

judepereira commented 8 years ago

That's very weird. How are you loading your certificate?

jbaizer commented 8 years ago

Exactly like the example, using a FileInputStream.

It appears to be loading the certificate properly, cert.available() returns the proper size of the certificate and intentionally using an expired certificate generates a different exception for me.

judepereira commented 8 years ago

Could you send me your sandbox certificate? I could take a look here

CyrusNG commented 8 years ago

I have the same issue. Is there any solution?

judepereira commented 8 years ago

A sandbox certificate would help, as there's no way in which I can reproduce it here.

jbaizer commented 8 years ago

Unfortunately, I can't share mine as it is for work. Hopefully someone else is able to.

atschx commented 8 years ago
judepereira commented 8 years ago

Yes, Apple supports only HTTP/2.

darklynx commented 8 years ago

@judepereira I have similar issue, does that mean that my certificate / APN Auth Key are not properly created or initialized?

darklynx commented 8 years ago

btw, it works using curl command mentioned here: http://stackoverflow.com/questions/35603331/curl-http2-request

judepereira commented 8 years ago

@darklynx Please open a new issue along with your code for sending the notification.

darklynx commented 8 years ago

@judepereira I figured out the cause of the problem. I'm surprised that nobody mentioned about it here.

In order HTTP/2 to work properly with Java 8 one need to supply ALPN support by using Jetty alpn-boot project, as described here: https://github.com/square/okhttp/wiki/Building

judepereira commented 8 years ago

Yes, this is a part of the readme: https://github.com/CleverTap/apns-http2/blob/master/README.md

darklynx commented 8 years ago

Indeed, I have to learn to read "readme" files from top to bottom, but not just look at the code samples :) Interesting though that in my case exception was indicating the same issue as described by person who initiated this ticket:

...
Caused by: java.io.EOFException: \n not found: size=176
...

I believe the person has felt into the same trap as me.