0

我们使用 JavaAPNS 向 iOS 设备发送推送通知。当我在 Windows 或 OS X 中时,发送和接收到 iOS 设备的推送通知,但是当我在 Linux 环境中时,会发生此错误:

javapns.communication.exceptions.KeystoreException: Keystore exception: DER input, Integer tag error
at javapns.communication.KeystoreManager.wrapKeystoreException(KeystoreManager.java:178)
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:66)
at javapns.communication.KeystoreManager.ensureReusableKeystore(KeystoreManager.java:87)
at javapns.communication.AppleServerBasicImpl.<init>(AppleServerBasicImpl.java:37)
at javapns.notification.AppleNotificationServerBasicImpl.<init>(AppleNotificationServerBasicImpl.java:57)
at javapns.notification.AppleNotificationServerBasicImpl.<init>(AppleNotificationServerBasicImpl.java:42)
at javapns.notification.AppleNotificationServerBasicImpl.<init>(AppleNotificationServerBasicImpl.java:28)
at javapns.Push.sendPayload(Push.java:170)
at javapns.Push.payload(Push.java:149)
at com.myproj(class.java:80)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)    Caused by: java.io.IOException: **DER input, Integer tag error**
at sun.security.util.DerInputStream.getInteger(DerInputStream.java:151)
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1202)
at java.security.KeyStore.load(KeyStore.java:1185)
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:64)
... 11 more

这是我的代码:

public void run() {
    List<PushedNotification> notifications = new ArrayList<PushedNotification>();
    String keystorePath = "/cert/cert.p12";

    InputStream keystore = this.getClass().getResourceAsStream(keystorePath);

    try {
        //Some code..
       payload = constructMessagePayload();     


        notifications = Push.payload(payload, keystore,"password",
                false, iphoneTargets);
        logger.info("Notification list size:" + notifications.size());
    } catch (CommunicationException e) {
        logger.error("Exception",e);
    } catch (KeystoreException e) {
        logger.error("Exception",e);
    } catch (JSONException e) {
        logger.error("Exception",e);
    }
    for (PushedNotification notification : notifications) {
        if (pn.isSuccessful()) {
            logger.info("Push ok: "
                    + pn.getPayload().toString());
        } else {
            logger.info("Push not ok: "
                    + pn.getException().toString());
        }
    }
}

如果我指定文件的绝对路径一切正常,但我想将它放在 src/main/resources 中,而不是每次需要更改文件时都登录服务器。如果我正确理解这是与私钥相关的问题。有没有办法解决这个问题。这里的 Linux 有什么不同?有什么建议吗?

4

1 回答 1

1

Fixed. When use Maven filtering of resources, it treats *.p12 file like a text file. http://johnnywey.wordpress.com/2009/11/04/careful-with-your-binary-resources/

于 2013-09-27T14:43:59.090 回答