hengsokchamroeun / javapns

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

Starting a PushQueue with multiple threads and InputStream parameter throws a Stream closed exception #87

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Create a PushQueue with multiple threads like this:

Push.queue(NotificationQueues.class.getResourceAsStream("....p12"), 
KEYSTORE_PASSWORD, false, NUM_THREADS);

What is the expected output? What do you see instead?

You will get the following exception for each started thread except the first 
one:

javapns.communication.exceptions.KeystoreException: Keystore exception: Stream 
closed
    at javapns.communication.KeystoreManager.wrapKeystoreException(KeystoreManager.java:164)
    at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:66)
    at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:42)
    at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:29)
    at javapns.communication.ConnectionToAppleServer.<init>(ConnectionToAppleServer.java:54)
    at javapns.notification.ConnectionToNotificationServer.<init>(ConnectionToNotificationServer.java:16)
    at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:107)
    at javapns.notification.transmission.NotificationThread.runQueue(NotificationThread.java:255)
    at javapns.notification.transmission.NotificationThread.run(NotificationThread.java:200)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    at sun.security.util.DerValue.init(DerValue.java:345)
    at sun.security.util.DerValue.<init>(DerValue.java:303)
    at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1200)
    at java.security.KeyStore.load(KeyStore.java:1185)
    at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:64)
    ... 8 more

What version of the product are you using? On what operating system?

javapns 2.1, MacOS X 10.7.2, java 1.6.0_29

Original issue reported on code.google.com by thomas...@googlemail.com on 29 Nov 2011 at 2:04

GoogleCodeExporter commented 8 years ago
Thank you for the report.  Indeed, providing an InputStream for the keystore 
appears to work only for a single thread, as other threads are then given a 
depleted stream.  A temporary workaround is to provide the keystore as a byte[] 
array, a File or a KeyStore object.  A permanent solution will be added in an 
upcoming release.

Original comment by sype...@gmail.com on 29 Nov 2011 at 3:53

GoogleCodeExporter commented 8 years ago
Fixed in revision 340 (2.1.1a1)

The AppleServerBasicImpl class will now automatically ensure that the keystore 
reference provided is reusable.  If it is an InputStream, it will be preloaded 
as a KeyStore object so that other threads don't get a depleted stream.

Original comment by sype...@gmail.com on 30 Nov 2011 at 1:53