我使用Google API Client Library for Java来检索访问令牌。
代码:
public static String getAccessToken() throws IOException {
GoogleCredential googleCredential = GoogleCredential
.fromStream(new FileInputStream(PATH_JSON_AUTH02))
.createScoped(Arrays.asList(URL_SCOPE_FCM));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
}
问题是JVM无法找到可信证书来向Google服务发出HTTPS请求。我尝试使用keytool导入所有类型的Google证书,但仍无效。
例外:
10:03:29,371 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/TesteCertificadoGoogle].[tudo.ApplicationService]] (http--0.0.0.0-8443-2) Servlet.service() for servlet tudo.ApplicationService threw exception: org.jboss.resteasy.spi.UnhandledException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我应该导入哪个证书?
答案 0 :(得分:1)
不需要从那里导入证书。我进行了检查,默认情况下,访问URL:https://accounts.google.com/o/oauth2/auth的证书已在Java信任库(cacerts)中显示。确保使用默认的Java信任库(cacerts)