kaylavanhaverbeck / javapns

Automatically exported from code.google.com/p/javapns
0 stars 0 forks source link

exception : javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake #32

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.public class IphoneNotificationManager {

    public static void sentMessage(NotificationDetail notificationDetail) {
        PayLoad aPayload = payLoadValueOf(notificationDetail);

        PushNotificationManager pushManager = PushNotificationManager
                .getInstance();
        // Get iPhone client
        try {
            pushManager.addDevice(notificationDetail.getDeviceId(),
                    notificationDetail.getUuid());

            Device client = pushManager.getDevice(notificationDetail
                    .getDeviceId());
            // Send message
            pushManager.sendNotification(client, aPayload);

            System.out.println("Message sent! " + aPayload);
            System.out.println("# of attempts: "
                    + pushManager.getRetryAttempts());
            pushManager.removeDevice(notificationDetail.getDeviceId());
        } catch (Exception e) {
            System.out.println("exception : " + e);
            e.printStackTrace();
        }
    }

    public static void initializeConnection() {
        PushNotificationManager pushManager = PushNotificationManager
                .getInstance();
        // Initialize connection
        try {
            pushManager.initializeConnection(ApplicationProperties.APPLE_HOST,
                    ApplicationProperties.APPLE_PORT,
                    ApplicationProperties.CERTIFICATE_FILE_PATH,
                    ApplicationProperties.APPLE_PWD,
                    SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
            System.out.println("connection establishd to APNS");
        } catch (Exception e) {
            System.out.println("not able to initialize connection to APNS");
        }
    }

    public static void stopConnection() {
        PushNotificationManager pushManager = PushNotificationManager
                .getInstance();
        try {
            pushManager.stopConnection();
            System.out.println("connection stopped succesfully");
        } catch (IOException e) {
            System.out.println("not able to stop connection to APNS");
        }
    }

    private static PayLoad payLoadValueOf(NotificationDetail notificationDetail) {
        PayLoad aPayload = null;
        try {
            aPayload = new PayLoad();
            aPayload.addAlert(notificationDetail.getMatchbetween() + " at "
                    + notificationDetail.getMatchdate() + " on "
                    + notificationDetail.getMatchtime());
            aPayload.addSound("default");

        } catch (JSONException e) {
            System.out.println("Exceptio : " + e);
        }
        return aPayload;
    }

    public static void main(String args[]) {
        NotificationDetail notificationDetail = new NotificationDetail();
        notificationDetail
                .setUuid("ebbf8c927bfd6754348fb7ccf17cbe73f2e4741fc10f08fc2316ae877867eb80");
        notificationDetail.setMatchbetween("abc vs axy");
        notificationDetail.setDeviceId("1");
        notificationDetail.setMatchdate("today ");
        notificationDetail.setMatchtime("12:30");
        initializeConnection();
        IphoneNotificationManager.sentMessage(notificationDetail);
        stopConnection();
    }

}

2. Working fine on Window 7 but not working in linux server.

What is the expected output? What do you see instead?
Getting an exception 
exception : javax.net.ssl.SSLHandshakeException: Remote host closed connection 
during handshake
javax.net.ssl.SSLHandshakeException: Remote host closed connection during 
handshake
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:801)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1089)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:618)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
    at java.io.OutputStream.write(OutputStream.java:58)
    at javapns.back.PushNotificationManager.sendNotification(Unknown Source)
    at com.src.IphoneNotificationManager.sentMessage(IphoneNotificationManager.java:29)
    at com.src.PushJob.execute(PushJob.java:20)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:782)
    ... 9 more

What version of the product are you using? On what operating system?
Using 
bcprov-jdk15-145.jar
javapns-jdk1.5-v1.6.2.jar

Please provide any additional information below.

Original issue reported on code.google.com by cery...@gmail.com on 14 Oct 2010 at 8:32

GoogleCodeExporter commented 8 years ago
When you:
Enable SSL logging in java by adding the following to your java VM arguments:

-Djavax.net.debug=all

What SSL errors do you get?

Original comment by idbill.p...@gmail.com on 16 Oct 2010 at 9:34

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
It works fine when we restart the tomcat server.

It appears again after sometime. Any help would be appreciated

Original comment by cery...@gmail.com on 19 Oct 2010 at 1:36

GoogleCodeExporter commented 8 years ago
Sounds like you are trying to maintain a socket connection or running into the 
200 message limit that others have commented on. 

Would you verify?

Original comment by idbill.p...@gmail.com on 19 Oct 2010 at 4:11

GoogleCodeExporter commented 8 years ago
I tried sending around 300 push in a loop and they all are successful.

