有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我们使用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) 个答案