在 GKE 或 GCE 中运行的容器中从 Google 存储桶读取文件时。以下代码失败:
public String readSmallTextFileFromBucket(String bucketName, String textFile) {
Blob blob = storage.get(bucketName, textFile);
String fileContent = new String(blob.getContent());
return fileContent;
}
出现错误:
com.google.cloud.storage.StorageException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
如果我将java/jdk-10.0.2/lib/security/cacerts
下载 OpenJDK 时获得的默认文件替换为我桌面上的默认文件,则上面的代码可以正常工作。
这是为什么?什么是使 Java API 从容器内的存储桶中读取的正确方法?