This above piece of code is called by a scheduled job through quartz. 
It works fine for 2-3 hrs. But after that starts giving this exception, 
everything
resolves after we restart the server.

Original comment by cery...@gmail.com on 20 Oct 2010 at 11:27

GoogleCodeExporter commented 8 years ago
Sounds like you are trying to maintain a socket connection.

The error is: Remote host closed connection during handshake

which would indicate that connection lapsed or you're not initializing the 
connection properly.

Original comment by idbill.p...@gmail.com on 20 Oct 2010 at 5:21

GoogleCodeExporter commented 8 years ago
I am calling above methods in this order

1. initializeConnection();
2. sentMessage(notificationDetail);
3. stopConnection();

But exception is coming in 2. call when we use sendNotification method of 
PushNotificationManager instance. 

I even tried with not calling 3. stopConnection as mentioned in some threads 
which i found. But that is also of no help. I am receiving same exception. 

I am not able to find any clue at all why this is happening??

Original comment by cery...@gmail.com on 21 Oct 2010 at 5:12

GoogleCodeExporter commented 8 years ago
It appears the getInstance is not syncronized. I'm updating the code to handle 
this.

Basically, when you call calling PushNotificationManager.getInstance you are 
getting a different instance of the singleton.

At the moment you would be better off having a class variable that stores that 
instance, so that you are guarnteed to get the same instance back.

Or you can try the new 163 version I just uploaded and provide feedback.

Original comment by idbill.p...@gmail.com on 21 Oct 2010 at 7:10

GoogleCodeExporter commented 8 years ago
Thanks for that i'll try that and update you on this.......

Original comment by cery...@gmail.com on 22 Oct 2010 at 5:14

GoogleCodeExporter commented 8 years ago
I tried getting instance only once. But same error occurred again after some 
tries.

Original comment by cery...@gmail.com on 22 Oct 2010 at 1:25

GoogleCodeExporter commented 8 years ago
I was receiving the same javax.net.ssl.SSLHandshakeException exception and I 
solve this issue by removing all duplicates of org.json.JSONObject classes from 
my project (refactoring some packages helped ie org.json -> 
org.json.myframework). Javapns and otherframework included same org.json 
package with same class names within them - so that was the problem in my case 
- JAR hell :(

If you use Eclipse try Ctrl+Shift+T <JSONObject> to check for duplications.

Original comment by nikola.p...@gmail.com on 28 Nov 2010 at 11:56

GoogleCodeExporter commented 8 years ago
Thanks for replying.

I have checked that also, but there is no duplication of jars for 
org.json.JSONObject classes. There exist only one jar for these classes i.e. 
javapns-jdk1.5-v1.6.2.jar.

Regards

Original comment by cery...@gmail.com on 29 Nov 2010 at 5:18

GoogleCodeExporter commented 8 years ago
hi, I' getting the same error, please help me out

javax.net.ssl.SSLHandshakeException: Remote host closed connection during 
handshake
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1120)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:623)
        at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
        at java.io.OutputStream.write(OutputStream.java:58)
        at com.apple.ist.retail.pos.tr.protocol.tr.transport.Call.executeCall(Call.java:197)
        at com.apple.ist.retail.pos.tr.protocol.tr.transport.Transport.executeCall(Transport.java:210)
        at com.apple.ist.retail.pos.tr.protocol.tr.TenderRetailServiceImpl.authorizeDebitPurchase(TenderRetailServiceImpl.java:486)
        at com.extendyourstore.domain.manager.tenderauth.tenderretail.TRAuthTechnician.requestAuthorization(TRAuthTechnician.java:943)
        at com.extendyourstore.domain.manager.tenderauth.TenderAuthValet.execute(TenderAuthValet.java:107)
        at com.extendyourstore.domain.manager.tenderauth.tenderretail.TRAuthTechnician.transport(TRAuthTechnician.java:1066)
        at com.extendyourstore.domain.manager.tenderauth.NxsTenderAuthManager.transportValet(NxsTenderAuthManager.java:283)
        at com.extendyourstore.domain.manager.tenderauth.NxsTenderAuthManager.requestAuthorization(NxsTenderAuthManager.java:172)
        at com.extendyourstore.pos.services.tender.authorization.can.AuthorizeChargeSite.arrive(AuthorizeChargeSite.java:587)
        at com.extendyourstore.foundation.tour.engine.Site.arrive(Site.java:177)
        at com.extendyourstore.foundation.tour.engine.Road.traverseForward(Road.java:833)
        at com.extendyourstore.foundation.tour.engine.Road.traverse(Road.java:582)
        at com.extendyourstore.foundation.tour.engine.SiteVertex.driveSite(SiteVertex.java:285)
        at com.extendyourstore.foundation.tour.engine.AbstractSite.driveSite(AbstractSite.java:71)
        at com.extendyourstore.foundation.tour.engine.Site.driveSite(Site.java:153)
        at com.extendyourstore.foundation.tour.service.BusDriver.processLetter(BusDriver.java:315)
        at com.extendyourstore.foundation.tour.service.BusDriver.processLetters(BusDriver.java:213)
        at com.extendyourstore.foundation.tour.service.AbstractCrewMember.run(AbstractCrewMember.java:231)
        at com.extendyourstore.foundation.manager.thread.StaticCacheThread.run(StaticCacheThread.java:148)
