java-apns
java-apns copied to clipboard
not able to send push notifications because javax.net.ssl.SSLHandshakeException
I am using maven dependency to include this library
Java version: J2SE-1.5
Code is pretty basic:
public static void main( String[] args )
{
ApnsService service =
APNS.newService()
.withCert("absolute-path-to-file.p12"
, "password")
.withSandboxDestination()
.build();
String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
String token = "some token";
service.start();
service.push(token, payload);
service.stop();
}
I am getting following stacktrace:
Exception in thread "main" com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at com.notnoop.apns.internal.Utilities.wrapAndThrowAsRuntimeException(Utilities.java:284) at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:342) at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:312) at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46) at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:56) at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36) at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:45) at Apple.ApplePushNeetloopsAPNS.App.main(App.java:25) Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:953) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:709) at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122) at java.io.OutputStream.write(OutputStream.java:75) at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:328) ... 6 more Caused by: java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:482) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934) ... 11 more
looks like an error w/ the .p12 file ?
https://github.com/notnoop/java-apns/issues/227
I am trying to test it with some other prebuilt tool and update here. Thanks for response.
I tried a mac appliction called Pusher to send notification with same p12 file and it is working fine.
i was also getting the same error and i tried Pusher which correctly sent the notification but then i figured out what is the issue.
The method i used to generate .p12 from my production certificate was wrong. i was selecting both Certificate and Key and then right click to export 2 files to generate .p12 file. Which infact was wrong and increasing file size. i regenerated .p12 file by right clicking only the production certificate and Voila!!! it worked.
On the other hand why pusher was working was due to the fact that pusher was using the certificate directly and not the generated .p12 file.
Hope this helps
Thanks @shows19 . You made my day! ;-)
I had a similar issue and what worked for me was following the instructions at NWPusher to generate my .p12
file.
works like a charm, thank you @shows19
My code was working fine with certificate and suddenly it stooped working with handshake failure. We tried many thing
- first test with apns_test if this will send test notification then you have problem with security configuration
Finally put certificate with in the war file. if you are testing out side folder then you might face this problem.
This work with me when I put certificate with in the war file.
I have tried this, but it is still the same error.. NWPusher works though. Did you right click on the certificate or the private key? I remembered trying all 3 combinations, export the certificate, the private key, both cert and private key..
The complete error is always: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure