DER输入,Javapns iOS推送通知发件人中的整数标记错误

时间:2013-09-27 09:31:04

标签: java ssl apple-push-notifications javapns

我们使用JavAPNS向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? 有什么建议吗?

1 个答案:

答案 0 :(得分:1)

固定。 使用Maven过滤资源时,它会将* .p12文件视为文本文件。 http://johnnywey.wordpress.com/2009/11/04/careful-with-your-binary-resources/