Caused by: java.io.EOFException: SSL peer shut down incorrectly

Original comment by sathiyar...@gmail.com on 17 Apr 2011 at 3:44

GoogleCodeExporter commented 8 years ago
My guess is that you are not connecting to the correct host and/or port.

What troubleshooting have you done

Original comment by idbill.p...@gmail.com on 17 Apr 2011 at 4:30

GoogleCodeExporter commented 8 years ago
ceryash, were you able to fix the issue you reported?

Original comment by sype...@gmail.com on 9 Sep 2011 at 7:05

GoogleCodeExporter commented 8 years ago
Closing issue as no feedback was received by original poster for many months.  
Please feel free to re-open if the issue is still valid.

Original comment by sype...@gmail.com on 14 Sep 2011 at 4:08

GoogleCodeExporter commented 8 years ago
Hi all,
Please help me. I am also getting ssl exception issues when i use enabled ssl 
.p12 certificate. kindly any one suggest me. i am using javaPNS-2.2 version.
I tried already openssl i did not able solve. if there any certificate issues 
or not?
This is our code.. 

    public static void main(String arg[]) {
        try {
             PushNotificationPayload payload = PushNotificationPayload.complex();
             payload.addAlert("Hi doubakor rajesh");
             payload.addBadge(1);
             payload.addSound("default");
             payload.addCustomDictionary("id", 1);
             System.out.println("payload...."+payload.toString());

             String token = "xxxxxxxxxxxxxxxxx";
             System.out.println("length ...."+token.length());
             String keyStorePassword = "xxxxx";
             String keyStoreFilePath = "E:\\APNS\\SSL\\Prudentialssl.p12";

             List<PushedNotification> notifications = javapns.Push.payload(payload, keyStoreFilePath, keyStorePassword, false, token.trim());

             for (PushedNotification NOTIFICATION : notifications) {
                 System.out.println("enter for loop .....");
                    if (NOTIFICATION.isSuccessful()) {
                            /* APPLE ACCEPTED THE NOTIFICATION AND SHOULD DELIVER IT */  
                            System.out.println("PUSH NOTIFICATION SENT SUCCESSFULLY TO: " +
                                                            NOTIFICATION.getDevice().getToken());
                            /* STILL NEED TO QUERY THE FEEDBACK SERVICE REGULARLY */  
                    } 
                    else {
                            String INVALIDTOKEN = NOTIFICATION.getDevice().getToken();
                            /* ADD CODE HERE TO REMOVE INVALIDTOKEN FROM YOUR DATABASE */  
                            System.out.println("INVALIDTOKEN"+INVALIDTOKEN);

                            /* FIND OUT MORE ABOUT WHAT THE PROBLEM WAS */  
                            Exception THEPROBLEM = NOTIFICATION.getException();
                            THEPROBLEM.printStackTrace();

                            /* IF THE PROBLEM WAS AN ERROR-RESPONSE PACKET RETURNED BY APPLE, GET IT */  
                            ResponsePacket THEERRORRESPONSE = NOTIFICATION.getResponse();
                            if (THEERRORRESPONSE != null) {
                                    System.out.println(THEERRORRESPONSE.getMessage());
                            }
                    }
              }

        } catch(Exception e) {
            e.printStackTrace();
        }
    }

Error : 

javax.net.ssl.SSLHandshakeException: Remote host closed connection during 
handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source)
    at sun.security.ssl.AppOutputStream.write(Unknown Source)
    at java.io.OutputStream.write(Unknown Source)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:402)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:350)
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:320)
    at javapns.Push.sendPayload(Push.java:177)
    at javapns.Push.payload(Push.java:149)
    at com.test.Push.main(Push.java:28)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(Unknown Source)
    ... 11 more

Thanks advanced ...

Original comment by elavan.k...@gmail.com on 19 Aug 2015 at 9:40