ApacheFlink,KinesisStreamSinkPKIX路径构建失败
创始人
2024-09-05 20:01:04
0次

在Java程序中使用Amazon Kinesis API时,可能会遇到以下异常:“javax.net.ssl.SSLHandshakeException:PKIX路径构建失败”。此异常通常是由于缺少证书或证书不受信任而引起的。

要解决此问题,需要下载Amazon根证书并将其添加到Java的信任存储中。以下是添加Amazon根证书的代码示例。

/**
 * Adds Amazon root certificates to Java trust store.
 */
private static void addAmazonRootCertificates() throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    InputStream cert1 = new BufferedInputStream(new FileInputStream("src/main/resources/certificate1.pem"));
    X509Certificate certificate1 = (X509Certificate) cf.generateCertificate(cert1);
    InputStream cert2 = new BufferedInputStream(new FileInputStream("src/main/resources/certificate2.pem"));
    X509Certificate certificate2 = (X509Certificate) cf.generateCertificate(cert2);

    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(null); // You don't need the KeyStore instance to come from a file.
    ks.setCertificateEntry("certificate1", certificate1);
    ks.setCertificateEntry("certificate2", certificate2);

    tmf.init(ks);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, tmf.getTrustManagers(), new SecureRandom());
    SSLContext.setDefault(sslContext);
}

在您的Java应用程序中添加此方法并调用它以添加Amazon根证书。这将解决“PKIX路径构建失败”异常并允许应用程序与Amazon Kinesis API进行安全通信。

相关内容

热门资讯

透明教程!wpk系统是否存在作... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
重大消息!有没有人wepoke... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
技巧知识分享!wepoker公... 很多人使用云端 AI 时,都担心wepoker公共底牌、内部资料上传带来隐私风险。这款本地运行的 A...
分享给玩家!wepoker透视... wepoker透视脚本安卓AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻...
新版2025教程!wepoke... 新版2025教程!wepoker辅助器怎么弄,WPK开挂脚本平台(从来是真的有透视)主打本地运行的 ...
详细说明!德扑之星辅助器,we... 详细说明!德扑之星辅助器,wepoker开挂工具软件(最初有开挂)主打本地运行的 AI 黑科技工具迎...
每日必看!wepoker买脚本... 每日必看!wepoker买脚本靠谱吗,微扑克开挂脚本插件(素来是真的有开挂)主打本地运行的 AI 黑...
专业教程!wepoker辅助器... 很多人使用云端 AI 时,都担心wepoker辅助器安装包、内部资料上传带来隐私风险。这款本地运行的...
软件教程!wepoker-h5... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
新手必备!we-poker辅助... 您好,新手必备!we-poker辅助器,德扑之星到底有没有挂神器(本来真的是有透视挂)这款游戏可以开...